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
|
|
|
private $params; |
34
|
|
|
|
35
|
|
|
public function __construct(array $params = []) |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
$this->params = $params; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param ServiceContainer $container |
42
|
|
|
*/ |
43
|
|
|
public function build(ServiceContainer $container) |
44
|
|
|
{ |
45
|
|
|
$assembler = $this; |
46
|
|
|
$container->addConfigurator(function ($c) use ($assembler) { |
47
|
|
|
$config = isset($assembler->params['mage_locator']) ? $assembler->params['mage_locator'] : $c->getParam('mage_locator', array('main' => '')); |
|
|
|
|
48
|
|
|
|
49
|
|
|
$srcNS = $assembler->getNamespace($config); |
50
|
|
|
$specPrefix = $assembler->getSpecPrefix($config); |
51
|
|
|
$srcPath = $assembler->getSrcPath($config); |
52
|
|
|
$specPath = $assembler->getSpecPath($config); |
53
|
|
|
$codePool = $assembler->getCodePool($config); |
54
|
|
|
$filesystem = $c->get('filesystem'); |
55
|
|
|
|
56
|
|
|
if (!$filesystem->isDirectory($srcPath)) { |
57
|
|
|
$filesystem->makeDirectory($srcPath); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if (!$filesystem->isDirectory($specPath)) { |
61
|
|
|
$filesystem->makeDirectory($specPath); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$factory = new LocatorFactory($srcNS, $specPrefix, $srcPath, $specPath, $filesystem, $codePool); |
65
|
|
|
|
66
|
|
|
$c->define('locator.locators.magento.model_locator', |
67
|
|
|
function () use ($factory) { |
68
|
|
|
return $factory->getLocator('model'); |
69
|
|
|
}, |
70
|
|
|
['locator.locators.magento'] |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
$c->define('locator.locators.magento.block_locator', |
74
|
|
|
function () use ($factory) { |
75
|
|
|
return $factory->getLocator('block'); |
76
|
|
|
}, |
77
|
|
|
['locator.locators.magento'] |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
$c->define('locator.locators.magento.helper_locator', |
81
|
|
|
function () use ($factory) { |
82
|
|
|
return $factory->getLocator('helper'); |
83
|
|
|
}, |
84
|
|
|
['locator.locators.magento'] |
85
|
|
|
); |
86
|
|
|
|
87
|
|
|
$c->define('locator.locators.magento.controller_locator', |
88
|
|
|
function () use ($factory) { |
89
|
|
|
return $factory->getLocator('controller'); |
90
|
|
|
}, |
91
|
|
|
['locator.locators.magento'] |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
$resourceManager = $c->get('locator.resource_manager'); |
95
|
|
|
|
96
|
|
|
array_map( |
97
|
|
|
array($resourceManager, 'registerLocator'), |
98
|
|
|
$c->getByTag('locator.locators.magento') |
99
|
|
|
); |
100
|
|
|
}); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function getNamespace(array $config) |
104
|
|
|
{ |
105
|
|
|
return array_key_exists('namespace', $config) ? $config['namespace'] : ''; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function getSpecPrefix(array $config) |
109
|
|
|
{ |
110
|
|
|
return array_key_exists('spec_prefix', $config) ? $config['spec_prefix'] : ''; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function getSrcPath(Array $config) |
|
|
|
|
114
|
|
|
{ |
115
|
|
|
return array_key_exists('src_path', $config) ? rtrim($config['src_path'], '/') . DIRECTORY_SEPARATOR : 'src'; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function getSpecPath(array $config) |
119
|
|
|
{ |
120
|
|
|
return array_key_exists('spec_path', $config) ? rtrim($config['spec_path'], '/') . DIRECTORY_SEPARATOR : '.'; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function getCodePool(array $config) |
124
|
|
|
{ |
125
|
|
|
return array_key_exists('code_pool', $config) ? $config['code_pool'] : 'local'; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|