1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
namespace fixtures; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
6
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
7
|
|
|
|
8
|
|
|
require __DIR__.'/App.php'; |
9
|
|
|
|
10
|
|
|
class AppKernel extends Kernel |
11
|
|
|
{ |
12
|
|
|
public function __construct() |
13
|
|
|
{ |
14
|
|
|
\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists'); |
15
|
|
|
$this->name = 'app'.uniqid(); |
16
|
|
|
parent::__construct('test', true); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function registerBundles() |
20
|
|
|
{ |
21
|
|
|
return array( |
22
|
|
|
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle, |
23
|
|
|
new \Symfony\Bundle\TwigBundle\TwigBundle, |
24
|
|
|
new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle, |
25
|
|
|
new \Knp\RadBundle\KnpRadBundle, |
26
|
|
|
new \fixtures\App, |
27
|
|
|
); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function registerContainerConfiguration(LoaderInterface $loader) |
31
|
|
|
{ |
32
|
|
|
if (file_exists($file = __DIR__.'/tmp/config.yml')) { |
33
|
|
|
$loader->load($file); |
34
|
|
|
} |
35
|
|
|
$loader->load(function($container) { |
|
|
|
|
36
|
|
|
$container->loadFromExtension('framework', array( |
37
|
|
|
'test' => null, |
38
|
|
|
'session' => array( |
39
|
|
|
'handler_id' => null, |
40
|
|
|
), |
41
|
|
|
'secret' => '%kernel.secret%', |
42
|
|
|
'csrf_protection' => null, |
43
|
|
|
'form' => null, |
44
|
|
|
'router' => array('resource' => __DIR__.'/routing.yml'), |
45
|
|
|
'validation' => array('enable_annotations' => true), |
46
|
|
|
'templating' => array( |
47
|
|
|
'engines' => array('twig'), |
48
|
|
|
), |
49
|
|
|
)); |
50
|
|
|
$container->loadFromExtension('knp_rad', array( |
51
|
|
|
'csrf_links' => array('enabled' => true,), |
52
|
|
|
'listener' => array( |
53
|
|
|
'orm_user' => false, |
54
|
|
|
), |
55
|
|
|
)); |
56
|
|
|
$container->loadFromExtension('doctrine', array( |
57
|
|
|
'dbal' => array( |
58
|
|
|
'driver' => 'pdo_sqlite', |
59
|
|
|
'dbname' => 'knprad_test', |
60
|
|
|
'path' => __DIR__.'/tmp/knp_rad.sqlite', |
61
|
|
|
), |
62
|
|
|
'orm' => array( |
63
|
|
|
'mappings' => array( |
64
|
|
|
'app' => array( |
65
|
|
|
'type' => 'annotation', |
66
|
|
|
'dir' => __DIR__.'/tmp/App/Entity', |
67
|
|
|
'prefix' => 'App', |
68
|
|
|
), |
69
|
|
|
), |
70
|
|
|
), |
71
|
|
|
)); |
72
|
|
|
}); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
protected function getKernelParameters() |
76
|
|
|
{ |
77
|
|
|
$parameters = parent::getKernelParameters(); |
78
|
|
|
$parameters['kernel.secret'] = 'secret!'; |
79
|
|
|
|
80
|
|
|
return $parameters; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function getCacheDir() |
84
|
|
|
{ |
85
|
|
|
return $this->rootDir.'/tmp/cache/'.$this->name.$this->environment; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getLogDir() |
89
|
|
|
{ |
90
|
|
|
return $this->rootDir.'/tmp/logs'; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.