1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the puli/cli package. |
5
|
|
|
* |
6
|
|
|
* (c) Bernhard Schussek <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Puli\Cli\Handler; |
13
|
|
|
|
14
|
|
|
use Puli\Manager\Api\Discovery\DiscoveryManager; |
15
|
|
|
use Puli\Manager\Api\Factory\FactoryManager; |
16
|
|
|
use Puli\Manager\Api\Repository\RepositoryManager; |
17
|
|
|
use RuntimeException; |
18
|
|
|
use Webmozart\Console\Api\Args\Args; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Handles the "build" command. |
22
|
|
|
* |
23
|
|
|
* @since 1.0 |
24
|
|
|
* |
25
|
|
|
* @author Bernhard Schussek <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class BuildCommandHandler |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var string[] |
31
|
|
|
*/ |
32
|
|
|
private static $targets = array('all', 'factory', 'repository', 'discovery'); |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var RepositoryManager |
36
|
|
|
*/ |
37
|
|
|
private $repoManager; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var DiscoveryManager |
41
|
|
|
*/ |
42
|
|
|
private $discoveryManager; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var FactoryManager |
46
|
|
|
*/ |
47
|
|
|
private $factoryManager; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Creates the handler. |
51
|
|
|
* |
52
|
|
|
* @param RepositoryManager $repoManager The repository manager. |
53
|
|
|
* @param DiscoveryManager $discoveryManager The discovery manager. |
54
|
|
|
* @param FactoryManager $factoryManager The factory manager. |
55
|
|
|
*/ |
56
|
6 |
|
public function __construct(RepositoryManager $repoManager, DiscoveryManager $discoveryManager, FactoryManager $factoryManager) |
57
|
|
|
{ |
58
|
6 |
|
$this->repoManager = $repoManager; |
59
|
6 |
|
$this->discoveryManager = $discoveryManager; |
60
|
6 |
|
$this->factoryManager = $factoryManager; |
61
|
6 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Handles the "build" command. |
65
|
|
|
* |
66
|
|
|
* @param Args $args The console arguments. |
67
|
|
|
* |
68
|
|
|
* @return int The status code. |
69
|
|
|
*/ |
70
|
6 |
|
public function handle(Args $args) |
71
|
|
|
{ |
72
|
6 |
|
$target = $args->getArgument('target'); |
73
|
|
|
|
74
|
6 |
|
if (!in_array($target, self::$targets)) { |
75
|
1 |
|
throw new RuntimeException(sprintf( |
76
|
1 |
|
'Invalid build target "%s". Expected one of: "%s"', |
77
|
|
|
$target, |
78
|
1 |
|
implode('", "', self::$targets) |
79
|
|
|
)); |
80
|
|
|
} |
81
|
|
|
|
82
|
5 |
|
if ('all' === $target || 'factory' === $target) { |
83
|
3 |
|
$this->factoryManager->autoGenerateFactoryClass(); |
84
|
|
|
} |
85
|
|
|
|
86
|
5 |
|
if ('all' === $target || 'repository' === $target) { |
87
|
3 |
|
$this->repoManager->clearRepository(); |
88
|
3 |
|
$this->repoManager->buildRepository(); |
89
|
|
|
} |
90
|
|
|
|
91
|
5 |
|
if ('all' === $target || 'discovery' === $target) { |
92
|
3 |
|
$this->discoveryManager->clearDiscovery(); |
93
|
3 |
|
$this->discoveryManager->buildDiscovery(); |
94
|
3 |
|
$this->discoveryManager->removeObsoleteDisabledBindingDescriptors(); |
95
|
|
|
} |
96
|
|
|
|
97
|
5 |
|
return 0; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|