|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Openl10n\Cli; |
|
4
|
|
|
|
|
5
|
|
|
use Openl10n\Cli\Command; |
|
6
|
|
|
use Openl10n\Cli\Listener\WorkingDirectoryListener; |
|
7
|
|
|
use Openl10n\Cli\ServiceContainer\Configuration\ConfigurationLoader; |
|
8
|
|
|
use Openl10n\Cli\ServiceContainer\Extension; |
|
9
|
|
|
use Openl10n\Cli\ServiceContainer\ExtensionManager; |
|
10
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
|
11
|
|
|
|
|
12
|
|
|
class ApplicationFactory |
|
13
|
|
|
{ |
|
14
|
|
|
const NAME = 'openl10n'; |
|
15
|
|
|
|
|
16
|
|
|
const VERSION = '@package_version@'; |
|
17
|
|
|
|
|
18
|
|
|
const CONFIG_FILENAME = '.openl10n.yml'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Create the application. |
|
22
|
|
|
* |
|
23
|
|
|
* @return Application |
|
24
|
|
|
*/ |
|
25
|
|
|
public function createApplication() |
|
26
|
|
|
{ |
|
27
|
|
|
$configurationLoader = $this->createConfigurationLoader(); |
|
28
|
|
|
$extensionManager = $this->createExtensionManager(); |
|
29
|
|
|
$eventDispatcher = $this->createEventDispatcher(); |
|
30
|
|
|
|
|
31
|
|
|
$eventDispatcher->addSubscriber(new WorkingDirectoryListener($configurationLoader)); |
|
32
|
|
|
|
|
33
|
|
|
$application = new Application(self::NAME, self::VERSION, $configurationLoader, $extensionManager); |
|
34
|
|
|
$application->addCommands($this->getDefaultCommands()); |
|
35
|
|
|
$application->setDispatcher($eventDispatcher); |
|
36
|
|
|
|
|
37
|
|
|
return $application; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @return array The default commands |
|
42
|
|
|
*/ |
|
43
|
|
|
protected function getDefaultCommands() |
|
44
|
|
|
{ |
|
45
|
|
|
return [ |
|
46
|
|
|
new Command\InitCommand(), |
|
47
|
|
|
new Command\PullCommand(), |
|
48
|
|
|
new Command\PushCommand(), |
|
49
|
|
|
]; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return array The default extensions |
|
54
|
|
|
*/ |
|
55
|
|
|
protected function getDefaultExtensions() |
|
56
|
|
|
{ |
|
57
|
|
|
return [ |
|
58
|
|
|
new Extension\CoreExtension(), |
|
59
|
|
|
new Extension\ServerExtension(), |
|
60
|
|
|
new Extension\ProjectExtension(), |
|
61
|
|
|
new Extension\FilesExtension(), |
|
62
|
|
|
new Extension\OptionsExtension(), |
|
63
|
|
|
]; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return ConfigurationLoader The configuration loader |
|
68
|
|
|
*/ |
|
69
|
|
|
protected function createConfigurationLoader() |
|
70
|
|
|
{ |
|
71
|
|
|
return new ConfigurationLoader(getcwd(), self::CONFIG_FILENAME); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return ExtensionManager The extension manager |
|
76
|
|
|
*/ |
|
77
|
|
|
public function createExtensionManager() |
|
78
|
|
|
{ |
|
79
|
|
|
return new ExtensionManager($this->getDefaultExtensions()); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return EventDispatcher An EventDispatcher |
|
84
|
|
|
*/ |
|
85
|
|
|
private function createEventDispatcher() |
|
86
|
|
|
{ |
|
87
|
|
|
return new EventDispatcher(); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|