Vous êtes connecté en tant que anonymous Se Deconnecter
Browse code

Application modulaire fonctionnelle !

Emmanuel ROY authored on 12/08/2019 15:10:25
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,144 +0,0 @@
1
-<?php
2
-
3
-/*
4
- * This file is part of the Symfony package.
5
- *
6
- * (c) Fabien Potencier <fabien@symfony.com>
7
- *
8
- * For the full copyright and license information, please view the LICENSE
9
- * file that was distributed with this source code.
10
- */
11
-
12
-namespace Symfony\Component\Translation\DependencyInjection;
13
-
14
-use Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass;
15
-use Symfony\Component\DependencyInjection\ContainerBuilder;
16
-use Symfony\Component\DependencyInjection\Definition;
17
-use Symfony\Component\DependencyInjection\Reference;
18
-use Symfony\Component\DependencyInjection\ServiceLocator;
19
-
20
-/**
21
- * @author Yonel Ceruto <yonelceruto@gmail.com>
22
- */
23
-class TranslatorPathsPass extends AbstractRecursivePass
24
-{
25
-    private $translatorServiceId;
26
-    private $debugCommandServiceId;
27
-    private $updateCommandServiceId;
28
-    private $resolverServiceId;
29
-    private $level = 0;
30
-    private $paths = [];
31
-    private $definitions = [];
32
-    private $controllers = [];
33
-
34
-    public function __construct(string $translatorServiceId = 'translator', string $debugCommandServiceId = 'console.command.translation_debug', string $updateCommandServiceId = 'console.command.translation_update', string $resolverServiceId = 'argument_resolver.service')
35
-    {
36
-        $this->translatorServiceId = $translatorServiceId;
37
-        $this->debugCommandServiceId = $debugCommandServiceId;
38
-        $this->updateCommandServiceId = $updateCommandServiceId;
39
-        $this->resolverServiceId = $resolverServiceId;
40
-    }
41
-
42
-    public function process(ContainerBuilder $container)
43
-    {
44
-        if (!$container->hasDefinition($this->translatorServiceId)) {
45
-            return;
46
-        }
47
-
48
-        foreach ($this->findControllerArguments($container) as $controller => $argument) {
49
-            $id = substr($controller, 0, strpos($controller, ':') ?: \strlen($controller));
50
-            if ($container->hasDefinition($id)) {
51
-                list($locatorRef) = $argument->getValues();
52
-                $this->controllers[(string) $locatorRef][$container->getDefinition($id)->getClass()] = true;
53
-            }
54
-        }
55
-
56
-        try {
57
-            parent::process($container);
58
-
59
-            $paths = [];
60
-            foreach ($this->paths as $class => $_) {
61
-                if (($r = $container->getReflectionClass($class)) && !$r->isInterface()) {
62
-                    $paths[] = $r->getFileName();
63
-                }
64
-            }
65
-            if ($paths) {
66
-                if ($container->hasDefinition($this->debugCommandServiceId)) {
67
-                    $definition = $container->getDefinition($this->debugCommandServiceId);
68
-                    $definition->replaceArgument(6, array_merge($definition->getArgument(6), $paths));
69
-                }
70
-                if ($container->hasDefinition($this->updateCommandServiceId)) {
71
-                    $definition = $container->getDefinition($this->updateCommandServiceId);
72
-                    $definition->replaceArgument(7, array_merge($definition->getArgument(7), $paths));
73
-                }
74
-            }
75
-        } finally {
76
-            $this->level = 0;
77
-            $this->paths = [];
78
-            $this->definitions = [];
79
-        }
80
-    }
81
-
82
-    protected function processValue($value, $isRoot = false)
83
-    {
84
-        if ($value instanceof Reference) {
85
-            if ((string) $value === $this->translatorServiceId) {
86
-                for ($i = $this->level - 1; $i >= 0; --$i) {
87
-                    $class = $this->definitions[$i]->getClass();
88
-
89
-                    if (ServiceLocator::class === $class) {
90
-                        if (!isset($this->controllers[$this->currentId])) {
91
-                            continue;
92
-                        }
93
-                        foreach ($this->controllers[$this->currentId] as $class => $_) {
94
-                            $this->paths[$class] = true;
95
-                        }
96
-                    } else {
97
-                        $this->paths[$class] = true;
98
-                    }
99
-
100
-                    break;
101
-                }
102
-            }
103
-
104
-            return $value;
105
-        }
106
-
107
-        if ($value instanceof Definition) {
108
-            $this->definitions[$this->level++] = $value;
109
-            $value = parent::processValue($value, $isRoot);
110
-            unset($this->definitions[--$this->level]);
111
-
112
-            return $value;
113
-        }
114
-
115
-        return parent::processValue($value, $isRoot);
116
-    }
117
-
118
-    private function findControllerArguments(ContainerBuilder $container): array
119
-    {
120
-        if ($container->hasDefinition($this->resolverServiceId)) {
121
-            $argument = $container->getDefinition($this->resolverServiceId)->getArgument(0);
122
-            if ($argument instanceof Reference) {
123
-                $argument = $container->getDefinition($argument);
124
-            }
125
-
126
-            return $argument->getArgument(0);
127
-        }
128
-
129
-        if ($container->hasDefinition('debug.'.$this->resolverServiceId)) {
130
-            $argument = $container->getDefinition('debug.'.$this->resolverServiceId)->getArgument(0);
131
-            if ($argument instanceof Reference) {
132
-                $argument = $container->getDefinition($argument);
133
-            }
134
-            $argument = $argument->getArgument(0);
135
-            if ($argument instanceof Reference) {
136
-                $argument = $container->getDefinition($argument);
137
-            }
138
-
139
-            return $argument->getArgument(0);
140
-        }
141
-
142
-        return [];
143
-    }
144
-}
Browse code

initial commit

Emmanuel ROY authored on 09/08/2019 08:39:02
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,144 @@
1
+<?php
2
+
3
+/*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+namespace Symfony\Component\Translation\DependencyInjection;
13
+
14
+use Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass;
15
+use Symfony\Component\DependencyInjection\ContainerBuilder;
16
+use Symfony\Component\DependencyInjection\Definition;
17
+use Symfony\Component\DependencyInjection\Reference;
18
+use Symfony\Component\DependencyInjection\ServiceLocator;
19
+
20
+/**
21
+ * @author Yonel Ceruto <yonelceruto@gmail.com>
22
+ */
23
+class TranslatorPathsPass extends AbstractRecursivePass
24
+{
25
+    private $translatorServiceId;
26
+    private $debugCommandServiceId;
27
+    private $updateCommandServiceId;
28
+    private $resolverServiceId;
29
+    private $level = 0;
30
+    private $paths = [];
31
+    private $definitions = [];
32
+    private $controllers = [];
33
+
34
+    public function __construct(string $translatorServiceId = 'translator', string $debugCommandServiceId = 'console.command.translation_debug', string $updateCommandServiceId = 'console.command.translation_update', string $resolverServiceId = 'argument_resolver.service')
35
+    {
36
+        $this->translatorServiceId = $translatorServiceId;
37
+        $this->debugCommandServiceId = $debugCommandServiceId;
38
+        $this->updateCommandServiceId = $updateCommandServiceId;
39
+        $this->resolverServiceId = $resolverServiceId;
40
+    }
41
+
42
+    public function process(ContainerBuilder $container)
43
+    {
44
+        if (!$container->hasDefinition($this->translatorServiceId)) {
45
+            return;
46
+        }
47
+
48
+        foreach ($this->findControllerArguments($container) as $controller => $argument) {
49
+            $id = substr($controller, 0, strpos($controller, ':') ?: \strlen($controller));
50
+            if ($container->hasDefinition($id)) {
51
+                list($locatorRef) = $argument->getValues();
52
+                $this->controllers[(string) $locatorRef][$container->getDefinition($id)->getClass()] = true;
53
+            }
54
+        }
55
+
56
+        try {
57
+            parent::process($container);
58
+
59
+            $paths = [];
60
+            foreach ($this->paths as $class => $_) {
61
+                if (($r = $container->getReflectionClass($class)) && !$r->isInterface()) {
62
+                    $paths[] = $r->getFileName();
63
+                }
64
+            }
65
+            if ($paths) {
66
+                if ($container->hasDefinition($this->debugCommandServiceId)) {
67
+                    $definition = $container->getDefinition($this->debugCommandServiceId);
68
+                    $definition->replaceArgument(6, array_merge($definition->getArgument(6), $paths));
69
+                }
70
+                if ($container->hasDefinition($this->updateCommandServiceId)) {
71
+                    $definition = $container->getDefinition($this->updateCommandServiceId);
72
+                    $definition->replaceArgument(7, array_merge($definition->getArgument(7), $paths));
73
+                }
74
+            }
75
+        } finally {
76
+            $this->level = 0;
77
+            $this->paths = [];
78
+            $this->definitions = [];
79
+        }
80
+    }
81
+
82
+    protected function processValue($value, $isRoot = false)
83
+    {
84
+        if ($value instanceof Reference) {
85
+            if ((string) $value === $this->translatorServiceId) {
86
+                for ($i = $this->level - 1; $i >= 0; --$i) {
87
+                    $class = $this->definitions[$i]->getClass();
88
+
89
+                    if (ServiceLocator::class === $class) {
90
+                        if (!isset($this->controllers[$this->currentId])) {
91
+                            continue;
92
+                        }
93
+                        foreach ($this->controllers[$this->currentId] as $class => $_) {
94
+                            $this->paths[$class] = true;
95
+                        }
96
+                    } else {
97
+                        $this->paths[$class] = true;
98
+                    }
99
+
100
+                    break;
101
+                }
102
+            }
103
+
104
+            return $value;
105
+        }
106
+
107
+        if ($value instanceof Definition) {
108
+            $this->definitions[$this->level++] = $value;
109
+            $value = parent::processValue($value, $isRoot);
110
+            unset($this->definitions[--$this->level]);
111
+
112
+            return $value;
113
+        }
114
+
115
+        return parent::processValue($value, $isRoot);
116
+    }
117
+
118
+    private function findControllerArguments(ContainerBuilder $container): array
119
+    {
120
+        if ($container->hasDefinition($this->resolverServiceId)) {
121
+            $argument = $container->getDefinition($this->resolverServiceId)->getArgument(0);
122
+            if ($argument instanceof Reference) {
123
+                $argument = $container->getDefinition($argument);
124
+            }
125
+
126
+            return $argument->getArgument(0);
127
+        }
128
+
129
+        if ($container->hasDefinition('debug.'.$this->resolverServiceId)) {
130
+            $argument = $container->getDefinition('debug.'.$this->resolverServiceId)->getArgument(0);
131
+            if ($argument instanceof Reference) {
132
+                $argument = $container->getDefinition($argument);
133
+            }
134
+            $argument = $argument->getArgument(0);
135
+            if ($argument instanceof Reference) {
136
+                $argument = $container->getDefinition($argument);
137
+            }
138
+
139
+            return $argument->getArgument(0);
140
+        }
141
+
142
+        return [];
143
+    }
144
+}