@@ -12,39 +12,39 @@ |
||
12 | 12 | use Symfony\Polyfill\Intl\Grapheme as p; |
13 | 13 | |
14 | 14 | if (!defined('GRAPHEME_EXTR_COUNT')) { |
15 | - define('GRAPHEME_EXTR_COUNT', 0); |
|
15 | + define('GRAPHEME_EXTR_COUNT', 0); |
|
16 | 16 | } |
17 | 17 | if (!defined('GRAPHEME_EXTR_MAXBYTES')) { |
18 | - define('GRAPHEME_EXTR_MAXBYTES', 1); |
|
18 | + define('GRAPHEME_EXTR_MAXBYTES', 1); |
|
19 | 19 | } |
20 | 20 | if (!defined('GRAPHEME_EXTR_MAXCHARS')) { |
21 | - define('GRAPHEME_EXTR_MAXCHARS', 2); |
|
21 | + define('GRAPHEME_EXTR_MAXCHARS', 2); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | if (!function_exists('grapheme_extract')) { |
25 | - function grapheme_extract(?string $haystack, ?int $size, ?int $type = GRAPHEME_EXTR_COUNT, ?int $offset = 0, &$next = null): string|false { return p\Grapheme::grapheme_extract((string) $haystack, (int) $size, (int) $type, (int) $offset, $next); } |
|
25 | + function grapheme_extract(?string $haystack, ?int $size, ?int $type = GRAPHEME_EXTR_COUNT, ?int $offset = 0, &$next = null): string|false { return p\Grapheme::grapheme_extract((string) $haystack, (int) $size, (int) $type, (int) $offset, $next); } |
|
26 | 26 | } |
27 | 27 | if (!function_exists('grapheme_stripos')) { |
28 | - function grapheme_stripos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_stripos((string) $haystack, (string) $needle, (int) $offset); } |
|
28 | + function grapheme_stripos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_stripos((string) $haystack, (string) $needle, (int) $offset); } |
|
29 | 29 | } |
30 | 30 | if (!function_exists('grapheme_stristr')) { |
31 | - function grapheme_stristr(?string $haystack, ?string $needle, ?bool $beforeNeedle = false): string|false { return p\Grapheme::grapheme_stristr((string) $haystack, (string) $needle, (bool) $beforeNeedle); } |
|
31 | + function grapheme_stristr(?string $haystack, ?string $needle, ?bool $beforeNeedle = false): string|false { return p\Grapheme::grapheme_stristr((string) $haystack, (string) $needle, (bool) $beforeNeedle); } |
|
32 | 32 | } |
33 | 33 | if (!function_exists('grapheme_strlen')) { |
34 | - function grapheme_strlen(?string $string): int|false|null { return p\Grapheme::grapheme_strlen((string) $string); } |
|
34 | + function grapheme_strlen(?string $string): int|false|null { return p\Grapheme::grapheme_strlen((string) $string); } |
|
35 | 35 | } |
36 | 36 | if (!function_exists('grapheme_strpos')) { |
37 | - function grapheme_strpos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strpos((string) $haystack, (string) $needle, (int) $offset); } |
|
37 | + function grapheme_strpos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strpos((string) $haystack, (string) $needle, (int) $offset); } |
|
38 | 38 | } |
39 | 39 | if (!function_exists('grapheme_strripos')) { |
40 | - function grapheme_strripos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strripos((string) $haystack, (string) $needle, (int) $offset); } |
|
40 | + function grapheme_strripos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strripos((string) $haystack, (string) $needle, (int) $offset); } |
|
41 | 41 | } |
42 | 42 | if (!function_exists('grapheme_strrpos')) { |
43 | - function grapheme_strrpos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strrpos((string) $haystack, (string) $needle, (int) $offset); } |
|
43 | + function grapheme_strrpos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strrpos((string) $haystack, (string) $needle, (int) $offset); } |
|
44 | 44 | } |
45 | 45 | if (!function_exists('grapheme_strstr')) { |
46 | - function grapheme_strstr(?string $haystack, ?string $needle, ?bool $beforeNeedle = false): string|false { return p\Grapheme::grapheme_strstr((string) $haystack, (string) $needle, (bool) $beforeNeedle); } |
|
46 | + function grapheme_strstr(?string $haystack, ?string $needle, ?bool $beforeNeedle = false): string|false { return p\Grapheme::grapheme_strstr((string) $haystack, (string) $needle, (bool) $beforeNeedle); } |
|
47 | 47 | } |
48 | 48 | if (!function_exists('grapheme_substr')) { |
49 | - function grapheme_substr(?string $string, ?int $offset, ?int $length = null): string|false { return p\Grapheme::grapheme_substr((string) $string, (int) $offset, $length); } |
|
49 | + function grapheme_substr(?string $string, ?int $offset, ?int $length = null): string|false { return p\Grapheme::grapheme_substr((string) $string, (int) $offset, $length); } |
|
50 | 50 | } |
@@ -11,40 +11,40 @@ |
||
11 | 11 | |
12 | 12 | use Symfony\Polyfill\Intl\Grapheme as p; |
13 | 13 | |
14 | -if (!defined('GRAPHEME_EXTR_COUNT')) { |
|
15 | - define('GRAPHEME_EXTR_COUNT', 0); |
|
14 | +if ( ! defined( 'GRAPHEME_EXTR_COUNT' ) ) { |
|
15 | + define( 'GRAPHEME_EXTR_COUNT', 0 ); |
|
16 | 16 | } |
17 | -if (!defined('GRAPHEME_EXTR_MAXBYTES')) { |
|
18 | - define('GRAPHEME_EXTR_MAXBYTES', 1); |
|
17 | +if ( ! defined( 'GRAPHEME_EXTR_MAXBYTES' ) ) { |
|
18 | + define( 'GRAPHEME_EXTR_MAXBYTES', 1 ); |
|
19 | 19 | } |
20 | -if (!defined('GRAPHEME_EXTR_MAXCHARS')) { |
|
21 | - define('GRAPHEME_EXTR_MAXCHARS', 2); |
|
20 | +if ( ! defined( 'GRAPHEME_EXTR_MAXCHARS' ) ) { |
|
21 | + define( 'GRAPHEME_EXTR_MAXCHARS', 2 ); |
|
22 | 22 | } |
23 | 23 | |
24 | -if (!function_exists('grapheme_extract')) { |
|
25 | - function grapheme_extract(?string $haystack, ?int $size, ?int $type = GRAPHEME_EXTR_COUNT, ?int $offset = 0, &$next = null): string|false { return p\Grapheme::grapheme_extract((string) $haystack, (int) $size, (int) $type, (int) $offset, $next); } |
|
24 | +if ( ! function_exists( 'grapheme_extract' ) ) { |
|
25 | + function grapheme_extract( ?string $haystack, ?int $size, ?int $type = GRAPHEME_EXTR_COUNT, ?int $offset = 0, &$next = null ): string | false { return p\Grapheme::grapheme_extract( (string)$haystack, (int)$size, (int)$type, (int)$offset, $next ); } |
|
26 | 26 | } |
27 | -if (!function_exists('grapheme_stripos')) { |
|
28 | - function grapheme_stripos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_stripos((string) $haystack, (string) $needle, (int) $offset); } |
|
27 | +if ( ! function_exists( 'grapheme_stripos' ) ) { |
|
28 | + function grapheme_stripos( ?string $haystack, ?string $needle, ?int $offset = 0 ): int | false { return p\Grapheme::grapheme_stripos( (string)$haystack, (string)$needle, (int)$offset ); } |
|
29 | 29 | } |
30 | -if (!function_exists('grapheme_stristr')) { |
|
31 | - function grapheme_stristr(?string $haystack, ?string $needle, ?bool $beforeNeedle = false): string|false { return p\Grapheme::grapheme_stristr((string) $haystack, (string) $needle, (bool) $beforeNeedle); } |
|
30 | +if ( ! function_exists( 'grapheme_stristr' ) ) { |
|
31 | + function grapheme_stristr( ?string $haystack, ?string $needle, ?bool $beforeNeedle = false ): string | false { return p\Grapheme::grapheme_stristr( (string)$haystack, (string)$needle, (bool)$beforeNeedle ); } |
|
32 | 32 | } |
33 | -if (!function_exists('grapheme_strlen')) { |
|
34 | - function grapheme_strlen(?string $string): int|false|null { return p\Grapheme::grapheme_strlen((string) $string); } |
|
33 | +if ( ! function_exists( 'grapheme_strlen' ) ) { |
|
34 | + function grapheme_strlen( ?string $string ): int | false | null { return p\Grapheme::grapheme_strlen( (string)$string ); } |
|
35 | 35 | } |
36 | -if (!function_exists('grapheme_strpos')) { |
|
37 | - function grapheme_strpos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strpos((string) $haystack, (string) $needle, (int) $offset); } |
|
36 | +if ( ! function_exists( 'grapheme_strpos' ) ) { |
|
37 | + function grapheme_strpos( ?string $haystack, ?string $needle, ?int $offset = 0 ): int | false { return p\Grapheme::grapheme_strpos( (string)$haystack, (string)$needle, (int)$offset ); } |
|
38 | 38 | } |
39 | -if (!function_exists('grapheme_strripos')) { |
|
40 | - function grapheme_strripos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strripos((string) $haystack, (string) $needle, (int) $offset); } |
|
39 | +if ( ! function_exists( 'grapheme_strripos' ) ) { |
|
40 | + function grapheme_strripos( ?string $haystack, ?string $needle, ?int $offset = 0 ): int | false { return p\Grapheme::grapheme_strripos( (string)$haystack, (string)$needle, (int)$offset ); } |
|
41 | 41 | } |
42 | -if (!function_exists('grapheme_strrpos')) { |
|
43 | - function grapheme_strrpos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strrpos((string) $haystack, (string) $needle, (int) $offset); } |
|
42 | +if ( ! function_exists( 'grapheme_strrpos' ) ) { |
|
43 | + function grapheme_strrpos( ?string $haystack, ?string $needle, ?int $offset = 0 ): int | false { return p\Grapheme::grapheme_strrpos( (string)$haystack, (string)$needle, (int)$offset ); } |
|
44 | 44 | } |
45 | -if (!function_exists('grapheme_strstr')) { |
|
46 | - function grapheme_strstr(?string $haystack, ?string $needle, ?bool $beforeNeedle = false): string|false { return p\Grapheme::grapheme_strstr((string) $haystack, (string) $needle, (bool) $beforeNeedle); } |
|
45 | +if ( ! function_exists( 'grapheme_strstr' ) ) { |
|
46 | + function grapheme_strstr( ?string $haystack, ?string $needle, ?bool $beforeNeedle = false ): string | false { return p\Grapheme::grapheme_strstr( (string)$haystack, (string)$needle, (bool)$beforeNeedle ); } |
|
47 | 47 | } |
48 | -if (!function_exists('grapheme_substr')) { |
|
49 | - function grapheme_substr(?string $string, ?int $offset, ?int $length = null): string|false { return p\Grapheme::grapheme_substr((string) $string, (int) $offset, $length); } |
|
48 | +if ( ! function_exists( 'grapheme_substr' ) ) { |
|
49 | + function grapheme_substr( ?string $string, ?int $offset, ?int $length = null ): string | false { return p\Grapheme::grapheme_substr( (string)$string, (int)$offset, $length ); } |
|
50 | 50 | } |
@@ -28,26 +28,26 @@ |
||
28 | 28 | */ |
29 | 29 | interface ServiceSubscriberInterface |
30 | 30 | { |
31 | - /** |
|
32 | - * Returns an array of service types required by such instances, optionally keyed by the service names used internally. |
|
33 | - * |
|
34 | - * For mandatory dependencies: |
|
35 | - * |
|
36 | - * * ['logger' => 'Psr\Log\LoggerInterface'] means the objects use the "logger" name |
|
37 | - * internally to fetch a service which must implement Psr\Log\LoggerInterface. |
|
38 | - * * ['loggers' => 'Psr\Log\LoggerInterface[]'] means the objects use the "loggers" name |
|
39 | - * internally to fetch an iterable of Psr\Log\LoggerInterface instances. |
|
40 | - * * ['Psr\Log\LoggerInterface'] is a shortcut for |
|
41 | - * * ['Psr\Log\LoggerInterface' => 'Psr\Log\LoggerInterface'] |
|
42 | - * |
|
43 | - * otherwise: |
|
44 | - * |
|
45 | - * * ['logger' => '?Psr\Log\LoggerInterface'] denotes an optional dependency |
|
46 | - * * ['loggers' => '?Psr\Log\LoggerInterface[]'] denotes an optional iterable dependency |
|
47 | - * * ['?Psr\Log\LoggerInterface'] is a shortcut for |
|
48 | - * * ['Psr\Log\LoggerInterface' => '?Psr\Log\LoggerInterface'] |
|
49 | - * |
|
50 | - * @return string[] The required service types, optionally keyed by service names |
|
51 | - */ |
|
52 | - public static function getSubscribedServices(); |
|
31 | + /** |
|
32 | + * Returns an array of service types required by such instances, optionally keyed by the service names used internally. |
|
33 | + * |
|
34 | + * For mandatory dependencies: |
|
35 | + * |
|
36 | + * * ['logger' => 'Psr\Log\LoggerInterface'] means the objects use the "logger" name |
|
37 | + * internally to fetch a service which must implement Psr\Log\LoggerInterface. |
|
38 | + * * ['loggers' => 'Psr\Log\LoggerInterface[]'] means the objects use the "loggers" name |
|
39 | + * internally to fetch an iterable of Psr\Log\LoggerInterface instances. |
|
40 | + * * ['Psr\Log\LoggerInterface'] is a shortcut for |
|
41 | + * * ['Psr\Log\LoggerInterface' => 'Psr\Log\LoggerInterface'] |
|
42 | + * |
|
43 | + * otherwise: |
|
44 | + * |
|
45 | + * * ['logger' => '?Psr\Log\LoggerInterface'] denotes an optional dependency |
|
46 | + * * ['loggers' => '?Psr\Log\LoggerInterface[]'] denotes an optional iterable dependency |
|
47 | + * * ['?Psr\Log\LoggerInterface'] is a shortcut for |
|
48 | + * * ['Psr\Log\LoggerInterface' => '?Psr\Log\LoggerInterface'] |
|
49 | + * |
|
50 | + * @return string[] The required service types, optionally keyed by service names |
|
51 | + */ |
|
52 | + public static function getSubscribedServices(); |
|
53 | 53 | } |
@@ -26,8 +26,7 @@ |
||
26 | 26 | * |
27 | 27 | * @author Nicolas Grekas <[email protected]> |
28 | 28 | */ |
29 | -interface ServiceSubscriberInterface |
|
30 | -{ |
|
29 | +interface ServiceSubscriberInterface { |
|
31 | 30 | /** |
32 | 31 | * Returns an array of service types required by such instances, optionally keyed by the service names used internally. |
33 | 32 | * |
@@ -20,6 +20,5 @@ |
||
20 | 20 | * @author Alexander M. Turek <[email protected]> |
21 | 21 | */ |
22 | 22 | #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)] |
23 | -final class Required |
|
24 | -{ |
|
23 | +final class Required { |
|
25 | 24 | } |
@@ -21,16 +21,16 @@ |
||
21 | 21 | */ |
22 | 22 | interface ServiceProviderInterface extends ContainerInterface |
23 | 23 | { |
24 | - /** |
|
25 | - * Returns an associative array of service types keyed by the identifiers provided by the current container. |
|
26 | - * |
|
27 | - * Examples: |
|
28 | - * |
|
29 | - * * ['logger' => 'Psr\Log\LoggerInterface'] means the object provides a service named "logger" that implements Psr\Log\LoggerInterface |
|
30 | - * * ['foo' => '?'] means the container provides service name "foo" of unspecified type |
|
31 | - * * ['bar' => '?Bar\Baz'] means the container provides a service "bar" of type Bar\Baz|null |
|
32 | - * |
|
33 | - * @return string[] The provided service types, keyed by service names |
|
34 | - */ |
|
35 | - public function getProvidedServices(): array; |
|
24 | + /** |
|
25 | + * Returns an associative array of service types keyed by the identifiers provided by the current container. |
|
26 | + * |
|
27 | + * Examples: |
|
28 | + * |
|
29 | + * * ['logger' => 'Psr\Log\LoggerInterface'] means the object provides a service named "logger" that implements Psr\Log\LoggerInterface |
|
30 | + * * ['foo' => '?'] means the container provides service name "foo" of unspecified type |
|
31 | + * * ['bar' => '?Bar\Baz'] means the container provides a service "bar" of type Bar\Baz|null |
|
32 | + * |
|
33 | + * @return string[] The provided service types, keyed by service names |
|
34 | + */ |
|
35 | + public function getProvidedServices(): array; |
|
36 | 36 | } |
@@ -19,8 +19,7 @@ |
||
19 | 19 | * @author Nicolas Grekas <[email protected]> |
20 | 20 | * @author Mateusz Sip <[email protected]> |
21 | 21 | */ |
22 | -interface ServiceProviderInterface extends ContainerInterface |
|
23 | -{ |
|
22 | +interface ServiceProviderInterface extends ContainerInterface { |
|
24 | 23 | /** |
25 | 24 | * Returns an associative array of service types keyed by the identifiers provided by the current container. |
26 | 25 | * |
@@ -26,103 +26,103 @@ |
||
26 | 26 | */ |
27 | 27 | trait ServiceLocatorTrait |
28 | 28 | { |
29 | - private $factories; |
|
30 | - private $loading = []; |
|
31 | - private $providedTypes; |
|
32 | - |
|
33 | - /** |
|
34 | - * @param callable[] $factories |
|
35 | - */ |
|
36 | - public function __construct(array $factories) |
|
37 | - { |
|
38 | - $this->factories = $factories; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * {@inheritdoc} |
|
43 | - * |
|
44 | - * @return bool |
|
45 | - */ |
|
46 | - public function has(string $id) |
|
47 | - { |
|
48 | - return isset($this->factories[$id]); |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * {@inheritdoc} |
|
53 | - * |
|
54 | - * @return mixed |
|
55 | - */ |
|
56 | - public function get(string $id) |
|
57 | - { |
|
58 | - if (!isset($this->factories[$id])) { |
|
59 | - throw $this->createNotFoundException($id); |
|
60 | - } |
|
61 | - |
|
62 | - if (isset($this->loading[$id])) { |
|
63 | - $ids = array_values($this->loading); |
|
64 | - $ids = \array_slice($this->loading, array_search($id, $ids)); |
|
65 | - $ids[] = $id; |
|
66 | - |
|
67 | - throw $this->createCircularReferenceException($id, $ids); |
|
68 | - } |
|
69 | - |
|
70 | - $this->loading[$id] = $id; |
|
71 | - try { |
|
72 | - return $this->factories[$id]($this); |
|
73 | - } finally { |
|
74 | - unset($this->loading[$id]); |
|
75 | - } |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * {@inheritdoc} |
|
80 | - */ |
|
81 | - public function getProvidedServices(): array |
|
82 | - { |
|
83 | - if (null === $this->providedTypes) { |
|
84 | - $this->providedTypes = []; |
|
85 | - |
|
86 | - foreach ($this->factories as $name => $factory) { |
|
87 | - if (!\is_callable($factory)) { |
|
88 | - $this->providedTypes[$name] = '?'; |
|
89 | - } else { |
|
90 | - $type = (new \ReflectionFunction($factory))->getReturnType(); |
|
91 | - |
|
92 | - $this->providedTypes[$name] = $type ? ($type->allowsNull() ? '?' : '').($type instanceof \ReflectionNamedType ? $type->getName() : $type) : '?'; |
|
93 | - } |
|
94 | - } |
|
95 | - } |
|
96 | - |
|
97 | - return $this->providedTypes; |
|
98 | - } |
|
99 | - |
|
100 | - private function createNotFoundException(string $id): NotFoundExceptionInterface |
|
101 | - { |
|
102 | - if (!$alternatives = array_keys($this->factories)) { |
|
103 | - $message = 'is empty...'; |
|
104 | - } else { |
|
105 | - $last = array_pop($alternatives); |
|
106 | - if ($alternatives) { |
|
107 | - $message = sprintf('only knows about the "%s" and "%s" services.', implode('", "', $alternatives), $last); |
|
108 | - } else { |
|
109 | - $message = sprintf('only knows about the "%s" service.', $last); |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - if ($this->loading) { |
|
114 | - $message = sprintf('The service "%s" has a dependency on a non-existent service "%s". This locator %s', end($this->loading), $id, $message); |
|
115 | - } else { |
|
116 | - $message = sprintf('Service "%s" not found: the current service locator %s', $id, $message); |
|
117 | - } |
|
118 | - |
|
119 | - return new class($message) extends \InvalidArgumentException implements NotFoundExceptionInterface { |
|
120 | - }; |
|
121 | - } |
|
122 | - |
|
123 | - private function createCircularReferenceException(string $id, array $path): ContainerExceptionInterface |
|
124 | - { |
|
125 | - return new class(sprintf('Circular reference detected for service "%s", path: "%s".', $id, implode(' -> ', $path))) extends \RuntimeException implements ContainerExceptionInterface { |
|
126 | - }; |
|
127 | - } |
|
29 | + private $factories; |
|
30 | + private $loading = []; |
|
31 | + private $providedTypes; |
|
32 | + |
|
33 | + /** |
|
34 | + * @param callable[] $factories |
|
35 | + */ |
|
36 | + public function __construct(array $factories) |
|
37 | + { |
|
38 | + $this->factories = $factories; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * {@inheritdoc} |
|
43 | + * |
|
44 | + * @return bool |
|
45 | + */ |
|
46 | + public function has(string $id) |
|
47 | + { |
|
48 | + return isset($this->factories[$id]); |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * {@inheritdoc} |
|
53 | + * |
|
54 | + * @return mixed |
|
55 | + */ |
|
56 | + public function get(string $id) |
|
57 | + { |
|
58 | + if (!isset($this->factories[$id])) { |
|
59 | + throw $this->createNotFoundException($id); |
|
60 | + } |
|
61 | + |
|
62 | + if (isset($this->loading[$id])) { |
|
63 | + $ids = array_values($this->loading); |
|
64 | + $ids = \array_slice($this->loading, array_search($id, $ids)); |
|
65 | + $ids[] = $id; |
|
66 | + |
|
67 | + throw $this->createCircularReferenceException($id, $ids); |
|
68 | + } |
|
69 | + |
|
70 | + $this->loading[$id] = $id; |
|
71 | + try { |
|
72 | + return $this->factories[$id]($this); |
|
73 | + } finally { |
|
74 | + unset($this->loading[$id]); |
|
75 | + } |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * {@inheritdoc} |
|
80 | + */ |
|
81 | + public function getProvidedServices(): array |
|
82 | + { |
|
83 | + if (null === $this->providedTypes) { |
|
84 | + $this->providedTypes = []; |
|
85 | + |
|
86 | + foreach ($this->factories as $name => $factory) { |
|
87 | + if (!\is_callable($factory)) { |
|
88 | + $this->providedTypes[$name] = '?'; |
|
89 | + } else { |
|
90 | + $type = (new \ReflectionFunction($factory))->getReturnType(); |
|
91 | + |
|
92 | + $this->providedTypes[$name] = $type ? ($type->allowsNull() ? '?' : '').($type instanceof \ReflectionNamedType ? $type->getName() : $type) : '?'; |
|
93 | + } |
|
94 | + } |
|
95 | + } |
|
96 | + |
|
97 | + return $this->providedTypes; |
|
98 | + } |
|
99 | + |
|
100 | + private function createNotFoundException(string $id): NotFoundExceptionInterface |
|
101 | + { |
|
102 | + if (!$alternatives = array_keys($this->factories)) { |
|
103 | + $message = 'is empty...'; |
|
104 | + } else { |
|
105 | + $last = array_pop($alternatives); |
|
106 | + if ($alternatives) { |
|
107 | + $message = sprintf('only knows about the "%s" and "%s" services.', implode('", "', $alternatives), $last); |
|
108 | + } else { |
|
109 | + $message = sprintf('only knows about the "%s" service.', $last); |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + if ($this->loading) { |
|
114 | + $message = sprintf('The service "%s" has a dependency on a non-existent service "%s". This locator %s', end($this->loading), $id, $message); |
|
115 | + } else { |
|
116 | + $message = sprintf('Service "%s" not found: the current service locator %s', $id, $message); |
|
117 | + } |
|
118 | + |
|
119 | + return new class($message) extends \InvalidArgumentException implements NotFoundExceptionInterface { |
|
120 | + }; |
|
121 | + } |
|
122 | + |
|
123 | + private function createCircularReferenceException(string $id, array $path): ContainerExceptionInterface |
|
124 | + { |
|
125 | + return new class(sprintf('Circular reference detected for service "%s", path: "%s".', $id, implode(' -> ', $path))) extends \RuntimeException implements ContainerExceptionInterface { |
|
126 | + }; |
|
127 | + } |
|
128 | 128 | } |
@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | use Psr\Container\NotFoundExceptionInterface; |
16 | 16 | |
17 | 17 | // Help opcache.preload discover always-needed symbols |
18 | -class_exists(ContainerExceptionInterface::class); |
|
19 | -class_exists(NotFoundExceptionInterface::class); |
|
18 | +class_exists( ContainerExceptionInterface::class ); |
|
19 | +class_exists( NotFoundExceptionInterface::class ); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * A trait to help implement ServiceProviderInterface. |
@@ -27,13 +27,13 @@ discard block |
||
27 | 27 | trait ServiceLocatorTrait |
28 | 28 | { |
29 | 29 | private $factories; |
30 | - private $loading = []; |
|
30 | + private $loading = [ ]; |
|
31 | 31 | private $providedTypes; |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * @param callable[] $factories |
35 | 35 | */ |
36 | - public function __construct(array $factories) |
|
36 | + public function __construct( array $factories ) |
|
37 | 37 | { |
38 | 38 | $this->factories = $factories; |
39 | 39 | } |
@@ -43,9 +43,9 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @return bool |
45 | 45 | */ |
46 | - public function has(string $id) |
|
46 | + public function has( string $id ) |
|
47 | 47 | { |
48 | - return isset($this->factories[$id]); |
|
48 | + return isset( $this->factories[ $id ] ); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -53,25 +53,25 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return mixed |
55 | 55 | */ |
56 | - public function get(string $id) |
|
56 | + public function get( string $id ) |
|
57 | 57 | { |
58 | - if (!isset($this->factories[$id])) { |
|
59 | - throw $this->createNotFoundException($id); |
|
58 | + if ( ! isset( $this->factories[ $id ] ) ) { |
|
59 | + throw $this->createNotFoundException( $id ); |
|
60 | 60 | } |
61 | 61 | |
62 | - if (isset($this->loading[$id])) { |
|
63 | - $ids = array_values($this->loading); |
|
64 | - $ids = \array_slice($this->loading, array_search($id, $ids)); |
|
65 | - $ids[] = $id; |
|
62 | + if ( isset( $this->loading[ $id ] ) ) { |
|
63 | + $ids = array_values( $this->loading ); |
|
64 | + $ids = \array_slice( $this->loading, array_search( $id, $ids ) ); |
|
65 | + $ids[ ] = $id; |
|
66 | 66 | |
67 | - throw $this->createCircularReferenceException($id, $ids); |
|
67 | + throw $this->createCircularReferenceException( $id, $ids ); |
|
68 | 68 | } |
69 | 69 | |
70 | - $this->loading[$id] = $id; |
|
70 | + $this->loading[ $id ] = $id; |
|
71 | 71 | try { |
72 | - return $this->factories[$id]($this); |
|
72 | + return $this->factories[ $id ]( $this ); |
|
73 | 73 | } finally { |
74 | - unset($this->loading[$id]); |
|
74 | + unset( $this->loading[ $id ] ); |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 | |
@@ -80,16 +80,16 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function getProvidedServices(): array |
82 | 82 | { |
83 | - if (null === $this->providedTypes) { |
|
84 | - $this->providedTypes = []; |
|
83 | + if ( null === $this->providedTypes ) { |
|
84 | + $this->providedTypes = [ ]; |
|
85 | 85 | |
86 | - foreach ($this->factories as $name => $factory) { |
|
87 | - if (!\is_callable($factory)) { |
|
88 | - $this->providedTypes[$name] = '?'; |
|
86 | + foreach ( $this->factories as $name => $factory ) { |
|
87 | + if ( ! \is_callable( $factory ) ) { |
|
88 | + $this->providedTypes[ $name ] = '?'; |
|
89 | 89 | } else { |
90 | - $type = (new \ReflectionFunction($factory))->getReturnType(); |
|
90 | + $type = ( new \ReflectionFunction( $factory ) )->getReturnType(); |
|
91 | 91 | |
92 | - $this->providedTypes[$name] = $type ? ($type->allowsNull() ? '?' : '').($type instanceof \ReflectionNamedType ? $type->getName() : $type) : '?'; |
|
92 | + $this->providedTypes[ $name ] = $type ? ( $type->allowsNull() ? '?' : '' ) . ( $type instanceof \ReflectionNamedType ? $type->getName() : $type ) : '?'; |
|
93 | 93 | } |
94 | 94 | } |
95 | 95 | } |
@@ -97,32 +97,32 @@ discard block |
||
97 | 97 | return $this->providedTypes; |
98 | 98 | } |
99 | 99 | |
100 | - private function createNotFoundException(string $id): NotFoundExceptionInterface |
|
100 | + private function createNotFoundException( string $id ): NotFoundExceptionInterface |
|
101 | 101 | { |
102 | - if (!$alternatives = array_keys($this->factories)) { |
|
102 | + if ( ! $alternatives = array_keys( $this->factories ) ) { |
|
103 | 103 | $message = 'is empty...'; |
104 | 104 | } else { |
105 | - $last = array_pop($alternatives); |
|
106 | - if ($alternatives) { |
|
107 | - $message = sprintf('only knows about the "%s" and "%s" services.', implode('", "', $alternatives), $last); |
|
105 | + $last = array_pop( $alternatives ); |
|
106 | + if ( $alternatives ) { |
|
107 | + $message = sprintf( 'only knows about the "%s" and "%s" services.', implode( '", "', $alternatives ), $last ); |
|
108 | 108 | } else { |
109 | - $message = sprintf('only knows about the "%s" service.', $last); |
|
109 | + $message = sprintf( 'only knows about the "%s" service.', $last ); |
|
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
113 | - if ($this->loading) { |
|
114 | - $message = sprintf('The service "%s" has a dependency on a non-existent service "%s". This locator %s', end($this->loading), $id, $message); |
|
113 | + if ( $this->loading ) { |
|
114 | + $message = sprintf( 'The service "%s" has a dependency on a non-existent service "%s". This locator %s', end( $this->loading ), $id, $message ); |
|
115 | 115 | } else { |
116 | - $message = sprintf('Service "%s" not found: the current service locator %s', $id, $message); |
|
116 | + $message = sprintf( 'Service "%s" not found: the current service locator %s', $id, $message ); |
|
117 | 117 | } |
118 | 118 | |
119 | - return new class($message) extends \InvalidArgumentException implements NotFoundExceptionInterface { |
|
119 | + return new class( $message ) extends \InvalidArgumentException implements NotFoundExceptionInterface { |
|
120 | 120 | }; |
121 | 121 | } |
122 | 122 | |
123 | - private function createCircularReferenceException(string $id, array $path): ContainerExceptionInterface |
|
123 | + private function createCircularReferenceException( string $id, array $path ): ContainerExceptionInterface |
|
124 | 124 | { |
125 | - return new class(sprintf('Circular reference detected for service "%s", path: "%s".', $id, implode(' -> ', $path))) extends \RuntimeException implements ContainerExceptionInterface { |
|
125 | + return new class( sprintf( 'Circular reference detected for service "%s", path: "%s".', $id, implode( ' -> ', $path ) ) ) extends \RuntimeException implements ContainerExceptionInterface { |
|
126 | 126 | }; |
127 | 127 | } |
128 | 128 | } |
@@ -24,8 +24,7 @@ discard block |
||
24 | 24 | * @author Robin Chalas <[email protected]> |
25 | 25 | * @author Nicolas Grekas <[email protected]> |
26 | 26 | */ |
27 | -trait ServiceLocatorTrait |
|
28 | -{ |
|
27 | +trait ServiceLocatorTrait { |
|
29 | 28 | private $factories; |
30 | 29 | private $loading = []; |
31 | 30 | private $providedTypes; |
@@ -33,8 +32,7 @@ discard block |
||
33 | 32 | /** |
34 | 33 | * @param callable[] $factories |
35 | 34 | */ |
36 | - public function __construct(array $factories) |
|
37 | - { |
|
35 | + public function __construct(array $factories) { |
|
38 | 36 | $this->factories = $factories; |
39 | 37 | } |
40 | 38 | |
@@ -43,8 +41,7 @@ discard block |
||
43 | 41 | * |
44 | 42 | * @return bool |
45 | 43 | */ |
46 | - public function has(string $id) |
|
47 | - { |
|
44 | + public function has(string $id) { |
|
48 | 45 | return isset($this->factories[$id]); |
49 | 46 | } |
50 | 47 | |
@@ -53,8 +50,7 @@ discard block |
||
53 | 50 | * |
54 | 51 | * @return mixed |
55 | 52 | */ |
56 | - public function get(string $id) |
|
57 | - { |
|
53 | + public function get(string $id) { |
|
58 | 54 | if (!isset($this->factories[$id])) { |
59 | 55 | throw $this->createNotFoundException($id); |
60 | 56 | } |
@@ -21,46 +21,46 @@ |
||
21 | 21 | */ |
22 | 22 | trait ServiceSubscriberTrait |
23 | 23 | { |
24 | - /** @var ContainerInterface */ |
|
25 | - protected $container; |
|
24 | + /** @var ContainerInterface */ |
|
25 | + protected $container; |
|
26 | 26 | |
27 | - /** |
|
28 | - * {@inheritdoc} |
|
29 | - */ |
|
30 | - public static function getSubscribedServices(): array |
|
31 | - { |
|
32 | - static $services; |
|
27 | + /** |
|
28 | + * {@inheritdoc} |
|
29 | + */ |
|
30 | + public static function getSubscribedServices(): array |
|
31 | + { |
|
32 | + static $services; |
|
33 | 33 | |
34 | - if (null !== $services) { |
|
35 | - return $services; |
|
36 | - } |
|
34 | + if (null !== $services) { |
|
35 | + return $services; |
|
36 | + } |
|
37 | 37 | |
38 | - $services = \is_callable(['parent', __FUNCTION__]) ? parent::getSubscribedServices() : []; |
|
38 | + $services = \is_callable(['parent', __FUNCTION__]) ? parent::getSubscribedServices() : []; |
|
39 | 39 | |
40 | - foreach ((new \ReflectionClass(self::class))->getMethods() as $method) { |
|
41 | - if ($method->isStatic() || $method->isAbstract() || $method->isGenerator() || $method->isInternal() || $method->getNumberOfRequiredParameters()) { |
|
42 | - continue; |
|
43 | - } |
|
40 | + foreach ((new \ReflectionClass(self::class))->getMethods() as $method) { |
|
41 | + if ($method->isStatic() || $method->isAbstract() || $method->isGenerator() || $method->isInternal() || $method->getNumberOfRequiredParameters()) { |
|
42 | + continue; |
|
43 | + } |
|
44 | 44 | |
45 | - if (self::class === $method->getDeclaringClass()->name && ($returnType = $method->getReturnType()) && !$returnType->isBuiltin()) { |
|
46 | - $services[self::class.'::'.$method->name] = '?'.($returnType instanceof \ReflectionNamedType ? $returnType->getName() : $returnType); |
|
47 | - } |
|
48 | - } |
|
45 | + if (self::class === $method->getDeclaringClass()->name && ($returnType = $method->getReturnType()) && !$returnType->isBuiltin()) { |
|
46 | + $services[self::class.'::'.$method->name] = '?'.($returnType instanceof \ReflectionNamedType ? $returnType->getName() : $returnType); |
|
47 | + } |
|
48 | + } |
|
49 | 49 | |
50 | - return $services; |
|
51 | - } |
|
50 | + return $services; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @required |
|
55 | - */ |
|
56 | - public function setContainer(ContainerInterface $container) |
|
57 | - { |
|
58 | - $this->container = $container; |
|
53 | + /** |
|
54 | + * @required |
|
55 | + */ |
|
56 | + public function setContainer(ContainerInterface $container) |
|
57 | + { |
|
58 | + $this->container = $container; |
|
59 | 59 | |
60 | - if (\is_callable(['parent', __FUNCTION__])) { |
|
61 | - return parent::setContainer($container); |
|
62 | - } |
|
60 | + if (\is_callable(['parent', __FUNCTION__])) { |
|
61 | + return parent::setContainer($container); |
|
62 | + } |
|
63 | 63 | |
64 | - return null; |
|
65 | - } |
|
64 | + return null; |
|
65 | + } |
|
66 | 66 | } |
@@ -31,19 +31,19 @@ discard block |
||
31 | 31 | { |
32 | 32 | static $services; |
33 | 33 | |
34 | - if (null !== $services) { |
|
34 | + if ( null !== $services ) { |
|
35 | 35 | return $services; |
36 | 36 | } |
37 | 37 | |
38 | - $services = \is_callable(['parent', __FUNCTION__]) ? parent::getSubscribedServices() : []; |
|
38 | + $services = \is_callable( [ 'parent', __FUNCTION__ ] ) ? parent::getSubscribedServices() : [ ]; |
|
39 | 39 | |
40 | - foreach ((new \ReflectionClass(self::class))->getMethods() as $method) { |
|
41 | - if ($method->isStatic() || $method->isAbstract() || $method->isGenerator() || $method->isInternal() || $method->getNumberOfRequiredParameters()) { |
|
40 | + foreach ( ( new \ReflectionClass( self::class ) )->getMethods() as $method ) { |
|
41 | + if ( $method->isStatic() || $method->isAbstract() || $method->isGenerator() || $method->isInternal() || $method->getNumberOfRequiredParameters() ) { |
|
42 | 42 | continue; |
43 | 43 | } |
44 | 44 | |
45 | - if (self::class === $method->getDeclaringClass()->name && ($returnType = $method->getReturnType()) && !$returnType->isBuiltin()) { |
|
46 | - $services[self::class.'::'.$method->name] = '?'.($returnType instanceof \ReflectionNamedType ? $returnType->getName() : $returnType); |
|
45 | + if ( self::class === $method->getDeclaringClass()->name && ( $returnType = $method->getReturnType() ) && ! $returnType->isBuiltin() ) { |
|
46 | + $services[ self::class . '::' . $method->name ] = '?' . ( $returnType instanceof \ReflectionNamedType ? $returnType->getName() : $returnType ); |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * @required |
55 | 55 | */ |
56 | - public function setContainer(ContainerInterface $container) |
|
56 | + public function setContainer( ContainerInterface $container ) |
|
57 | 57 | { |
58 | 58 | $this->container = $container; |
59 | 59 | |
60 | - if (\is_callable(['parent', __FUNCTION__])) { |
|
61 | - return parent::setContainer($container); |
|
60 | + if ( \is_callable( [ 'parent', __FUNCTION__ ] ) ) { |
|
61 | + return parent::setContainer( $container ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | return null; |
@@ -19,8 +19,7 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @author Kevin Bond <[email protected]> |
21 | 21 | */ |
22 | -trait ServiceSubscriberTrait |
|
23 | -{ |
|
22 | +trait ServiceSubscriberTrait { |
|
24 | 23 | /** @var ContainerInterface */ |
25 | 24 | protected $container; |
26 | 25 | |
@@ -53,8 +52,7 @@ discard block |
||
53 | 52 | /** |
54 | 53 | * @required |
55 | 54 | */ |
56 | - public function setContainer(ContainerInterface $container) |
|
57 | - { |
|
55 | + public function setContainer(ContainerInterface $container) { |
|
58 | 56 | $this->container = $container; |
59 | 57 | |
60 | 58 | if (\is_callable(['parent', __FUNCTION__])) { |
@@ -26,5 +26,5 @@ |
||
26 | 26 | */ |
27 | 27 | interface ResetInterface |
28 | 28 | { |
29 | - public function reset(); |
|
29 | + public function reset(); |
|
30 | 30 | } |
@@ -24,7 +24,6 @@ |
||
24 | 24 | * process loop (note that we advise making your services stateless instead of |
25 | 25 | * implementing this interface when possible.) |
26 | 26 | */ |
27 | -interface ResetInterface |
|
28 | -{ |
|
27 | +interface ResetInterface { |
|
29 | 28 | public function reset(); |
30 | 29 | } |
@@ -17,76 +17,76 @@ |
||
17 | 17 | |
18 | 18 | abstract class ServiceLocatorTest extends TestCase |
19 | 19 | { |
20 | - protected function getServiceLocator(array $factories) |
|
21 | - { |
|
22 | - return new class($factories) implements ContainerInterface { |
|
23 | - use ServiceLocatorTrait; |
|
24 | - }; |
|
25 | - } |
|
20 | + protected function getServiceLocator(array $factories) |
|
21 | + { |
|
22 | + return new class($factories) implements ContainerInterface { |
|
23 | + use ServiceLocatorTrait; |
|
24 | + }; |
|
25 | + } |
|
26 | 26 | |
27 | - public function testHas() |
|
28 | - { |
|
29 | - $locator = $this->getServiceLocator([ |
|
30 | - 'foo' => function () { return 'bar'; }, |
|
31 | - 'bar' => function () { return 'baz'; }, |
|
32 | - function () { return 'dummy'; }, |
|
33 | - ]); |
|
27 | + public function testHas() |
|
28 | + { |
|
29 | + $locator = $this->getServiceLocator([ |
|
30 | + 'foo' => function () { return 'bar'; }, |
|
31 | + 'bar' => function () { return 'baz'; }, |
|
32 | + function () { return 'dummy'; }, |
|
33 | + ]); |
|
34 | 34 | |
35 | - $this->assertTrue($locator->has('foo')); |
|
36 | - $this->assertTrue($locator->has('bar')); |
|
37 | - $this->assertFalse($locator->has('dummy')); |
|
38 | - } |
|
35 | + $this->assertTrue($locator->has('foo')); |
|
36 | + $this->assertTrue($locator->has('bar')); |
|
37 | + $this->assertFalse($locator->has('dummy')); |
|
38 | + } |
|
39 | 39 | |
40 | - public function testGet() |
|
41 | - { |
|
42 | - $locator = $this->getServiceLocator([ |
|
43 | - 'foo' => function () { return 'bar'; }, |
|
44 | - 'bar' => function () { return 'baz'; }, |
|
45 | - ]); |
|
40 | + public function testGet() |
|
41 | + { |
|
42 | + $locator = $this->getServiceLocator([ |
|
43 | + 'foo' => function () { return 'bar'; }, |
|
44 | + 'bar' => function () { return 'baz'; }, |
|
45 | + ]); |
|
46 | 46 | |
47 | - $this->assertSame('bar', $locator->get('foo')); |
|
48 | - $this->assertSame('baz', $locator->get('bar')); |
|
49 | - } |
|
47 | + $this->assertSame('bar', $locator->get('foo')); |
|
48 | + $this->assertSame('baz', $locator->get('bar')); |
|
49 | + } |
|
50 | 50 | |
51 | - public function testGetDoesNotMemoize() |
|
52 | - { |
|
53 | - $i = 0; |
|
54 | - $locator = $this->getServiceLocator([ |
|
55 | - 'foo' => function () use (&$i) { |
|
56 | - ++$i; |
|
51 | + public function testGetDoesNotMemoize() |
|
52 | + { |
|
53 | + $i = 0; |
|
54 | + $locator = $this->getServiceLocator([ |
|
55 | + 'foo' => function () use (&$i) { |
|
56 | + ++$i; |
|
57 | 57 | |
58 | - return 'bar'; |
|
59 | - }, |
|
60 | - ]); |
|
58 | + return 'bar'; |
|
59 | + }, |
|
60 | + ]); |
|
61 | 61 | |
62 | - $this->assertSame('bar', $locator->get('foo')); |
|
63 | - $this->assertSame('bar', $locator->get('foo')); |
|
64 | - $this->assertSame(2, $i); |
|
65 | - } |
|
62 | + $this->assertSame('bar', $locator->get('foo')); |
|
63 | + $this->assertSame('bar', $locator->get('foo')); |
|
64 | + $this->assertSame(2, $i); |
|
65 | + } |
|
66 | 66 | |
67 | - public function testThrowsOnUndefinedInternalService() |
|
68 | - { |
|
69 | - if (!$this->getExpectedException()) { |
|
70 | - $this->expectException(\Psr\Container\NotFoundExceptionInterface::class); |
|
71 | - $this->expectExceptionMessage('The service "foo" has a dependency on a non-existent service "bar". This locator only knows about the "foo" service.'); |
|
72 | - } |
|
73 | - $locator = $this->getServiceLocator([ |
|
74 | - 'foo' => function () use (&$locator) { return $locator->get('bar'); }, |
|
75 | - ]); |
|
67 | + public function testThrowsOnUndefinedInternalService() |
|
68 | + { |
|
69 | + if (!$this->getExpectedException()) { |
|
70 | + $this->expectException(\Psr\Container\NotFoundExceptionInterface::class); |
|
71 | + $this->expectExceptionMessage('The service "foo" has a dependency on a non-existent service "bar". This locator only knows about the "foo" service.'); |
|
72 | + } |
|
73 | + $locator = $this->getServiceLocator([ |
|
74 | + 'foo' => function () use (&$locator) { return $locator->get('bar'); }, |
|
75 | + ]); |
|
76 | 76 | |
77 | - $locator->get('foo'); |
|
78 | - } |
|
77 | + $locator->get('foo'); |
|
78 | + } |
|
79 | 79 | |
80 | - public function testThrowsOnCircularReference() |
|
81 | - { |
|
82 | - $this->expectException(\Psr\Container\ContainerExceptionInterface::class); |
|
83 | - $this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> baz -> bar".'); |
|
84 | - $locator = $this->getServiceLocator([ |
|
85 | - 'foo' => function () use (&$locator) { return $locator->get('bar'); }, |
|
86 | - 'bar' => function () use (&$locator) { return $locator->get('baz'); }, |
|
87 | - 'baz' => function () use (&$locator) { return $locator->get('bar'); }, |
|
88 | - ]); |
|
80 | + public function testThrowsOnCircularReference() |
|
81 | + { |
|
82 | + $this->expectException(\Psr\Container\ContainerExceptionInterface::class); |
|
83 | + $this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> baz -> bar".'); |
|
84 | + $locator = $this->getServiceLocator([ |
|
85 | + 'foo' => function () use (&$locator) { return $locator->get('bar'); }, |
|
86 | + 'bar' => function () use (&$locator) { return $locator->get('baz'); }, |
|
87 | + 'baz' => function () use (&$locator) { return $locator->get('bar'); }, |
|
88 | + ]); |
|
89 | 89 | |
90 | - $locator->get('foo'); |
|
91 | - } |
|
90 | + $locator->get('foo'); |
|
91 | + } |
|
92 | 92 | } |
@@ -17,76 +17,76 @@ |
||
17 | 17 | |
18 | 18 | abstract class ServiceLocatorTest extends TestCase |
19 | 19 | { |
20 | - protected function getServiceLocator(array $factories) |
|
20 | + protected function getServiceLocator( array $factories ) |
|
21 | 21 | { |
22 | - return new class($factories) implements ContainerInterface { |
|
22 | + return new class( $factories ) implements ContainerInterface { |
|
23 | 23 | use ServiceLocatorTrait; |
24 | 24 | }; |
25 | 25 | } |
26 | 26 | |
27 | 27 | public function testHas() |
28 | 28 | { |
29 | - $locator = $this->getServiceLocator([ |
|
30 | - 'foo' => function () { return 'bar'; }, |
|
31 | - 'bar' => function () { return 'baz'; }, |
|
32 | - function () { return 'dummy'; }, |
|
33 | - ]); |
|
29 | + $locator = $this->getServiceLocator( [ |
|
30 | + 'foo' => function() { return 'bar'; }, |
|
31 | + 'bar' => function() { return 'baz'; }, |
|
32 | + function() { return 'dummy'; }, |
|
33 | + ] ); |
|
34 | 34 | |
35 | - $this->assertTrue($locator->has('foo')); |
|
36 | - $this->assertTrue($locator->has('bar')); |
|
37 | - $this->assertFalse($locator->has('dummy')); |
|
35 | + $this->assertTrue( $locator->has( 'foo' ) ); |
|
36 | + $this->assertTrue( $locator->has( 'bar' ) ); |
|
37 | + $this->assertFalse( $locator->has( 'dummy' ) ); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | public function testGet() |
41 | 41 | { |
42 | - $locator = $this->getServiceLocator([ |
|
43 | - 'foo' => function () { return 'bar'; }, |
|
44 | - 'bar' => function () { return 'baz'; }, |
|
45 | - ]); |
|
42 | + $locator = $this->getServiceLocator( [ |
|
43 | + 'foo' => function() { return 'bar'; }, |
|
44 | + 'bar' => function() { return 'baz'; }, |
|
45 | + ] ); |
|
46 | 46 | |
47 | - $this->assertSame('bar', $locator->get('foo')); |
|
48 | - $this->assertSame('baz', $locator->get('bar')); |
|
47 | + $this->assertSame( 'bar', $locator->get( 'foo' ) ); |
|
48 | + $this->assertSame( 'baz', $locator->get( 'bar' ) ); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | public function testGetDoesNotMemoize() |
52 | 52 | { |
53 | 53 | $i = 0; |
54 | - $locator = $this->getServiceLocator([ |
|
55 | - 'foo' => function () use (&$i) { |
|
54 | + $locator = $this->getServiceLocator( [ |
|
55 | + 'foo' => function() use ( &$i ) { |
|
56 | 56 | ++$i; |
57 | 57 | |
58 | 58 | return 'bar'; |
59 | 59 | }, |
60 | - ]); |
|
60 | + ] ); |
|
61 | 61 | |
62 | - $this->assertSame('bar', $locator->get('foo')); |
|
63 | - $this->assertSame('bar', $locator->get('foo')); |
|
64 | - $this->assertSame(2, $i); |
|
62 | + $this->assertSame( 'bar', $locator->get( 'foo' ) ); |
|
63 | + $this->assertSame( 'bar', $locator->get( 'foo' ) ); |
|
64 | + $this->assertSame( 2, $i ); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | public function testThrowsOnUndefinedInternalService() |
68 | 68 | { |
69 | - if (!$this->getExpectedException()) { |
|
70 | - $this->expectException(\Psr\Container\NotFoundExceptionInterface::class); |
|
71 | - $this->expectExceptionMessage('The service "foo" has a dependency on a non-existent service "bar". This locator only knows about the "foo" service.'); |
|
69 | + if ( ! $this->getExpectedException() ) { |
|
70 | + $this->expectException( \Psr\Container\NotFoundExceptionInterface::class ); |
|
71 | + $this->expectExceptionMessage( 'The service "foo" has a dependency on a non-existent service "bar". This locator only knows about the "foo" service.' ); |
|
72 | 72 | } |
73 | - $locator = $this->getServiceLocator([ |
|
74 | - 'foo' => function () use (&$locator) { return $locator->get('bar'); }, |
|
75 | - ]); |
|
73 | + $locator = $this->getServiceLocator( [ |
|
74 | + 'foo' => function() use ( &$locator ) { return $locator->get( 'bar' ); }, |
|
75 | + ] ); |
|
76 | 76 | |
77 | - $locator->get('foo'); |
|
77 | + $locator->get( 'foo' ); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | public function testThrowsOnCircularReference() |
81 | 81 | { |
82 | - $this->expectException(\Psr\Container\ContainerExceptionInterface::class); |
|
83 | - $this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> baz -> bar".'); |
|
84 | - $locator = $this->getServiceLocator([ |
|
85 | - 'foo' => function () use (&$locator) { return $locator->get('bar'); }, |
|
86 | - 'bar' => function () use (&$locator) { return $locator->get('baz'); }, |
|
87 | - 'baz' => function () use (&$locator) { return $locator->get('bar'); }, |
|
88 | - ]); |
|
82 | + $this->expectException( \Psr\Container\ContainerExceptionInterface::class ); |
|
83 | + $this->expectExceptionMessage( 'Circular reference detected for service "bar", path: "bar -> baz -> bar".' ); |
|
84 | + $locator = $this->getServiceLocator( [ |
|
85 | + 'foo' => function() use ( &$locator ) { return $locator->get( 'bar' ); }, |
|
86 | + 'bar' => function() use ( &$locator ) { return $locator->get( 'baz' ); }, |
|
87 | + 'baz' => function() use ( &$locator ) { return $locator->get( 'bar' ); }, |
|
88 | + ] ); |
|
89 | 89 | |
90 | - $locator->get('foo'); |
|
90 | + $locator->get( 'foo' ); |
|
91 | 91 | } |
92 | 92 | } |
@@ -15,17 +15,14 @@ discard block |
||
15 | 15 | use Psr\Container\ContainerInterface; |
16 | 16 | use Symfony\Contracts\Service\ServiceLocatorTrait; |
17 | 17 | |
18 | -abstract class ServiceLocatorTest extends TestCase |
|
19 | -{ |
|
20 | - protected function getServiceLocator(array $factories) |
|
21 | - { |
|
18 | +abstract class ServiceLocatorTest extends TestCase { |
|
19 | + protected function getServiceLocator(array $factories) { |
|
22 | 20 | return new class($factories) implements ContainerInterface { |
23 | 21 | use ServiceLocatorTrait; |
24 | 22 | }; |
25 | 23 | } |
26 | 24 | |
27 | - public function testHas() |
|
28 | - { |
|
25 | + public function testHas() { |
|
29 | 26 | $locator = $this->getServiceLocator([ |
30 | 27 | 'foo' => function () { return 'bar'; }, |
31 | 28 | 'bar' => function () { return 'baz'; }, |
@@ -37,8 +34,7 @@ discard block |
||
37 | 34 | $this->assertFalse($locator->has('dummy')); |
38 | 35 | } |
39 | 36 | |
40 | - public function testGet() |
|
41 | - { |
|
37 | + public function testGet() { |
|
42 | 38 | $locator = $this->getServiceLocator([ |
43 | 39 | 'foo' => function () { return 'bar'; }, |
44 | 40 | 'bar' => function () { return 'baz'; }, |
@@ -48,8 +44,7 @@ discard block |
||
48 | 44 | $this->assertSame('baz', $locator->get('bar')); |
49 | 45 | } |
50 | 46 | |
51 | - public function testGetDoesNotMemoize() |
|
52 | - { |
|
47 | + public function testGetDoesNotMemoize() { |
|
53 | 48 | $i = 0; |
54 | 49 | $locator = $this->getServiceLocator([ |
55 | 50 | 'foo' => function () use (&$i) { |
@@ -64,8 +59,7 @@ discard block |
||
64 | 59 | $this->assertSame(2, $i); |
65 | 60 | } |
66 | 61 | |
67 | - public function testThrowsOnUndefinedInternalService() |
|
68 | - { |
|
62 | + public function testThrowsOnUndefinedInternalService() { |
|
69 | 63 | if (!$this->getExpectedException()) { |
70 | 64 | $this->expectException(\Psr\Container\NotFoundExceptionInterface::class); |
71 | 65 | $this->expectExceptionMessage('The service "foo" has a dependency on a non-existent service "bar". This locator only knows about the "foo" service.'); |
@@ -77,8 +71,7 @@ discard block |
||
77 | 71 | $locator->get('foo'); |
78 | 72 | } |
79 | 73 | |
80 | - public function testThrowsOnCircularReference() |
|
81 | - { |
|
74 | + public function testThrowsOnCircularReference() { |
|
82 | 75 | $this->expectException(\Psr\Container\ContainerExceptionInterface::class); |
83 | 76 | $this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> baz -> bar".'); |
84 | 77 | $locator = $this->getServiceLocator([ |
@@ -12,136 +12,136 @@ |
||
12 | 12 | use Symfony\Polyfill\Mbstring as p; |
13 | 13 | |
14 | 14 | if (\PHP_VERSION_ID >= 80000) { |
15 | - return require __DIR__.'/bootstrap80.php'; |
|
15 | + return require __DIR__.'/bootstrap80.php'; |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | if (!function_exists('mb_convert_encoding')) { |
19 | - function mb_convert_encoding($string, $to_encoding, $from_encoding = null) { return p\Mbstring::mb_convert_encoding($string, $to_encoding, $from_encoding); } |
|
19 | + function mb_convert_encoding($string, $to_encoding, $from_encoding = null) { return p\Mbstring::mb_convert_encoding($string, $to_encoding, $from_encoding); } |
|
20 | 20 | } |
21 | 21 | if (!function_exists('mb_decode_mimeheader')) { |
22 | - function mb_decode_mimeheader($string) { return p\Mbstring::mb_decode_mimeheader($string); } |
|
22 | + function mb_decode_mimeheader($string) { return p\Mbstring::mb_decode_mimeheader($string); } |
|
23 | 23 | } |
24 | 24 | if (!function_exists('mb_encode_mimeheader')) { |
25 | - function mb_encode_mimeheader($string, $charset = null, $transfer_encoding = null, $newline = "\r\n", $indent = 0) { return p\Mbstring::mb_encode_mimeheader($string, $charset, $transfer_encoding, $newline, $indent); } |
|
25 | + function mb_encode_mimeheader($string, $charset = null, $transfer_encoding = null, $newline = "\r\n", $indent = 0) { return p\Mbstring::mb_encode_mimeheader($string, $charset, $transfer_encoding, $newline, $indent); } |
|
26 | 26 | } |
27 | 27 | if (!function_exists('mb_decode_numericentity')) { |
28 | - function mb_decode_numericentity($string, $map, $encoding = null) { return p\Mbstring::mb_decode_numericentity($string, $map, $encoding); } |
|
28 | + function mb_decode_numericentity($string, $map, $encoding = null) { return p\Mbstring::mb_decode_numericentity($string, $map, $encoding); } |
|
29 | 29 | } |
30 | 30 | if (!function_exists('mb_encode_numericentity')) { |
31 | - function mb_encode_numericentity($string, $map, $encoding = null, $hex = false) { return p\Mbstring::mb_encode_numericentity($string, $map, $encoding, $hex); } |
|
31 | + function mb_encode_numericentity($string, $map, $encoding = null, $hex = false) { return p\Mbstring::mb_encode_numericentity($string, $map, $encoding, $hex); } |
|
32 | 32 | } |
33 | 33 | if (!function_exists('mb_convert_case')) { |
34 | - function mb_convert_case($string, $mode, $encoding = null) { return p\Mbstring::mb_convert_case($string, $mode, $encoding); } |
|
34 | + function mb_convert_case($string, $mode, $encoding = null) { return p\Mbstring::mb_convert_case($string, $mode, $encoding); } |
|
35 | 35 | } |
36 | 36 | if (!function_exists('mb_internal_encoding')) { |
37 | - function mb_internal_encoding($encoding = null) { return p\Mbstring::mb_internal_encoding($encoding); } |
|
37 | + function mb_internal_encoding($encoding = null) { return p\Mbstring::mb_internal_encoding($encoding); } |
|
38 | 38 | } |
39 | 39 | if (!function_exists('mb_language')) { |
40 | - function mb_language($language = null) { return p\Mbstring::mb_language($language); } |
|
40 | + function mb_language($language = null) { return p\Mbstring::mb_language($language); } |
|
41 | 41 | } |
42 | 42 | if (!function_exists('mb_list_encodings')) { |
43 | - function mb_list_encodings() { return p\Mbstring::mb_list_encodings(); } |
|
43 | + function mb_list_encodings() { return p\Mbstring::mb_list_encodings(); } |
|
44 | 44 | } |
45 | 45 | if (!function_exists('mb_encoding_aliases')) { |
46 | - function mb_encoding_aliases($encoding) { return p\Mbstring::mb_encoding_aliases($encoding); } |
|
46 | + function mb_encoding_aliases($encoding) { return p\Mbstring::mb_encoding_aliases($encoding); } |
|
47 | 47 | } |
48 | 48 | if (!function_exists('mb_check_encoding')) { |
49 | - function mb_check_encoding($value = null, $encoding = null) { return p\Mbstring::mb_check_encoding($value, $encoding); } |
|
49 | + function mb_check_encoding($value = null, $encoding = null) { return p\Mbstring::mb_check_encoding($value, $encoding); } |
|
50 | 50 | } |
51 | 51 | if (!function_exists('mb_detect_encoding')) { |
52 | - function mb_detect_encoding($string, $encodings = null, $strict = false) { return p\Mbstring::mb_detect_encoding($string, $encodings, $strict); } |
|
52 | + function mb_detect_encoding($string, $encodings = null, $strict = false) { return p\Mbstring::mb_detect_encoding($string, $encodings, $strict); } |
|
53 | 53 | } |
54 | 54 | if (!function_exists('mb_detect_order')) { |
55 | - function mb_detect_order($encoding = null) { return p\Mbstring::mb_detect_order($encoding); } |
|
55 | + function mb_detect_order($encoding = null) { return p\Mbstring::mb_detect_order($encoding); } |
|
56 | 56 | } |
57 | 57 | if (!function_exists('mb_parse_str')) { |
58 | - function mb_parse_str($string, &$result = []) { parse_str($string, $result); return (bool) $result; } |
|
58 | + function mb_parse_str($string, &$result = []) { parse_str($string, $result); return (bool) $result; } |
|
59 | 59 | } |
60 | 60 | if (!function_exists('mb_strlen')) { |
61 | - function mb_strlen($string, $encoding = null) { return p\Mbstring::mb_strlen($string, $encoding); } |
|
61 | + function mb_strlen($string, $encoding = null) { return p\Mbstring::mb_strlen($string, $encoding); } |
|
62 | 62 | } |
63 | 63 | if (!function_exists('mb_strpos')) { |
64 | - function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strpos($haystack, $needle, $offset, $encoding); } |
|
64 | + function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strpos($haystack, $needle, $offset, $encoding); } |
|
65 | 65 | } |
66 | 66 | if (!function_exists('mb_strtolower')) { |
67 | - function mb_strtolower($string, $encoding = null) { return p\Mbstring::mb_strtolower($string, $encoding); } |
|
67 | + function mb_strtolower($string, $encoding = null) { return p\Mbstring::mb_strtolower($string, $encoding); } |
|
68 | 68 | } |
69 | 69 | if (!function_exists('mb_strtoupper')) { |
70 | - function mb_strtoupper($string, $encoding = null) { return p\Mbstring::mb_strtoupper($string, $encoding); } |
|
70 | + function mb_strtoupper($string, $encoding = null) { return p\Mbstring::mb_strtoupper($string, $encoding); } |
|
71 | 71 | } |
72 | 72 | if (!function_exists('mb_substitute_character')) { |
73 | - function mb_substitute_character($substitute_character = null) { return p\Mbstring::mb_substitute_character($substitute_character); } |
|
73 | + function mb_substitute_character($substitute_character = null) { return p\Mbstring::mb_substitute_character($substitute_character); } |
|
74 | 74 | } |
75 | 75 | if (!function_exists('mb_substr')) { |
76 | - function mb_substr($string, $start, $length = 2147483647, $encoding = null) { return p\Mbstring::mb_substr($string, $start, $length, $encoding); } |
|
76 | + function mb_substr($string, $start, $length = 2147483647, $encoding = null) { return p\Mbstring::mb_substr($string, $start, $length, $encoding); } |
|
77 | 77 | } |
78 | 78 | if (!function_exists('mb_stripos')) { |
79 | - function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_stripos($haystack, $needle, $offset, $encoding); } |
|
79 | + function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_stripos($haystack, $needle, $offset, $encoding); } |
|
80 | 80 | } |
81 | 81 | if (!function_exists('mb_stristr')) { |
82 | - function mb_stristr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_stristr($haystack, $needle, $before_needle, $encoding); } |
|
82 | + function mb_stristr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_stristr($haystack, $needle, $before_needle, $encoding); } |
|
83 | 83 | } |
84 | 84 | if (!function_exists('mb_strrchr')) { |
85 | - function mb_strrchr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strrchr($haystack, $needle, $before_needle, $encoding); } |
|
85 | + function mb_strrchr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strrchr($haystack, $needle, $before_needle, $encoding); } |
|
86 | 86 | } |
87 | 87 | if (!function_exists('mb_strrichr')) { |
88 | - function mb_strrichr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strrichr($haystack, $needle, $before_needle, $encoding); } |
|
88 | + function mb_strrichr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strrichr($haystack, $needle, $before_needle, $encoding); } |
|
89 | 89 | } |
90 | 90 | if (!function_exists('mb_strripos')) { |
91 | - function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strripos($haystack, $needle, $offset, $encoding); } |
|
91 | + function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strripos($haystack, $needle, $offset, $encoding); } |
|
92 | 92 | } |
93 | 93 | if (!function_exists('mb_strrpos')) { |
94 | - function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strrpos($haystack, $needle, $offset, $encoding); } |
|
94 | + function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strrpos($haystack, $needle, $offset, $encoding); } |
|
95 | 95 | } |
96 | 96 | if (!function_exists('mb_strstr')) { |
97 | - function mb_strstr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strstr($haystack, $needle, $before_needle, $encoding); } |
|
97 | + function mb_strstr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strstr($haystack, $needle, $before_needle, $encoding); } |
|
98 | 98 | } |
99 | 99 | if (!function_exists('mb_get_info')) { |
100 | - function mb_get_info($type = 'all') { return p\Mbstring::mb_get_info($type); } |
|
100 | + function mb_get_info($type = 'all') { return p\Mbstring::mb_get_info($type); } |
|
101 | 101 | } |
102 | 102 | if (!function_exists('mb_http_output')) { |
103 | - function mb_http_output($encoding = null) { return p\Mbstring::mb_http_output($encoding); } |
|
103 | + function mb_http_output($encoding = null) { return p\Mbstring::mb_http_output($encoding); } |
|
104 | 104 | } |
105 | 105 | if (!function_exists('mb_strwidth')) { |
106 | - function mb_strwidth($string, $encoding = null) { return p\Mbstring::mb_strwidth($string, $encoding); } |
|
106 | + function mb_strwidth($string, $encoding = null) { return p\Mbstring::mb_strwidth($string, $encoding); } |
|
107 | 107 | } |
108 | 108 | if (!function_exists('mb_substr_count')) { |
109 | - function mb_substr_count($haystack, $needle, $encoding = null) { return p\Mbstring::mb_substr_count($haystack, $needle, $encoding); } |
|
109 | + function mb_substr_count($haystack, $needle, $encoding = null) { return p\Mbstring::mb_substr_count($haystack, $needle, $encoding); } |
|
110 | 110 | } |
111 | 111 | if (!function_exists('mb_output_handler')) { |
112 | - function mb_output_handler($string, $status) { return p\Mbstring::mb_output_handler($string, $status); } |
|
112 | + function mb_output_handler($string, $status) { return p\Mbstring::mb_output_handler($string, $status); } |
|
113 | 113 | } |
114 | 114 | if (!function_exists('mb_http_input')) { |
115 | - function mb_http_input($type = null) { return p\Mbstring::mb_http_input($type); } |
|
115 | + function mb_http_input($type = null) { return p\Mbstring::mb_http_input($type); } |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | if (!function_exists('mb_convert_variables')) { |
119 | - function mb_convert_variables($to_encoding, $from_encoding, &...$vars) { return p\Mbstring::mb_convert_variables($to_encoding, $from_encoding, ...$vars); } |
|
119 | + function mb_convert_variables($to_encoding, $from_encoding, &...$vars) { return p\Mbstring::mb_convert_variables($to_encoding, $from_encoding, ...$vars); } |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | if (!function_exists('mb_ord')) { |
123 | - function mb_ord($string, $encoding = null) { return p\Mbstring::mb_ord($string, $encoding); } |
|
123 | + function mb_ord($string, $encoding = null) { return p\Mbstring::mb_ord($string, $encoding); } |
|
124 | 124 | } |
125 | 125 | if (!function_exists('mb_chr')) { |
126 | - function mb_chr($codepoint, $encoding = null) { return p\Mbstring::mb_chr($codepoint, $encoding); } |
|
126 | + function mb_chr($codepoint, $encoding = null) { return p\Mbstring::mb_chr($codepoint, $encoding); } |
|
127 | 127 | } |
128 | 128 | if (!function_exists('mb_scrub')) { |
129 | - function mb_scrub($string, $encoding = null) { $encoding = null === $encoding ? mb_internal_encoding() : $encoding; return mb_convert_encoding($string, $encoding, $encoding); } |
|
129 | + function mb_scrub($string, $encoding = null) { $encoding = null === $encoding ? mb_internal_encoding() : $encoding; return mb_convert_encoding($string, $encoding, $encoding); } |
|
130 | 130 | } |
131 | 131 | if (!function_exists('mb_str_split')) { |
132 | - function mb_str_split($string, $length = 1, $encoding = null) { return p\Mbstring::mb_str_split($string, $length, $encoding); } |
|
132 | + function mb_str_split($string, $length = 1, $encoding = null) { return p\Mbstring::mb_str_split($string, $length, $encoding); } |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | if (extension_loaded('mbstring')) { |
136 | - return; |
|
136 | + return; |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | if (!defined('MB_CASE_UPPER')) { |
140 | - define('MB_CASE_UPPER', 0); |
|
140 | + define('MB_CASE_UPPER', 0); |
|
141 | 141 | } |
142 | 142 | if (!defined('MB_CASE_LOWER')) { |
143 | - define('MB_CASE_LOWER', 1); |
|
143 | + define('MB_CASE_LOWER', 1); |
|
144 | 144 | } |
145 | 145 | if (!defined('MB_CASE_TITLE')) { |
146 | - define('MB_CASE_TITLE', 2); |
|
146 | + define('MB_CASE_TITLE', 2); |
|
147 | 147 | } |
@@ -11,137 +11,137 @@ |
||
11 | 11 | |
12 | 12 | use Symfony\Polyfill\Mbstring as p; |
13 | 13 | |
14 | -if (\PHP_VERSION_ID >= 80000) { |
|
15 | - return require __DIR__.'/bootstrap80.php'; |
|
14 | +if ( \PHP_VERSION_ID >= 80000 ) { |
|
15 | + return require __DIR__ . '/bootstrap80.php'; |
|
16 | 16 | } |
17 | 17 | |
18 | -if (!function_exists('mb_convert_encoding')) { |
|
19 | - function mb_convert_encoding($string, $to_encoding, $from_encoding = null) { return p\Mbstring::mb_convert_encoding($string, $to_encoding, $from_encoding); } |
|
18 | +if ( ! function_exists( 'mb_convert_encoding' ) ) { |
|
19 | + function mb_convert_encoding( $string, $to_encoding, $from_encoding = null ) { return p\Mbstring::mb_convert_encoding( $string, $to_encoding, $from_encoding ); } |
|
20 | 20 | } |
21 | -if (!function_exists('mb_decode_mimeheader')) { |
|
22 | - function mb_decode_mimeheader($string) { return p\Mbstring::mb_decode_mimeheader($string); } |
|
21 | +if ( ! function_exists( 'mb_decode_mimeheader' ) ) { |
|
22 | + function mb_decode_mimeheader( $string ) { return p\Mbstring::mb_decode_mimeheader( $string ); } |
|
23 | 23 | } |
24 | -if (!function_exists('mb_encode_mimeheader')) { |
|
25 | - function mb_encode_mimeheader($string, $charset = null, $transfer_encoding = null, $newline = "\r\n", $indent = 0) { return p\Mbstring::mb_encode_mimeheader($string, $charset, $transfer_encoding, $newline, $indent); } |
|
24 | +if ( ! function_exists( 'mb_encode_mimeheader' ) ) { |
|
25 | + function mb_encode_mimeheader( $string, $charset = null, $transfer_encoding = null, $newline = "\r\n", $indent = 0 ) { return p\Mbstring::mb_encode_mimeheader( $string, $charset, $transfer_encoding, $newline, $indent ); } |
|
26 | 26 | } |
27 | -if (!function_exists('mb_decode_numericentity')) { |
|
28 | - function mb_decode_numericentity($string, $map, $encoding = null) { return p\Mbstring::mb_decode_numericentity($string, $map, $encoding); } |
|
27 | +if ( ! function_exists( 'mb_decode_numericentity' ) ) { |
|
28 | + function mb_decode_numericentity( $string, $map, $encoding = null ) { return p\Mbstring::mb_decode_numericentity( $string, $map, $encoding ); } |
|
29 | 29 | } |
30 | -if (!function_exists('mb_encode_numericentity')) { |
|
31 | - function mb_encode_numericentity($string, $map, $encoding = null, $hex = false) { return p\Mbstring::mb_encode_numericentity($string, $map, $encoding, $hex); } |
|
30 | +if ( ! function_exists( 'mb_encode_numericentity' ) ) { |
|
31 | + function mb_encode_numericentity( $string, $map, $encoding = null, $hex = false ) { return p\Mbstring::mb_encode_numericentity( $string, $map, $encoding, $hex ); } |
|
32 | 32 | } |
33 | -if (!function_exists('mb_convert_case')) { |
|
34 | - function mb_convert_case($string, $mode, $encoding = null) { return p\Mbstring::mb_convert_case($string, $mode, $encoding); } |
|
33 | +if ( ! function_exists( 'mb_convert_case' ) ) { |
|
34 | + function mb_convert_case( $string, $mode, $encoding = null ) { return p\Mbstring::mb_convert_case( $string, $mode, $encoding ); } |
|
35 | 35 | } |
36 | -if (!function_exists('mb_internal_encoding')) { |
|
37 | - function mb_internal_encoding($encoding = null) { return p\Mbstring::mb_internal_encoding($encoding); } |
|
36 | +if ( ! function_exists( 'mb_internal_encoding' ) ) { |
|
37 | + function mb_internal_encoding( $encoding = null ) { return p\Mbstring::mb_internal_encoding( $encoding ); } |
|
38 | 38 | } |
39 | -if (!function_exists('mb_language')) { |
|
40 | - function mb_language($language = null) { return p\Mbstring::mb_language($language); } |
|
39 | +if ( ! function_exists( 'mb_language' ) ) { |
|
40 | + function mb_language( $language = null ) { return p\Mbstring::mb_language( $language ); } |
|
41 | 41 | } |
42 | -if (!function_exists('mb_list_encodings')) { |
|
42 | +if ( ! function_exists( 'mb_list_encodings' ) ) { |
|
43 | 43 | function mb_list_encodings() { return p\Mbstring::mb_list_encodings(); } |
44 | 44 | } |
45 | -if (!function_exists('mb_encoding_aliases')) { |
|
46 | - function mb_encoding_aliases($encoding) { return p\Mbstring::mb_encoding_aliases($encoding); } |
|
45 | +if ( ! function_exists( 'mb_encoding_aliases' ) ) { |
|
46 | + function mb_encoding_aliases( $encoding ) { return p\Mbstring::mb_encoding_aliases( $encoding ); } |
|
47 | 47 | } |
48 | -if (!function_exists('mb_check_encoding')) { |
|
49 | - function mb_check_encoding($value = null, $encoding = null) { return p\Mbstring::mb_check_encoding($value, $encoding); } |
|
48 | +if ( ! function_exists( 'mb_check_encoding' ) ) { |
|
49 | + function mb_check_encoding( $value = null, $encoding = null ) { return p\Mbstring::mb_check_encoding( $value, $encoding ); } |
|
50 | 50 | } |
51 | -if (!function_exists('mb_detect_encoding')) { |
|
52 | - function mb_detect_encoding($string, $encodings = null, $strict = false) { return p\Mbstring::mb_detect_encoding($string, $encodings, $strict); } |
|
51 | +if ( ! function_exists( 'mb_detect_encoding' ) ) { |
|
52 | + function mb_detect_encoding( $string, $encodings = null, $strict = false ) { return p\Mbstring::mb_detect_encoding( $string, $encodings, $strict ); } |
|
53 | 53 | } |
54 | -if (!function_exists('mb_detect_order')) { |
|
55 | - function mb_detect_order($encoding = null) { return p\Mbstring::mb_detect_order($encoding); } |
|
54 | +if ( ! function_exists( 'mb_detect_order' ) ) { |
|
55 | + function mb_detect_order( $encoding = null ) { return p\Mbstring::mb_detect_order( $encoding ); } |
|
56 | 56 | } |
57 | -if (!function_exists('mb_parse_str')) { |
|
58 | - function mb_parse_str($string, &$result = []) { parse_str($string, $result); return (bool) $result; } |
|
57 | +if ( ! function_exists( 'mb_parse_str' ) ) { |
|
58 | + function mb_parse_str( $string, &$result = [ ] ) { parse_str( $string, $result ); return (bool)$result; } |
|
59 | 59 | } |
60 | -if (!function_exists('mb_strlen')) { |
|
61 | - function mb_strlen($string, $encoding = null) { return p\Mbstring::mb_strlen($string, $encoding); } |
|
60 | +if ( ! function_exists( 'mb_strlen' ) ) { |
|
61 | + function mb_strlen( $string, $encoding = null ) { return p\Mbstring::mb_strlen( $string, $encoding ); } |
|
62 | 62 | } |
63 | -if (!function_exists('mb_strpos')) { |
|
64 | - function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strpos($haystack, $needle, $offset, $encoding); } |
|
63 | +if ( ! function_exists( 'mb_strpos' ) ) { |
|
64 | + function mb_strpos( $haystack, $needle, $offset = 0, $encoding = null ) { return p\Mbstring::mb_strpos( $haystack, $needle, $offset, $encoding ); } |
|
65 | 65 | } |
66 | -if (!function_exists('mb_strtolower')) { |
|
67 | - function mb_strtolower($string, $encoding = null) { return p\Mbstring::mb_strtolower($string, $encoding); } |
|
66 | +if ( ! function_exists( 'mb_strtolower' ) ) { |
|
67 | + function mb_strtolower( $string, $encoding = null ) { return p\Mbstring::mb_strtolower( $string, $encoding ); } |
|
68 | 68 | } |
69 | -if (!function_exists('mb_strtoupper')) { |
|
70 | - function mb_strtoupper($string, $encoding = null) { return p\Mbstring::mb_strtoupper($string, $encoding); } |
|
69 | +if ( ! function_exists( 'mb_strtoupper' ) ) { |
|
70 | + function mb_strtoupper( $string, $encoding = null ) { return p\Mbstring::mb_strtoupper( $string, $encoding ); } |
|
71 | 71 | } |
72 | -if (!function_exists('mb_substitute_character')) { |
|
73 | - function mb_substitute_character($substitute_character = null) { return p\Mbstring::mb_substitute_character($substitute_character); } |
|
72 | +if ( ! function_exists( 'mb_substitute_character' ) ) { |
|
73 | + function mb_substitute_character( $substitute_character = null ) { return p\Mbstring::mb_substitute_character( $substitute_character ); } |
|
74 | 74 | } |
75 | -if (!function_exists('mb_substr')) { |
|
76 | - function mb_substr($string, $start, $length = 2147483647, $encoding = null) { return p\Mbstring::mb_substr($string, $start, $length, $encoding); } |
|
75 | +if ( ! function_exists( 'mb_substr' ) ) { |
|
76 | + function mb_substr( $string, $start, $length = 2147483647, $encoding = null ) { return p\Mbstring::mb_substr( $string, $start, $length, $encoding ); } |
|
77 | 77 | } |
78 | -if (!function_exists('mb_stripos')) { |
|
79 | - function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_stripos($haystack, $needle, $offset, $encoding); } |
|
78 | +if ( ! function_exists( 'mb_stripos' ) ) { |
|
79 | + function mb_stripos( $haystack, $needle, $offset = 0, $encoding = null ) { return p\Mbstring::mb_stripos( $haystack, $needle, $offset, $encoding ); } |
|
80 | 80 | } |
81 | -if (!function_exists('mb_stristr')) { |
|
82 | - function mb_stristr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_stristr($haystack, $needle, $before_needle, $encoding); } |
|
81 | +if ( ! function_exists( 'mb_stristr' ) ) { |
|
82 | + function mb_stristr( $haystack, $needle, $before_needle = false, $encoding = null ) { return p\Mbstring::mb_stristr( $haystack, $needle, $before_needle, $encoding ); } |
|
83 | 83 | } |
84 | -if (!function_exists('mb_strrchr')) { |
|
85 | - function mb_strrchr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strrchr($haystack, $needle, $before_needle, $encoding); } |
|
84 | +if ( ! function_exists( 'mb_strrchr' ) ) { |
|
85 | + function mb_strrchr( $haystack, $needle, $before_needle = false, $encoding = null ) { return p\Mbstring::mb_strrchr( $haystack, $needle, $before_needle, $encoding ); } |
|
86 | 86 | } |
87 | -if (!function_exists('mb_strrichr')) { |
|
88 | - function mb_strrichr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strrichr($haystack, $needle, $before_needle, $encoding); } |
|
87 | +if ( ! function_exists( 'mb_strrichr' ) ) { |
|
88 | + function mb_strrichr( $haystack, $needle, $before_needle = false, $encoding = null ) { return p\Mbstring::mb_strrichr( $haystack, $needle, $before_needle, $encoding ); } |
|
89 | 89 | } |
90 | -if (!function_exists('mb_strripos')) { |
|
91 | - function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strripos($haystack, $needle, $offset, $encoding); } |
|
90 | +if ( ! function_exists( 'mb_strripos' ) ) { |
|
91 | + function mb_strripos( $haystack, $needle, $offset = 0, $encoding = null ) { return p\Mbstring::mb_strripos( $haystack, $needle, $offset, $encoding ); } |
|
92 | 92 | } |
93 | -if (!function_exists('mb_strrpos')) { |
|
94 | - function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strrpos($haystack, $needle, $offset, $encoding); } |
|
93 | +if ( ! function_exists( 'mb_strrpos' ) ) { |
|
94 | + function mb_strrpos( $haystack, $needle, $offset = 0, $encoding = null ) { return p\Mbstring::mb_strrpos( $haystack, $needle, $offset, $encoding ); } |
|
95 | 95 | } |
96 | -if (!function_exists('mb_strstr')) { |
|
97 | - function mb_strstr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strstr($haystack, $needle, $before_needle, $encoding); } |
|
96 | +if ( ! function_exists( 'mb_strstr' ) ) { |
|
97 | + function mb_strstr( $haystack, $needle, $before_needle = false, $encoding = null ) { return p\Mbstring::mb_strstr( $haystack, $needle, $before_needle, $encoding ); } |
|
98 | 98 | } |
99 | -if (!function_exists('mb_get_info')) { |
|
100 | - function mb_get_info($type = 'all') { return p\Mbstring::mb_get_info($type); } |
|
99 | +if ( ! function_exists( 'mb_get_info' ) ) { |
|
100 | + function mb_get_info( $type = 'all' ) { return p\Mbstring::mb_get_info( $type ); } |
|
101 | 101 | } |
102 | -if (!function_exists('mb_http_output')) { |
|
103 | - function mb_http_output($encoding = null) { return p\Mbstring::mb_http_output($encoding); } |
|
102 | +if ( ! function_exists( 'mb_http_output' ) ) { |
|
103 | + function mb_http_output( $encoding = null ) { return p\Mbstring::mb_http_output( $encoding ); } |
|
104 | 104 | } |
105 | -if (!function_exists('mb_strwidth')) { |
|
106 | - function mb_strwidth($string, $encoding = null) { return p\Mbstring::mb_strwidth($string, $encoding); } |
|
105 | +if ( ! function_exists( 'mb_strwidth' ) ) { |
|
106 | + function mb_strwidth( $string, $encoding = null ) { return p\Mbstring::mb_strwidth( $string, $encoding ); } |
|
107 | 107 | } |
108 | -if (!function_exists('mb_substr_count')) { |
|
109 | - function mb_substr_count($haystack, $needle, $encoding = null) { return p\Mbstring::mb_substr_count($haystack, $needle, $encoding); } |
|
108 | +if ( ! function_exists( 'mb_substr_count' ) ) { |
|
109 | + function mb_substr_count( $haystack, $needle, $encoding = null ) { return p\Mbstring::mb_substr_count( $haystack, $needle, $encoding ); } |
|
110 | 110 | } |
111 | -if (!function_exists('mb_output_handler')) { |
|
112 | - function mb_output_handler($string, $status) { return p\Mbstring::mb_output_handler($string, $status); } |
|
111 | +if ( ! function_exists( 'mb_output_handler' ) ) { |
|
112 | + function mb_output_handler( $string, $status ) { return p\Mbstring::mb_output_handler( $string, $status ); } |
|
113 | 113 | } |
114 | -if (!function_exists('mb_http_input')) { |
|
115 | - function mb_http_input($type = null) { return p\Mbstring::mb_http_input($type); } |
|
114 | +if ( ! function_exists( 'mb_http_input' ) ) { |
|
115 | + function mb_http_input( $type = null ) { return p\Mbstring::mb_http_input( $type ); } |
|
116 | 116 | } |
117 | 117 | |
118 | -if (!function_exists('mb_convert_variables')) { |
|
119 | - function mb_convert_variables($to_encoding, $from_encoding, &...$vars) { return p\Mbstring::mb_convert_variables($to_encoding, $from_encoding, ...$vars); } |
|
118 | +if ( ! function_exists( 'mb_convert_variables' ) ) { |
|
119 | + function mb_convert_variables( $to_encoding, $from_encoding, &...$vars ) { return p\Mbstring::mb_convert_variables( $to_encoding, $from_encoding, ...$vars ); } |
|
120 | 120 | } |
121 | 121 | |
122 | -if (!function_exists('mb_ord')) { |
|
123 | - function mb_ord($string, $encoding = null) { return p\Mbstring::mb_ord($string, $encoding); } |
|
122 | +if ( ! function_exists( 'mb_ord' ) ) { |
|
123 | + function mb_ord( $string, $encoding = null ) { return p\Mbstring::mb_ord( $string, $encoding ); } |
|
124 | 124 | } |
125 | -if (!function_exists('mb_chr')) { |
|
126 | - function mb_chr($codepoint, $encoding = null) { return p\Mbstring::mb_chr($codepoint, $encoding); } |
|
125 | +if ( ! function_exists( 'mb_chr' ) ) { |
|
126 | + function mb_chr( $codepoint, $encoding = null ) { return p\Mbstring::mb_chr( $codepoint, $encoding ); } |
|
127 | 127 | } |
128 | -if (!function_exists('mb_scrub')) { |
|
129 | - function mb_scrub($string, $encoding = null) { $encoding = null === $encoding ? mb_internal_encoding() : $encoding; return mb_convert_encoding($string, $encoding, $encoding); } |
|
128 | +if ( ! function_exists( 'mb_scrub' ) ) { |
|
129 | + function mb_scrub( $string, $encoding = null ) { $encoding = null === $encoding ? mb_internal_encoding() : $encoding; return mb_convert_encoding( $string, $encoding, $encoding ); } |
|
130 | 130 | } |
131 | -if (!function_exists('mb_str_split')) { |
|
132 | - function mb_str_split($string, $length = 1, $encoding = null) { return p\Mbstring::mb_str_split($string, $length, $encoding); } |
|
131 | +if ( ! function_exists( 'mb_str_split' ) ) { |
|
132 | + function mb_str_split( $string, $length = 1, $encoding = null ) { return p\Mbstring::mb_str_split( $string, $length, $encoding ); } |
|
133 | 133 | } |
134 | 134 | |
135 | -if (extension_loaded('mbstring')) { |
|
135 | +if ( extension_loaded( 'mbstring' ) ) { |
|
136 | 136 | return; |
137 | 137 | } |
138 | 138 | |
139 | -if (!defined('MB_CASE_UPPER')) { |
|
140 | - define('MB_CASE_UPPER', 0); |
|
139 | +if ( ! defined( 'MB_CASE_UPPER' ) ) { |
|
140 | + define( 'MB_CASE_UPPER', 0 ); |
|
141 | 141 | } |
142 | -if (!defined('MB_CASE_LOWER')) { |
|
143 | - define('MB_CASE_LOWER', 1); |
|
142 | +if ( ! defined( 'MB_CASE_LOWER' ) ) { |
|
143 | + define( 'MB_CASE_LOWER', 1 ); |
|
144 | 144 | } |
145 | -if (!defined('MB_CASE_TITLE')) { |
|
146 | - define('MB_CASE_TITLE', 2); |
|
145 | +if ( ! defined( 'MB_CASE_TITLE' ) ) { |
|
146 | + define( 'MB_CASE_TITLE', 2 ); |
|
147 | 147 | } |