|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
|
4
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
|
5
|
|
|
|
|
6
|
|
|
class AppKernel extends Kernel |
|
7
|
|
|
{ |
|
8
|
|
|
public function registerBundles() |
|
9
|
|
|
{ |
|
10
|
|
|
$bundles = [ |
|
11
|
|
|
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), |
|
12
|
|
|
new Symfony\Bundle\SecurityBundle\SecurityBundle(), |
|
13
|
|
|
new Symfony\Bundle\TwigBundle\TwigBundle(), |
|
14
|
|
|
new Symfony\Bundle\MonologBundle\MonologBundle(), |
|
15
|
|
|
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(), |
|
16
|
|
|
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), |
|
17
|
|
|
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), |
|
18
|
|
|
new Knp\DoctrineBehaviors\Bundle\DoctrineBehaviorsBundle(), |
|
19
|
|
|
new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(), |
|
20
|
|
|
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(), |
|
21
|
|
|
new Mcfedr\JsonFormBundle\McfedrJsonFormBundle(), |
|
22
|
|
|
new Nelmio\CorsBundle\NelmioCorsBundle(), |
|
23
|
|
|
new FOS\JsRoutingBundle\FOSJsRoutingBundle(), |
|
24
|
|
|
new AppBundle\AppBundle() |
|
25
|
|
|
]; |
|
26
|
|
|
|
|
27
|
|
|
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) { |
|
28
|
|
|
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle(); |
|
29
|
|
|
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); |
|
30
|
|
|
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle(); |
|
31
|
|
|
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle(); |
|
32
|
|
|
$bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(); |
|
33
|
|
|
$bundles[] = new Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle(); |
|
34
|
|
|
$bundles[] = new Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle(); |
|
35
|
|
|
$bundles[] = new Hautelook\AliceBundle\HautelookAliceBundle(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
return $bundles; |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function getRootDir() |
|
42
|
|
|
{ |
|
43
|
|
|
return __DIR__; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function getCacheDir() |
|
47
|
|
|
{ |
|
48
|
|
|
return dirname(__DIR__).'/var/cache/'.$this->getEnvironment(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function getLogDir() |
|
52
|
|
|
{ |
|
53
|
|
|
return dirname(__DIR__).'/var/logs'; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function registerContainerConfiguration(LoaderInterface $loader) |
|
57
|
|
|
{ |
|
58
|
|
|
$loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml'); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.