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
|
|
|
* {@inheritDoc} |
45
|
|
|
*/ |
46
|
17 |
|
public function __construct(ConfigurationInterface $configuration) |
47
|
|
|
{ |
48
|
17 |
|
$this->initialize($configuration); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Inicializa el núcleo. |
53
|
|
|
* |
54
|
|
|
* @param ConfigurationInterface $configuration |
55
|
|
|
* @return void |
56
|
|
|
*/ |
57
|
17 |
|
private function initialize(ConfigurationInterface $configuration): void |
58
|
|
|
{ |
59
|
|
|
// Crear el contenedor de dependencias. |
60
|
17 |
|
$this->container = new ContainerBuilder(); |
61
|
|
|
|
62
|
|
|
// Registrar configuración como servicio. |
63
|
17 |
|
$this->container |
64
|
17 |
|
->register(ConfigurationInterface::class) |
65
|
17 |
|
->setSynthetic(true) |
66
|
17 |
|
; |
67
|
17 |
|
$this->container->set(ConfigurationInterface::class, $configuration); |
68
|
|
|
|
69
|
|
|
// Cargar parámetros al contenedor. |
70
|
17 |
|
foreach ($configuration->getParameters() as $name => $value) { |
|
|
|
|
71
|
17 |
|
$this->container->setParameter($name, $value); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
// Registrar servicios. |
75
|
17 |
|
$serviceRegistryClass = $configuration->getServiceRegistryClass(); |
76
|
17 |
|
$serviceRegistry = new $serviceRegistryClass(); |
77
|
17 |
|
$serviceRegistry->register($this->container); |
78
|
|
|
|
79
|
|
|
// Procesar servicios con un Compiler Pass si está definido. |
80
|
17 |
|
$compilerPassClass = $configuration->getCompilerPassClass(); |
81
|
17 |
|
if ($compilerPassClass !== null) { |
82
|
17 |
|
$servicesPrefix = $configuration->getServicesPrefix(); |
83
|
17 |
|
$this->container->addCompilerPass( |
84
|
17 |
|
new $compilerPassClass($servicesPrefix) |
85
|
17 |
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
// Agregar el compiler pass para inyectar las configuraciones. |
89
|
17 |
|
$compilerPassClass = ServiceConfigurationCompilerPass::class; |
90
|
17 |
|
$this->container->addCompilerPass(new $compilerPassClass()); |
91
|
|
|
|
92
|
|
|
// Compilar el contenedor de servicios. |
93
|
17 |
|
$this->container->compile(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* {@inheritDoc} |
98
|
|
|
*/ |
99
|
16 |
|
public function getContainer(): ContainerBuilder |
100
|
|
|
{ |
101
|
16 |
|
return $this->container; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* {@inheritDoc} |
106
|
|
|
*/ |
107
|
9 |
|
public function getConfiguration(): ConfigurationInterface |
108
|
|
|
{ |
109
|
9 |
|
return $this->container->get(ConfigurationInterface::class); |
|
|
|
|
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
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.