Skip to content

Commit 30874d4

Browse files
committed
Add AppKernel
1 parent ba630fc commit 30874d4

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

app/AppKernel.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
use PhpGitHooks\Infrastructure\CommandBus\CommandBus\CommandBusCompilerPass;
4+
use PhpGitHooks\Infrastructure\CommandBus\QueryBus\QueryBusCompilerPass;
5+
use Symfony\Component\Config\FileLocator;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
8+
9+
class AppKernel
10+
{
11+
const SERVICES_FILE = 'services.yml';
12+
const CONFIG_PATH = '/config/';
13+
14+
/**
15+
* @var ContainerBuilder
16+
*/
17+
private $container;
18+
19+
public function __construct()
20+
{
21+
$this->container = new ContainerBuilder();
22+
$this->container->addCompilerPass(new CommandBusCompilerPass());
23+
$this->container->addCompilerPass(new QueryBusCompilerPass());
24+
$this->getConfigServices();
25+
$this->container->compile();
26+
}
27+
28+
private function getConfigServices()
29+
{
30+
$loader = new YamlFileLoader($this->container, new FileLocator(__DIR__.self::CONFIG_PATH));
31+
$loader->load(self::SERVICES_FILE);
32+
}
33+
34+
/**
35+
* @param string $serviceName
36+
*
37+
* @return object
38+
*/
39+
public function get($serviceName)
40+
{
41+
return $this->container->get($serviceName);
42+
}
43+
}

0 commit comments

Comments
 (0)