|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ScayTrase\Api\Cruds\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Config\FileLocator; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
9
|
|
|
|
|
10
|
|
|
final class CrudsExtension extends Extension |
|
11
|
|
|
{ |
|
12
|
|
|
/** {@inheritdoc} */ |
|
13
|
2 |
|
public function load(array $configs, ContainerBuilder $container) |
|
14
|
|
|
{ |
|
15
|
2 |
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
16
|
2 |
|
$loader->load('cruds.yml'); |
|
17
|
|
|
|
|
18
|
2 |
|
$this->registerSymfonyFormsCompatibility($container); |
|
19
|
2 |
|
$this->registerJmsSerializerCompatibility($container); |
|
|
|
|
|
|
20
|
2 |
|
$this->registerSymfonySerializerCompatibility($container); |
|
21
|
|
|
|
|
22
|
2 |
|
$config = $this->processConfiguration($this->getConfiguration([], $container), $configs); |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
2 |
|
$configurator = new CrudsEntitiesConfigurator($container); |
|
25
|
2 |
|
$container->addObjectResource($configurator); |
|
26
|
2 |
|
$prefix = $config['prefix']; |
|
27
|
2 |
|
foreach ($config['entities'] as $name => $entityConfig) { |
|
28
|
2 |
|
$entityConfig['prefix'] = $entityConfig['prefix'] ?: '/'.$name; |
|
29
|
2 |
|
$entityConfig['prefix'] = $prefix.$entityConfig['prefix']; |
|
30
|
2 |
|
$configurator->processEntityConfiguration($name, $entityConfig); |
|
31
|
2 |
|
} |
|
32
|
2 |
|
} |
|
33
|
|
|
|
|
34
|
2 |
|
private function registerSymfonyFormsCompatibility(ContainerBuilder $container) |
|
35
|
|
|
{ |
|
36
|
2 |
|
if (!$container->has('form.registry')) { |
|
37
|
2 |
|
return; |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
2 |
|
private function registerJmsSerializerCompatibility(ContainerBuilder $container) |
|
|
|
|
|
|
42
|
|
|
{ |
|
43
|
2 |
|
} |
|
44
|
|
|
|
|
45
|
2 |
|
private function registerSymfonySerializerCompatibility(ContainerBuilder $container) |
|
46
|
|
|
{ |
|
47
|
2 |
|
if (!$container->has('serializer')) { |
|
48
|
2 |
|
return; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
private function registerDoctrineOrmCompatibility(ContainerBuilder $container) |
|
|
|
|
|
|
53
|
|
|
{ |
|
54
|
|
|
if (!$container->has('doctrine')) { |
|
55
|
|
|
return; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call: