1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; |
4
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
5
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
6
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
7
|
|
|
use Symfony\Component\Routing\RouteCollectionBuilder; |
8
|
|
|
|
9
|
|
|
class AppKernel extends Kernel |
10
|
|
|
{ |
11
|
|
|
use MicroKernelTrait; |
12
|
|
|
|
13
|
|
|
private $config = []; |
14
|
|
|
|
15
|
|
|
private $services = []; |
16
|
|
|
|
17
|
|
|
public function registerBundles() |
18
|
|
|
{ |
19
|
|
|
return [ |
20
|
|
|
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), |
21
|
|
|
new League\Tactician\Bundle\TacticianBundle(), |
22
|
|
|
]; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function defineCacheDir($dir) |
26
|
|
|
{ |
27
|
|
|
$this->cacheDir = $dir; |
|
|
|
|
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function loadConfig($namespace, array $tacticianConfig) |
31
|
|
|
{ |
32
|
|
|
$this->config[$namespace] = $tacticianConfig; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function addServiceToRegister($serviceId, $className, array $tags) |
36
|
|
|
{ |
37
|
|
|
$this->services[$serviceId] = [ |
38
|
|
|
'className' => $className, |
39
|
|
|
'tags' => $tags, |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function getCacheDir() |
44
|
|
|
{ |
45
|
|
|
return $this->cacheDir; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader) |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
$frameworkConfig = ['secret' => 'S0ME_SECRET']; |
51
|
|
|
if (array_key_exists('framework', $this->config)) { |
52
|
|
|
$this->config['framework'] = array_merge($frameworkConfig, $this->config['framework']); |
53
|
|
|
} else { |
54
|
|
|
$this->config['framework'] = $frameworkConfig; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
foreach ($this->config as $namespace => $config) { |
58
|
|
|
$c->loadFromExtension($namespace, $config); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
foreach ($this->services as $serviceId => $definition) { |
62
|
|
|
$service = $c->register($serviceId, $definition['className']); |
63
|
|
|
foreach ($definition['tags'] as $tag) { |
64
|
|
|
$tagName = $tag['name']; |
65
|
|
|
unset($tag['name']); |
66
|
|
|
$service->addTag($tagName, $tag); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected function configureRoutes(RouteCollectionBuilder $routes) |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: