Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/dependency-injection/Loader/FileLoader.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children | af1871eacc83 |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
9 * file that was distributed with this source code. | 9 * file that was distributed with this source code. |
10 */ | 10 */ |
11 | 11 |
12 namespace Symfony\Component\DependencyInjection\Loader; | 12 namespace Symfony\Component\DependencyInjection\Loader; |
13 | 13 |
14 use Symfony\Component\Config\FileLocatorInterface; | |
15 use Symfony\Component\Config\Loader\FileLoader as BaseFileLoader; | |
16 use Symfony\Component\Config\Resource\GlobResource; | |
14 use Symfony\Component\DependencyInjection\ChildDefinition; | 17 use Symfony\Component\DependencyInjection\ChildDefinition; |
15 use Symfony\Component\DependencyInjection\ContainerBuilder; | 18 use Symfony\Component\DependencyInjection\ContainerBuilder; |
16 use Symfony\Component\DependencyInjection\Definition; | 19 use Symfony\Component\DependencyInjection\Definition; |
17 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; | 20 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; |
18 use Symfony\Component\Config\Loader\FileLoader as BaseFileLoader; | |
19 use Symfony\Component\Config\FileLocatorInterface; | |
20 use Symfony\Component\Config\Resource\GlobResource; | |
21 | 21 |
22 /** | 22 /** |
23 * FileLoader is the abstract class used by all built-in loaders that are file based. | 23 * FileLoader is the abstract class used by all built-in loaders that are file based. |
24 * | 24 * |
25 * @author Fabien Potencier <fabien@symfony.com> | 25 * @author Fabien Potencier <fabien@symfony.com> |
26 */ | 26 */ |
27 abstract class FileLoader extends BaseFileLoader | 27 abstract class FileLoader extends BaseFileLoader |
28 { | 28 { |
29 protected $container; | 29 protected $container; |
30 protected $isLoadingInstanceof = false; | 30 protected $isLoadingInstanceof = false; |
31 protected $instanceof = array(); | 31 protected $instanceof = []; |
32 | 32 |
33 public function __construct(ContainerBuilder $container, FileLocatorInterface $locator) | 33 public function __construct(ContainerBuilder $container, FileLocatorInterface $locator) |
34 { | 34 { |
35 $this->container = $container; | 35 $this->container = $container; |
36 | 36 |
55 } | 55 } |
56 | 56 |
57 $classes = $this->findClasses($namespace, $resource, $exclude); | 57 $classes = $this->findClasses($namespace, $resource, $exclude); |
58 // prepare for deep cloning | 58 // prepare for deep cloning |
59 $serializedPrototype = serialize($prototype); | 59 $serializedPrototype = serialize($prototype); |
60 $interfaces = array(); | 60 $interfaces = []; |
61 $singlyImplemented = array(); | 61 $singlyImplemented = []; |
62 | 62 |
63 foreach ($classes as $class => $errorMessage) { | 63 foreach ($classes as $class => $errorMessage) { |
64 if (interface_exists($class, false)) { | 64 if (interface_exists($class, false)) { |
65 $interfaces[] = $class; | 65 $interfaces[] = $class; |
66 } else { | 66 } else { |
91 */ | 91 */ |
92 protected function setDefinition($id, Definition $definition) | 92 protected function setDefinition($id, Definition $definition) |
93 { | 93 { |
94 if ($this->isLoadingInstanceof) { | 94 if ($this->isLoadingInstanceof) { |
95 if (!$definition instanceof ChildDefinition) { | 95 if (!$definition instanceof ChildDefinition) { |
96 throw new InvalidArgumentException(sprintf('Invalid type definition "%s": ChildDefinition expected, "%s" given.', $id, get_class($definition))); | 96 throw new InvalidArgumentException(sprintf('Invalid type definition "%s": ChildDefinition expected, "%s" given.', $id, \get_class($definition))); |
97 } | 97 } |
98 $this->instanceof[$id] = $definition; | 98 $this->instanceof[$id] = $definition; |
99 } else { | 99 } else { |
100 $this->container->setDefinition($id, $definition instanceof ChildDefinition ? $definition : $definition->setInstanceofConditionals($this->instanceof)); | 100 $this->container->setDefinition($id, $definition instanceof ChildDefinition ? $definition : $definition->setInstanceofConditionals($this->instanceof)); |
101 } | 101 } |
103 | 103 |
104 private function findClasses($namespace, $pattern, $excludePattern) | 104 private function findClasses($namespace, $pattern, $excludePattern) |
105 { | 105 { |
106 $parameterBag = $this->container->getParameterBag(); | 106 $parameterBag = $this->container->getParameterBag(); |
107 | 107 |
108 $excludePaths = array(); | 108 $excludePaths = []; |
109 $excludePrefix = null; | 109 $excludePrefix = null; |
110 if ($excludePattern) { | 110 if ($excludePattern) { |
111 $excludePattern = $parameterBag->unescapeValue($parameterBag->resolveValue($excludePattern)); | 111 $excludePattern = $parameterBag->unescapeValue($parameterBag->resolveValue($excludePattern)); |
112 foreach ($this->glob($excludePattern, true, $resource) as $path => $info) { | 112 foreach ($this->glob($excludePattern, true, $resource) as $path => $info) { |
113 if (null === $excludePrefix) { | 113 if (null === $excludePrefix) { |
118 $excludePaths[str_replace('\\', '/', $path)] = true; | 118 $excludePaths[str_replace('\\', '/', $path)] = true; |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 $pattern = $parameterBag->unescapeValue($parameterBag->resolveValue($pattern)); | 122 $pattern = $parameterBag->unescapeValue($parameterBag->resolveValue($pattern)); |
123 $classes = array(); | 123 $classes = []; |
124 $extRegexp = defined('HHVM_VERSION') ? '/\\.(?:php|hh)$/' : '/\\.php$/'; | 124 $extRegexp = \defined('HHVM_VERSION') ? '/\\.(?:php|hh)$/' : '/\\.php$/'; |
125 $prefixLen = null; | 125 $prefixLen = null; |
126 foreach ($this->glob($pattern, true, $resource) as $path => $info) { | 126 foreach ($this->glob($pattern, true, $resource) as $path => $info) { |
127 if (null === $prefixLen) { | 127 if (null === $prefixLen) { |
128 $prefixLen = strlen($resource->getPrefix()); | 128 $prefixLen = \strlen($resource->getPrefix()); |
129 | 129 |
130 if ($excludePrefix && 0 !== strpos($excludePrefix, $resource->getPrefix())) { | 130 if ($excludePrefix && 0 !== strpos($excludePrefix, $resource->getPrefix())) { |
131 throw new InvalidArgumentException(sprintf('Invalid "exclude" pattern when importing classes for "%s": make sure your "exclude" pattern (%s) is a subset of the "resource" pattern (%s)', $namespace, $excludePattern, $pattern)); | 131 throw new InvalidArgumentException(sprintf('Invalid "exclude" pattern when importing classes for "%s": make sure your "exclude" pattern (%s) is a subset of the "resource" pattern (%s)', $namespace, $excludePattern, $pattern)); |
132 } | 132 } |
133 } | 133 } |
137 } | 137 } |
138 | 138 |
139 if (!preg_match($extRegexp, $path, $m) || !$info->isReadable()) { | 139 if (!preg_match($extRegexp, $path, $m) || !$info->isReadable()) { |
140 continue; | 140 continue; |
141 } | 141 } |
142 $class = $namespace.ltrim(str_replace('/', '\\', substr($path, $prefixLen, -strlen($m[0]))), '\\'); | 142 $class = $namespace.ltrim(str_replace('/', '\\', substr($path, $prefixLen, -\strlen($m[0]))), '\\'); |
143 | 143 |
144 if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)*+$/', $class)) { | 144 if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)*+$/', $class)) { |
145 continue; | 145 continue; |
146 } | 146 } |
147 | 147 |