1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* MageSpec |
4
|
|
|
* |
5
|
|
|
* NOTICE OF LICENSE |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the MIT License, that is bundled with this |
8
|
|
|
* package in the file LICENSE. |
9
|
|
|
* It is also available through the world-wide-web at this URL: |
10
|
|
|
* |
11
|
|
|
* http://opensource.org/licenses/MIT |
12
|
|
|
* |
13
|
|
|
* If you did not receive a copy of the license and are unable to obtain it |
14
|
|
|
* through the world-wide-web, please send an email |
15
|
|
|
* to <[email protected]> so we can send you a copy immediately. |
16
|
|
|
* |
17
|
|
|
* @category MageTest |
18
|
|
|
* @package PhpSpec_MagentoExtension |
19
|
|
|
* |
20
|
|
|
* @copyright Copyright (c) 2012-2013 MageTest team and contributors. |
21
|
|
|
*/ |
22
|
|
|
namespace MageTest\PhpSpec\MagentoExtension\Extension; |
23
|
|
|
|
24
|
|
|
use MageTest\PhpSpec\MagentoExtension\Locator\Magento\BlockLocator; |
25
|
|
|
use MageTest\PhpSpec\MagentoExtension\Locator\Magento\ControllerLocator; |
26
|
|
|
use MageTest\PhpSpec\MagentoExtension\Locator\Magento\HelperLocator; |
27
|
|
|
use MageTest\PhpSpec\MagentoExtension\Locator\Magento\ModelLocator; |
28
|
|
|
use PhpSpec\Locator\ResourceManager; |
29
|
|
|
use PhpSpec\ServiceContainer; |
30
|
|
|
|
31
|
|
|
class LocatorAssembler implements Assembler |
32
|
|
|
{ |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param ServiceContainer $container |
36
|
|
|
*/ |
37
|
|
|
public function build(ServiceContainer $container) |
38
|
|
|
{ |
39
|
|
|
$assembler = $this; |
40
|
|
|
$container->addConfigurator(function ($c) use ($assembler) { |
41
|
|
|
$config = $c->getParam('mage_locator', array('main' => '')); |
42
|
|
|
|
43
|
|
|
$srcNS = $assembler->getNamespace($config); |
44
|
|
|
$specPrefix = $assembler->getSpecPrefix($config); |
45
|
|
|
$srcPath = $assembler->getSrcPath($config); |
46
|
|
|
$specPath = $assembler->getSpecPath($config); |
47
|
|
|
$codePool = $assembler->getCodePool($config); |
48
|
|
|
$filesystem = $c->get('filesystem'); |
49
|
|
|
|
50
|
|
|
if (!$filesystem->isDirectory($srcPath)) { |
51
|
|
|
$filesystem->makeDirectory($srcPath); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if (!$filesystem->isDirectory($specPath)) { |
55
|
|
|
$filesystem->makeDirectory($specPath); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$factory = new LocatorFactory($srcNS, $specPrefix, $srcPath, $specPath, $filesystem, $codePool); |
59
|
|
|
|
60
|
|
|
$c->setShared('locator.locators.magento.model_locator', |
61
|
|
|
function () use ($factory) { |
62
|
|
|
return $factory->getLocator('model'); |
63
|
|
|
} |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
$c->setShared('locator.locators.magento.block_locator', |
67
|
|
|
function () use ($factory) { |
68
|
|
|
return $factory->getLocator('block'); |
69
|
|
|
} |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
$c->setShared('locator.locators.magento.helper_locator', |
73
|
|
|
function () use ($factory) { |
74
|
|
|
return $factory->getLocator('helper'); |
75
|
|
|
} |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
$c->setShared('locator.locators.magento.controller_locator', |
79
|
|
|
function () use ($factory) { |
80
|
|
|
return $factory->getLocator('controller'); |
81
|
|
|
} |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
$resourceManager = $c->get('locator.resource_manager'); |
85
|
|
|
|
86
|
|
|
array_map( |
87
|
|
|
array($resourceManager, 'registerLocator'), |
88
|
|
|
$c->getByPrefix('locator.locators.magento') |
89
|
|
|
); |
90
|
|
|
}); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function getNamespace(array $config) |
94
|
|
|
{ |
95
|
|
|
return array_key_exists('namespace', $config) ? $config['namespace'] : ''; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function getSpecPrefix(array $config) |
99
|
|
|
{ |
100
|
|
|
return array_key_exists('spec_prefix', $config) ? $config['spec_prefix'] : ''; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function getSrcPath(Array $config) |
|
|
|
|
104
|
|
|
{ |
105
|
|
|
return array_key_exists('src_path', $config) ? rtrim($config['src_path'], '/') . DIRECTORY_SEPARATOR : 'src'; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function getSpecPath(array $config) |
109
|
|
|
{ |
110
|
|
|
return array_key_exists('spec_path', $config) ? rtrim($config['spec_path'], '/') . DIRECTORY_SEPARATOR : '.'; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function getCodePool(array $config) |
114
|
|
|
{ |
115
|
|
|
return array_key_exists('code_pool', $config) ? $config['code_pool'] : 'local'; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|