GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — 4.0 ( 164817...8a5179 )
by Olivier
04:13
created

ModuleContainerExtension::from()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the ICanBoogie package.
5
 *
6
 * (c) Olivier Laviale <[email protected]>
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 ICanBoogie\Module;
13
14
use ICanBoogie\ActiveRecord\Model;
15
use ICanBoogie\Application;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Definition;
18
use Symfony\Component\DependencyInjection\Extension\Extension;
19
use Symfony\Component\DependencyInjection\Reference;
20
21
/**
22
 * Define modules as services.
23
 */
24
class ModuleContainerExtension extends Extension
25
{
26
	/**
27
	 * Create a new instance.
28
	 *
29
	 * @param Application $app
30
	 *
31
	 * @return static
32
	 */
33
	static public function from(Application $app)
34
	{
35
		return new static($app);
36
	}
37
38
	/**
39
	 * @var Application
40
	 */
41
	private $app;
42
43
	/**
44
	 * @param Application $app
45
	 */
46
	public function __construct(Application $app)
47
	{
48
		$this->app = $app;
49
	}
50
51
	/**
52
	 * Loads a specific configuration.
53
	 *
54
	 * @param array $configs An array of configuration values
55
	 * @param ContainerBuilder $container A ContainerBuilder instance
56
	 *
57
	 * @throws \InvalidArgumentException When provided tag is not defined in this extension
58
	 */
59
	public function load(array $configs, ContainerBuilder $container)
60
	{
61
		foreach ($this->app->modules->descriptors as $module_id => $descriptor)
62
		{
63
			$class = $descriptor[Descriptor::CLASSNAME];
64
65
			$definition = (new Definition($class))
66
				->setFactory([ new Reference('modules'), 'offsetGet' ])
67
				->setArguments([ $module_id ]);
68
69
			$container->setDefinition("module.$module_id", $definition);
70
71
			$this->register_models($module_id, $descriptor[Descriptor::MODELS], $container);
72
		}
73
	}
74
75
	/**
76
	 * @param string $module_id
77
	 * @param array $models
78
	 * @param ContainerBuilder $container
79
	 */
80
	private function register_models($module_id, array $models, ContainerBuilder $container)
81
	{
82
		foreach ($models as $model_id => $definition)
83
		{
84
			if ($model_id === 'primary')
85
			{
86
				$model_id = $module_id;
87
			}
88
89
			$class = $definition[Model::CLASSNAME];
90
91
			$definition = (new Definition($class))
92
				->setFactory([ new Reference('models'), 'offsetGet' ])
93
				->setArguments([ $model_id ]);
94
95
			$container->setDefinition("model.$model_id", $definition);
96
		}
97
	}
98
}
99