1 | <?php |
||
29 | class TranslationExtension extends Extension |
||
30 | { |
||
31 | /** |
||
32 | * {@inheritdoc} |
||
33 | */ |
||
34 | 1 | public function load(array $configs, ContainerBuilder $container) |
|
78 | |||
79 | /** |
||
80 | * Handle the config node to prepare the config manager. |
||
81 | * |
||
82 | * @param ContainerBuilder $container |
||
83 | * @param array $config |
||
84 | */ |
||
85 | 1 | private function handleConfigNode(ContainerBuilder $container, array $config) |
|
86 | { |
||
87 | 1 | $configurationManager = $container->getDefinition('php_translation.configuration_manager'); |
|
88 | // $first will be the "default" configuration. |
||
89 | 1 | $first = null; |
|
90 | 1 | foreach ($config['configs'] as $name => &$c) { |
|
91 | if ($first === null || $name === 'default') { |
||
92 | $first = $name; |
||
93 | } |
||
94 | if (empty($c['project_root'])) { |
||
95 | // Add a project root of none is set. |
||
96 | $c['project_root'] = dirname($container->getParameter('kernel.root_dir')); |
||
97 | } |
||
98 | $c['name'] = $name; |
||
99 | $c['locales'] = $config['locales']; |
||
100 | $configurationServiceId = 'php_translation.configuration.'.$name; |
||
101 | $configDef = $container->register($configurationServiceId, ConfigurationModel::class); |
||
102 | $configDef->setPublic(false)->addArgument($c); |
||
103 | $configurationManager->addMethodCall('addConfiguration', [new Reference($configurationServiceId)]); |
||
104 | |||
105 | /* |
||
106 | * Configure storage service |
||
107 | */ |
||
108 | $storageDefinition = new DefinitionDecorator('php_translation.storage.abstract'); |
||
109 | $storageDefinition->replaceArgument(2, new Reference($configurationServiceId)); |
||
110 | $container->setDefinition('php_translation.storage.'.$name, $storageDefinition); |
||
111 | |||
112 | // Add storages |
||
113 | if (!empty($c['remote_storage'])) { |
||
114 | foreach ($c['remote_storage'] as $serviceId) { |
||
115 | $storageDefinition->addMethodCall('addRemoteStorage', [new Reference($serviceId)]); |
||
116 | } |
||
117 | } |
||
118 | if (!empty($c['local_storage'])) { |
||
119 | foreach ($c['local_storage'] as $serviceId) { |
||
120 | $storageDefinition->addMethodCall('addLocalStorage', [new Reference($serviceId)]); |
||
121 | } |
||
122 | } else { |
||
123 | // If there is no local storage configured, register a file storage |
||
124 | $def = new DefinitionDecorator('php_translation.single_storage.file.abstract'); |
||
125 | $def->replaceArgument(2, $c['output_dir']) |
||
126 | ->addTag('php_translation.storage', ['type' => 'local', 'name' => $name]); |
||
127 | $container->setDefinition('php_translation.single_storage.file.'.$name, $def); |
||
128 | } |
||
129 | 1 | } |
|
130 | |||
131 | 1 | if ($first !== null) { |
|
132 | // Create some aliases for the default storage |
||
133 | $container->setAlias('php_translation.storage', 'php_translation.sstorage.'.$first); |
||
134 | $container->setAlias('php_translation.storage.default', 'php_translation.storage.'.$first); |
||
135 | } |
||
136 | 1 | } |
|
137 | |||
138 | /** |
||
139 | * Handle config for WebUI. |
||
140 | * |
||
141 | * @param ContainerBuilder $container |
||
142 | * @param array $config |
||
143 | */ |
||
144 | private function enableWebUi(ContainerBuilder $container, array $config) |
||
150 | |||
151 | /** |
||
152 | * Handle config for EditInPlace. |
||
153 | * |
||
154 | * @param ContainerBuilder $container |
||
155 | * @param array $config |
||
156 | */ |
||
157 | private function enableEditInPlace(ContainerBuilder $container, array $config) |
||
174 | |||
175 | /** |
||
176 | * Handle config for Symfony Profiler. |
||
177 | * |
||
178 | * @param ContainerBuilder $container |
||
179 | * @param array $config |
||
180 | */ |
||
181 | private function enableSymfonyProfiler(ContainerBuilder $container, array $config) |
||
185 | |||
186 | /** |
||
187 | * Handle config for fallback auto translate. |
||
188 | * |
||
189 | * @param ContainerBuilder $container |
||
190 | * @param array $config |
||
191 | */ |
||
192 | private function enableFallbackAutoTranslator(ContainerBuilder $container, array $config) |
||
202 | |||
203 | /** |
||
204 | * {@inheritdoc} |
||
205 | */ |
||
206 | public function getAlias() |
||
210 | } |
||
211 |
PHP has two types of connecting operators (logical operators, and boolean operators):
and
&&
or
||
The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&
, or||
.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
die
introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.