Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176
This commit is contained in:
commit
9921556621
13277 changed files with 1459781 additions and 0 deletions
23
core/lib/Drupal/Component/Uuid/Com.php
Normal file
23
core/lib/Drupal/Component/Uuid/Com.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Component\Uuid\Com.
|
||||
*/
|
||||
|
||||
namespace Drupal\Component\Uuid;
|
||||
|
||||
/**
|
||||
* UUID implementation using the Windows internal GUID extension.
|
||||
*
|
||||
* @see http://php.net/com_create_guid
|
||||
*/
|
||||
class Com implements UuidInterface {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function generate() {
|
||||
// Remove {} wrapper and make lower case to keep result consistent.
|
||||
return strtolower(trim(com_create_guid(), '{}'));
|
||||
}
|
||||
}
|
21
core/lib/Drupal/Component/Uuid/Pecl.php
Normal file
21
core/lib/Drupal/Component/Uuid/Pecl.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Component\Uuid\Pecl.
|
||||
*/
|
||||
|
||||
namespace Drupal\Component\Uuid;
|
||||
|
||||
/**
|
||||
* UUID implementation using the PECL extension.
|
||||
*/
|
||||
class Pecl implements UuidInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function generate() {
|
||||
return uuid_create(UUID_TYPE_DEFAULT);
|
||||
}
|
||||
}
|
50
core/lib/Drupal/Component/Uuid/Php.php
Normal file
50
core/lib/Drupal/Component/Uuid/Php.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Component\Uuid\Php.
|
||||
*/
|
||||
|
||||
namespace Drupal\Component\Uuid;
|
||||
|
||||
use Drupal\Component\Utility\Crypt;
|
||||
|
||||
/**
|
||||
* Generates a UUID v4 using PHP code.
|
||||
*
|
||||
* Loosely based on Ruby's UUIDTools generate_random logic.
|
||||
*
|
||||
* @see http://uuidtools.rubyforge.org/api/classes/UUIDTools/UUID.html
|
||||
*/
|
||||
class Php implements UuidInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function generate() {
|
||||
$hex = substr(hash('sha256', Crypt::randomBytes(16)), 0, 32);
|
||||
|
||||
// The field names refer to RFC 4122 section 4.1.2.
|
||||
$time_low = substr($hex, 0, 8);
|
||||
$time_mid = substr($hex, 8, 4);
|
||||
|
||||
$time_hi_and_version = base_convert(substr($hex, 12, 4), 16, 10);
|
||||
$time_hi_and_version &= 0x0FFF;
|
||||
$time_hi_and_version |= (4 << 12);
|
||||
|
||||
$clock_seq_hi_and_reserved = base_convert(substr($hex, 16, 4), 16, 10);
|
||||
$clock_seq_hi_and_reserved &= 0x3F;
|
||||
$clock_seq_hi_and_reserved |= 0x80;
|
||||
|
||||
$clock_seq_low = substr($hex, 20, 2);
|
||||
$nodes = substr($hex, 20);
|
||||
|
||||
$uuid = sprintf('%s-%s-%04x-%02x%02x-%s',
|
||||
$time_low, $time_mid,
|
||||
$time_hi_and_version, $clock_seq_hi_and_reserved,
|
||||
$clock_seq_low, $nodes);
|
||||
|
||||
return $uuid;
|
||||
}
|
||||
|
||||
}
|
36
core/lib/Drupal/Component/Uuid/Uuid.php
Normal file
36
core/lib/Drupal/Component/Uuid/Uuid.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Component\Uuid\Uuid.
|
||||
*/
|
||||
|
||||
namespace Drupal\Component\Uuid;
|
||||
|
||||
/**
|
||||
* UUID Helper methods.
|
||||
*/
|
||||
class Uuid {
|
||||
|
||||
/**
|
||||
* The pattern used to validate a UUID string.
|
||||
*/
|
||||
const VALID_PATTERN = '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}';
|
||||
|
||||
/**
|
||||
* Checks that a string appears to be in the format of a UUID.
|
||||
*
|
||||
* Implementations should not implement validation, since UUIDs should be in
|
||||
* a consistent format across all implementations.
|
||||
*
|
||||
* @param string $uuid
|
||||
* The string to test.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the string is well formed, FALSE otherwise.
|
||||
*/
|
||||
public static function isValid($uuid) {
|
||||
return (bool) preg_match('/^' . self::VALID_PATTERN . '$/', $uuid);
|
||||
}
|
||||
|
||||
}
|
22
core/lib/Drupal/Component/Uuid/UuidInterface.php
Normal file
22
core/lib/Drupal/Component/Uuid/UuidInterface.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Component\Uuid\UuidInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\Component\Uuid;
|
||||
|
||||
/**
|
||||
* Interface that defines a UUID backend.
|
||||
*/
|
||||
interface UuidInterface {
|
||||
|
||||
/**
|
||||
* Generates a Universally Unique IDentifier (UUID).
|
||||
*
|
||||
* @return
|
||||
* A 16 byte integer represented as a hex string formatted with 4 hyphens.
|
||||
*/
|
||||
public function generate();
|
||||
}
|
Reference in a new issue