1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WellCommerce\Bundle\GeneratorBundle\Manipulator; |
4
|
|
|
|
5
|
|
|
use Sensio\Bundle\GeneratorBundle\Manipulator\ConfigurationManipulator; |
|
|
|
|
6
|
|
|
use Sensio\Bundle\GeneratorBundle\Manipulator\KernelManipulator; |
|
|
|
|
7
|
|
|
use Sensio\Bundle\GeneratorBundle\Manipulator\RoutingManipulator; |
|
|
|
|
8
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
9
|
|
|
use WellCommerce\Bundle\GeneratorBundle\Model\WellCommerceBundle; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class WellCommerceManipulator |
13
|
|
|
* |
14
|
|
|
* @author Adam Piotrowski <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
final class WellCommerceManipulator |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var KernelInterface |
20
|
|
|
*/ |
21
|
|
|
private $kernel; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $rootDir; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* WellCommerceManipulator constructor. |
30
|
|
|
* |
31
|
|
|
* @param KernelInterface $kernel |
32
|
|
|
*/ |
33
|
|
|
public function __construct(KernelInterface $kernel) |
34
|
|
|
{ |
35
|
|
|
$this->kernel = $kernel; |
36
|
|
|
$this->rootDir = $this->kernel->getRootDir() . '/config/'; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function enableBundle(WellCommerceBundle $bundle) |
40
|
|
|
{ |
41
|
|
|
$this->enableKernel($bundle); |
42
|
|
|
$this->enableRouting($bundle); |
43
|
|
|
$this->enableConfiguration($bundle); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
private function enableKernel(WellCommerceBundle $bundle) |
47
|
|
|
{ |
48
|
|
|
$manipulator = new KernelManipulator($this->kernel); |
49
|
|
|
$manipulator->addBundle($bundle->getBundleClassName()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
private function enableRouting(WellCommerceBundle $bundle) |
53
|
|
|
{ |
54
|
|
|
$file = $this->rootDir . '/routing.yml'; |
55
|
|
|
$manipulator = new RoutingManipulator($file); |
56
|
|
|
$manipulator->addResource($bundle->getName(), 'yml'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
private function enableConfiguration(WellCommerceBundle $bundle) |
60
|
|
|
{ |
61
|
|
|
$file = $this->rootDir . '/wellcommerce.yml'; |
62
|
|
|
$manipulator = new ConfigurationManipulator($file); |
63
|
|
|
$manipulator->addResource($bundle); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: