comparison vendor/symfony/http-kernel/DependencyInjection/AddAnnotatedClassesToCachePass.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
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
11 11
12 namespace Symfony\Component\HttpKernel\DependencyInjection; 12 namespace Symfony\Component\HttpKernel\DependencyInjection;
13 13
14 use Composer\Autoload\ClassLoader; 14 use Composer\Autoload\ClassLoader;
15 use Symfony\Component\Debug\DebugClassLoader; 15 use Symfony\Component\Debug\DebugClassLoader;
16 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16 use Symfony\Component\DependencyInjection\ContainerBuilder; 17 use Symfony\Component\DependencyInjection\ContainerBuilder;
17 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18 use Symfony\Component\HttpKernel\Kernel; 18 use Symfony\Component\HttpKernel\Kernel;
19 19
20 /** 20 /**
21 * Sets the classes to compile in the cache for the container. 21 * Sets the classes to compile in the cache for the container.
22 * 22 *
34 /** 34 /**
35 * {@inheritdoc} 35 * {@inheritdoc}
36 */ 36 */
37 public function process(ContainerBuilder $container) 37 public function process(ContainerBuilder $container)
38 { 38 {
39 $classes = array(); 39 $classes = [];
40 $annotatedClasses = array(); 40 $annotatedClasses = [];
41 foreach ($container->getExtensions() as $extension) { 41 foreach ($container->getExtensions() as $extension) {
42 if ($extension instanceof Extension) { 42 if ($extension instanceof Extension) {
43 if (\PHP_VERSION_ID < 70000) { 43 if (\PHP_VERSION_ID < 70000) {
44 $classes = array_merge($classes, $extension->getClassesToCompile()); 44 $classes = array_merge($classes, $extension->getClassesToCompile());
45 } 45 }
61 * Expands the given class patterns using a list of existing classes. 61 * Expands the given class patterns using a list of existing classes.
62 * 62 *
63 * @param array $patterns The class patterns to expand 63 * @param array $patterns The class patterns to expand
64 * @param array $classes The existing classes to match against the patterns 64 * @param array $classes The existing classes to match against the patterns
65 * 65 *
66 * @return array A list of classes derivated from the patterns 66 * @return array A list of classes derived from the patterns
67 */ 67 */
68 private function expandClasses(array $patterns, array $classes) 68 private function expandClasses(array $patterns, array $classes)
69 { 69 {
70 $expanded = array(); 70 $expanded = [];
71 71
72 // Explicit classes declared in the patterns are returned directly 72 // Explicit classes declared in the patterns are returned directly
73 foreach ($patterns as $key => $pattern) { 73 foreach ($patterns as $key => $pattern) {
74 if ('\\' !== substr($pattern, -1) && false === strpos($pattern, '*')) { 74 if ('\\' !== substr($pattern, -1) && false === strpos($pattern, '*')) {
75 unset($patterns[$key]); 75 unset($patterns[$key]);
91 return array_unique($expanded); 91 return array_unique($expanded);
92 } 92 }
93 93
94 private function getClassesInComposerClassMaps() 94 private function getClassesInComposerClassMaps()
95 { 95 {
96 $classes = array(); 96 $classes = [];
97 97
98 foreach (spl_autoload_functions() as $function) { 98 foreach (spl_autoload_functions() as $function) {
99 if (!is_array($function)) { 99 if (!\is_array($function)) {
100 continue; 100 continue;
101 } 101 }
102 102
103 if ($function[0] instanceof DebugClassLoader) { 103 if ($function[0] instanceof DebugClassLoader) {
104 $function = $function[0]->getClassLoader(); 104 $function = $function[0]->getClassLoader();
105 } 105 }
106 106
107 if (is_array($function) && $function[0] instanceof ClassLoader) { 107 if (\is_array($function) && $function[0] instanceof ClassLoader) {
108 $classes += array_filter($function[0]->getClassMap()); 108 $classes += array_filter($function[0]->getClassMap());
109 } 109 }
110 } 110 }
111 111
112 return array_keys($classes); 112 return array_keys($classes);
113 } 113 }
114 114
115 private function patternsToRegexps($patterns) 115 private function patternsToRegexps($patterns)
116 { 116 {
117 $regexps = array(); 117 $regexps = [];
118 118
119 foreach ($patterns as $pattern) { 119 foreach ($patterns as $pattern) {
120 // Escape user input 120 // Escape user input
121 $regex = preg_quote(ltrim($pattern, '\\')); 121 $regex = preg_quote(ltrim($pattern, '\\'));
122 122
123 // Wildcards * and ** 123 // Wildcards * and **
124 $regex = strtr($regex, array('\\*\\*' => '.*?', '\\*' => '[^\\\\]*?')); 124 $regex = strtr($regex, ['\\*\\*' => '.*?', '\\*' => '[^\\\\]*?']);
125 125
126 // If this class does not end by a slash, anchor the end 126 // If this class does not end by a slash, anchor the end
127 if ('\\' !== substr($regex, -1)) { 127 if ('\\' !== substr($regex, -1)) {
128 $regex .= '$'; 128 $regex .= '$';
129 } 129 }