1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the dotfiles project. |
7
|
|
|
* |
8
|
|
|
* (c) Anthonius Munthi <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Dotfiles\Core\Command; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\Console\Command\Command; |
|
|
|
|
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
19
|
|
|
use Symfony\Component\Process\Process; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class SubsplitCommand. |
23
|
|
|
* |
24
|
|
|
* @codeCoverageIgnore |
25
|
|
|
*/ |
26
|
|
|
class SubsplitCommand extends Command |
27
|
|
|
{ |
28
|
|
|
public const SOURCE = '[email protected]:kilip/dotfiles.git'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var OutputInterface |
32
|
|
|
*/ |
33
|
|
|
private $output; |
34
|
|
|
|
35
|
|
|
private $workdir; |
36
|
|
|
|
37
|
|
|
public function handleProcessRun($type, $buffer): void |
38
|
|
|
{ |
39
|
|
|
$contents = '<info>output:</info> '.$buffer; |
40
|
|
|
if (Process::ERR == $type) { |
41
|
|
|
$contents = '<error>error:</error> '.$buffer; |
42
|
|
|
} |
43
|
|
|
$this->output->write($contents); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected function configure(): void |
47
|
|
|
{ |
48
|
|
|
$this->setName('subsplit'); |
49
|
|
|
$this->workdir = realpath(__DIR__.'/../../../'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): void |
53
|
|
|
{ |
54
|
|
|
$this->output = $output; |
55
|
|
|
$workdir = $this->workdir; |
56
|
|
|
|
57
|
|
|
if (!is_dir($dir = $workdir.'/.subsplit')) { |
58
|
|
|
$this->runCommand('git subsplit --debug init '.static::SOURCE); |
59
|
|
|
} else { |
60
|
|
|
$this->runCommand('git subsplit --debug update '.static::SOURCE); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$tree = array( |
64
|
|
|
'core' => array( |
65
|
|
|
'path' => 'src/Core', |
66
|
|
|
'repo' => '[email protected]:dotfilesphp/core.git', |
67
|
|
|
), |
68
|
|
|
'bash' => array( |
69
|
|
|
'path' => 'src/Plugins/Bash', |
70
|
|
|
'repo' => '[email protected]:dotfilesphp/bash-plugin.git', |
71
|
|
|
), |
72
|
|
|
'phpbrew' => array( |
73
|
|
|
'path' => 'src/Plugins/PHPBrew', |
74
|
|
|
'repo' => '[email protected]:dotfilesphp/phpbrew-plugin.git', |
75
|
|
|
), |
76
|
|
|
'composer' => array( |
77
|
|
|
'path' => 'src/Plugins/Composer', |
78
|
|
|
'repo' => '[email protected]:dotfilesphp/composer-plugin.git', |
79
|
|
|
), |
80
|
|
|
'phpcsfixer' => array( |
81
|
|
|
'path' => 'src/Plugins/PHPCSFixer', |
82
|
|
|
'repo' => '[email protected]:dotfilesphp/phpcsfixer-plugin.git', |
83
|
|
|
), |
84
|
|
|
); |
85
|
|
|
|
86
|
|
|
foreach ($tree as $name => $config) { |
87
|
|
|
$this->output->writeln("processing <comment>$name</comment>"); |
88
|
|
|
$this->publish($config['path'], $config['repo']); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
private function publish($path, $repo, $heads = 'master', $tag = null): void |
93
|
|
|
{ |
94
|
|
|
$command = array( |
95
|
|
|
'git', |
96
|
|
|
'subsplit', |
97
|
|
|
'publish', |
98
|
|
|
'--heads='.$heads, |
99
|
|
|
); |
100
|
|
|
if (null !== $tag) { |
101
|
|
|
$command[] = '--tags='.$tag; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
$command[] = $path.':'.$repo; |
105
|
|
|
|
106
|
|
|
$command = implode(' ', $command); |
107
|
|
|
//$this->output->writeln("<comment>$command</comment>"); |
108
|
|
|
$this->runCommand($command); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
private function runCommand($command): void |
112
|
|
|
{ |
113
|
|
|
$process = new Process($command, $this->workdir); |
114
|
|
|
$process->run(array($this, 'handleProcessRun')); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: