|
1
|
|
|
<?php namespace Comodojo\Dispatcher\Components; |
|
2
|
|
|
|
|
3
|
|
|
use \Symfony\Component\Yaml\Yaml; |
|
4
|
|
|
use \Symfony\Component\Yaml\Exception\ParseException; |
|
5
|
|
|
use \Comodojo\Exception\ConfigurationException; |
|
6
|
|
|
use \Exception; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @package Comodojo dispatcher |
|
10
|
|
|
* @author Marco Giovinazzi <[email protected]> |
|
11
|
|
|
* @license MIT |
|
12
|
|
|
* |
|
13
|
|
|
* LICENSE: |
|
14
|
|
|
* |
|
15
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
16
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
17
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
18
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
19
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
20
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
21
|
|
|
* THE SOFTWARE. |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
class CommandsLoader { |
|
25
|
|
|
|
|
26
|
|
|
public static function load($commandconfig) { |
|
27
|
|
|
|
|
28
|
|
|
$config = self::importData($commandconfig); |
|
29
|
|
|
|
|
30
|
|
|
$classes = []; |
|
31
|
|
|
|
|
32
|
|
|
foreach ($config as $package) { |
|
33
|
|
|
foreach ($package as $command) { |
|
34
|
|
|
if ( $command['scope'] === 'dispatcher') { |
|
35
|
|
|
$classes[] = $command['class']; |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
return $classes; |
|
41
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
protected static function importData($file) { |
|
45
|
|
|
|
|
46
|
|
|
if ( file_exists($file) && is_readable($file) ) { |
|
47
|
|
|
|
|
48
|
|
|
$data = @file_get_contents($file); |
|
49
|
|
|
|
|
50
|
|
|
if ( $data !== false ) { |
|
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
return Yaml::parse($data); |
|
53
|
|
|
|
|
54
|
|
|
} else { |
|
55
|
|
|
throw new ConfigurationException("Configuration file $file not readable"); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
} else { |
|
59
|
|
|
throw new ConfigurationException("Configuration file $file not found"); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|