1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the EoHoneypotBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Eymen Gunay <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Eo\HoneypotBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
15
|
|
|
use Symfony\Component\Config\FileLocator; |
16
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
17
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
18
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
19
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* This is the class that loads and manages your bundle configuration |
23
|
|
|
* |
24
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} |
25
|
|
|
*/ |
26
|
|
|
class EoHoneypotExtension extends Extension |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* {@inheritDoc} |
30
|
|
|
*/ |
31
|
|
|
public function load(array $configs, ContainerBuilder $container) |
32
|
|
|
{ |
33
|
|
|
$configuration = new Configuration(); |
34
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
35
|
|
|
|
36
|
|
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
37
|
|
|
$loader->load('services.xml'); |
38
|
|
|
|
39
|
|
|
// Set db |
40
|
|
|
if ($config['storage']['database']['enabled']) { |
41
|
|
|
switch ($config['storage']['database']['driver']) { |
42
|
|
|
case 'orm': |
43
|
|
|
$db = new Reference('doctrine.orm.entity_manager'); |
44
|
|
|
break; |
45
|
|
|
case 'mongodb': |
46
|
|
|
$db = new Reference('doctrine.odm.mongodb.document_manager'); |
47
|
|
|
break; |
48
|
|
|
default: |
49
|
|
|
throw new \LogicException("Invalid db driver given"); |
50
|
|
|
break; |
|
|
|
|
51
|
|
|
} |
52
|
|
|
$container->getDefinition('eo_honeypot.manager')->addMethodCall('setObjectManager', array($db)); |
53
|
|
|
} |
54
|
|
|
$container->setParameter('eo_honeypot.options', $config); |
55
|
|
|
|
56
|
|
|
// Remove RedirectListener if redirect is disabled |
57
|
|
|
if (!$config['redirect']['enabled']) { |
58
|
|
|
$container->removeDefinition('eo_honeypot.redirect_listener'); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.