|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Derafu: Biblioteca PHP (Núcleo). |
|
7
|
|
|
* Copyright (C) Derafu <https://www.derafu.org> |
|
8
|
|
|
* |
|
9
|
|
|
* Este programa es software libre: usted puede redistribuirlo y/o modificarlo |
|
10
|
|
|
* bajo los términos de la Licencia Pública General Affero de GNU publicada por |
|
11
|
|
|
* la Fundación para el Software Libre, ya sea la versión 3 de la Licencia, o |
|
12
|
|
|
* (a su elección) cualquier versión posterior de la misma. |
|
13
|
|
|
* |
|
14
|
|
|
* Este programa se distribuye con la esperanza de que sea útil, pero SIN |
|
15
|
|
|
* GARANTÍA ALGUNA; ni siquiera la garantía implícita MERCANTIL o de APTITUD |
|
16
|
|
|
* PARA UN PROPÓSITO DETERMINADO. Consulte los detalles de la Licencia Pública |
|
17
|
|
|
* General Affero de GNU para obtener una información más detallada. |
|
18
|
|
|
* |
|
19
|
|
|
* Debería haber recibido una copia de la Licencia Pública General Affero de GNU |
|
20
|
|
|
* junto a este programa. |
|
21
|
|
|
* |
|
22
|
|
|
* En caso contrario, consulte <http://www.gnu.org/licenses/agpl.html>. |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace Derafu\Lib\Core\Foundation; |
|
26
|
|
|
|
|
27
|
|
|
use Derafu\Lib\Core\Foundation\Contract\ConfigurationInterface; |
|
28
|
|
|
use Derafu\Lib\Core\Foundation\Contract\KernelInterface; |
|
29
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Núcleo de la aplicación. |
|
33
|
|
|
*/ |
|
34
|
|
|
class Kernel implements KernelInterface |
|
35
|
|
|
{ |
|
36
|
|
|
/** |
|
37
|
|
|
* Contenedor de servicios de la aplicación. |
|
38
|
|
|
* |
|
39
|
|
|
* @var ContainerBuilder |
|
40
|
|
|
*/ |
|
41
|
|
|
private ContainerBuilder $container; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Constructor del núcleo de la aplicación. |
|
45
|
|
|
*/ |
|
46
|
16 |
|
public function __construct() |
|
47
|
|
|
{ |
|
48
|
16 |
|
$this->container = new ContainerBuilder(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* {@inheritdoc} |
|
53
|
|
|
*/ |
|
54
|
16 |
|
public function initialize(ConfigurationInterface $configuration): void |
|
55
|
|
|
{ |
|
56
|
|
|
// Registrar configuración como servicio. |
|
57
|
16 |
|
$this->container |
|
58
|
16 |
|
->register(ConfigurationInterface::class) |
|
59
|
16 |
|
->setSynthetic(true) |
|
60
|
16 |
|
; |
|
61
|
16 |
|
$this->container->set(ConfigurationInterface::class, $configuration); |
|
62
|
|
|
|
|
63
|
|
|
// Cargar parámetros al contenedor. |
|
64
|
16 |
|
foreach ($configuration->getParameters() as $name => $value) { |
|
|
|
|
|
|
65
|
16 |
|
$this->container->setParameter($name, $value); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
// Registrar servicios. |
|
69
|
16 |
|
$serviceRegistryClass = $configuration->getServiceRegistryClass(); |
|
70
|
16 |
|
$serviceRegistry = new $serviceRegistryClass(); |
|
71
|
16 |
|
$serviceRegistry->register($this->container); |
|
72
|
|
|
|
|
73
|
|
|
// Procesar servicios con un Compiler Pass si está definido. |
|
74
|
16 |
|
$compilerPassClass = $configuration->getCompilerPassClass(); |
|
75
|
16 |
|
if ($compilerPassClass !== null) { |
|
76
|
16 |
|
$servicesPrefix = $configuration->getServicesPrefix(); |
|
77
|
16 |
|
$this->container->addCompilerPass( |
|
78
|
16 |
|
new $compilerPassClass($servicesPrefix) |
|
79
|
16 |
|
); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
// Agregar el compiler pass para inyectar las configuraciones. |
|
83
|
16 |
|
$compilerPassClass = ServiceConfigurationCompilerPass::class; |
|
84
|
16 |
|
$this->container->addCompilerPass(new $compilerPassClass()); |
|
85
|
|
|
|
|
86
|
|
|
// Compilar el contenedor de servicios. |
|
87
|
16 |
|
$this->container->compile(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* {@inheritdoc} |
|
92
|
|
|
*/ |
|
93
|
15 |
|
public function getContainer(): ContainerBuilder |
|
94
|
|
|
{ |
|
95
|
15 |
|
return $this->container; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* {@inheritdoc} |
|
100
|
|
|
*/ |
|
101
|
7 |
|
public function getConfiguration(): ConfigurationInterface |
|
102
|
|
|
{ |
|
103
|
7 |
|
return $this->container->get(ConfigurationInterface::class); |
|
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.