|
2 | 2 |
|
3 | 3 | /**
|
4 | 4 | * @file
|
5 |
| - * Definition of Drupal\Component\Uuid\Uuid. |
| 5 | + * Contains \Drupal\Component\Uuid\Uuid. |
6 | 6 | */
|
7 | 7 |
|
8 | 8 | namespace Drupal\Component\Uuid;
|
9 | 9 |
|
10 | 10 | /**
|
11 |
| - * Factory class for UUIDs. |
12 |
| - * |
13 |
| - * Determines which UUID implementation to use, and uses that to generate |
14 |
| - * and validate UUIDs. |
| 11 | + * UUID Helper methods. |
15 | 12 | */
|
16 | 13 | class Uuid {
|
17 | 14 |
|
18 |
| - /** |
19 |
| - * Holds the UUID implementation. |
20 |
| - * |
21 |
| - * @var Drupal\Component\Uuid\UuidInterface |
22 |
| - */ |
23 |
| - protected $plugin; |
24 |
| - |
25 |
| - /** |
26 |
| - * Instantiates the correct UUID object. |
27 |
| - */ |
28 |
| - public function __construct() { |
29 |
| - $class = $this->determinePlugin(); |
30 |
| - $this->plugin = new $class(); |
31 |
| - } |
32 |
| - |
33 |
| - /** |
34 |
| - * Generates a universally unique identifier. |
35 |
| - * |
36 |
| - * @see Drupal\Component\Uuid\UuidInterface::generate() |
37 |
| - */ |
38 |
| - public function generate() { |
39 |
| - return $this->plugin->generate(); |
40 |
| - } |
41 |
| - |
42 | 15 | /**
|
43 | 16 | * Checks that a string appears to be in the format of a UUID.
|
44 | 17 | *
|
45 |
| - * Plugins should not implement validation, since UUIDs should be in a |
46 |
| - * consistent format across all plugins. |
| 18 | + * Implementations should not implement validation, since UUIDs should be in |
| 19 | + * a consistent format across all implementations. |
47 | 20 | *
|
48 | 21 | * @param string $uuid
|
49 | 22 | * The string to test.
|
50 | 23 | *
|
51 | 24 | * @return bool
|
52 | 25 | * TRUE if the string is well formed, FALSE otherwise.
|
53 | 26 | */
|
54 |
| - public function isValid($uuid) { |
55 |
| - return preg_match("/^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$/", $uuid); |
| 27 | + public static function isValid($uuid) { |
| 28 | + return (bool) preg_match("/^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$/", $uuid); |
56 | 29 | }
|
57 | 30 |
|
58 |
| - /** |
59 |
| - * Determines the optimal implementation to use for generating UUIDs. |
60 |
| - * |
61 |
| - * The selection is made based on the enabled PHP extensions with the |
62 |
| - * most performant available option chosen. |
63 |
| - * |
64 |
| - * @return string |
65 |
| - * The class name for the optimal UUID generator. |
66 |
| - */ |
67 |
| - protected function determinePlugin() { |
68 |
| - static $plugin; |
69 |
| - if (!empty($plugin)) { |
70 |
| - return $plugin; |
71 |
| - } |
72 |
| - |
73 |
| - $plugin = 'Drupal\Component\Uuid\Php'; |
74 |
| - |
75 |
| - // Debian/Ubuntu uses the (broken) OSSP extension as their UUID |
76 |
| - // implementation. The OSSP implementation is not compatible with the |
77 |
| - // PECL functions. |
78 |
| - if (function_exists('uuid_create') && !function_exists('uuid_make')) { |
79 |
| - $plugin = 'Drupal\Component\Uuid\Pecl'; |
80 |
| - } |
81 |
| - // Try to use the COM implementation for Windows users. |
82 |
| - elseif (function_exists('com_create_guid')) { |
83 |
| - $plugin = 'Drupal\Component\Uuid\Com'; |
84 |
| - } |
85 |
| - return $plugin; |
86 |
| - } |
87 | 31 | }
|
0 commit comments