1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Paysera\PhpStormHelper; |
6
|
|
|
|
7
|
|
|
use Alchemy\Zippy\Adapter\AdapterContainer; |
8
|
|
|
use Alchemy\Zippy\FileStrategy\ZipFileStrategy; |
9
|
|
|
use Alchemy\Zippy\Zippy; |
10
|
|
|
use GuzzleHttp\Client; |
11
|
|
|
use Humbug\SelfUpdate\Strategy\GithubStrategy; |
12
|
|
|
use Humbug\SelfUpdate\Updater; |
13
|
|
|
use Paysera\PhpStormHelper\Command\ConfigureCommand; |
14
|
|
|
use Paysera\PhpStormHelper\Command\ConfigureInstallationCommand; |
15
|
|
|
use Paysera\PhpStormHelper\Command\SelfUpdateCommand; |
16
|
|
|
use Paysera\PhpStormHelper\Entity\SourceFolder; |
17
|
|
|
use Paysera\PhpStormHelper\Service\ConfigurationOptionFinder; |
18
|
|
|
use Paysera\PhpStormHelper\Service\DirectoryResolver; |
19
|
|
|
use Paysera\PhpStormHelper\Service\DomHelper; |
20
|
|
|
use Paysera\PhpStormHelper\Service\ExternalToolsConfigurationHelper; |
21
|
|
|
use Paysera\PhpStormHelper\Service\GitignoreHelper; |
22
|
|
|
use Paysera\PhpStormHelper\Service\PluginDownloader; |
23
|
|
|
use Paysera\PhpStormHelper\Service\SourceFolderHelper; |
24
|
|
|
use Paysera\PhpStormHelper\Service\StructureConfigurator; |
25
|
|
|
use Paysera\PhpStormHelper\Service\WorkspaceConfigurationHelper; |
26
|
|
|
use Symfony\Component\Console\Application; |
27
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
28
|
|
|
|
29
|
|
|
class PhpStormHelperApplication extends Application |
30
|
|
|
{ |
31
|
6 |
|
public function __construct() |
32
|
|
|
{ |
33
|
6 |
|
parent::__construct('phpstorm-helper', '@application_version@'); |
34
|
|
|
|
35
|
6 |
|
$filesystem = new Filesystem(); |
36
|
6 |
|
$domHelper = new DomHelper(); |
37
|
6 |
|
$configurationOptionFinder = new ConfigurationOptionFinder($domHelper); |
38
|
|
|
|
39
|
6 |
|
$this->addCommands([ |
40
|
6 |
|
new ConfigureCommand( |
41
|
6 |
|
new StructureConfigurator($filesystem), |
42
|
6 |
|
new GitignoreHelper($filesystem, [ |
43
|
6 |
|
file_get_contents(__DIR__ . '/Resources/gitignore-rules.txt'), |
44
|
|
|
]), |
45
|
6 |
|
$configurationOptionFinder, |
46
|
6 |
|
new WorkspaceConfigurationHelper($domHelper, $filesystem), |
47
|
6 |
|
new SourceFolderHelper($configurationOptionFinder, $this->createDefaultSourceFolders()), |
48
|
6 |
|
new Filesystem() |
49
|
|
|
), |
50
|
6 |
|
new ConfigureInstallationCommand( |
51
|
6 |
|
new ExternalToolsConfigurationHelper(new DirectoryResolver(), $filesystem, $domHelper), |
52
|
6 |
|
new PluginDownloader(new DirectoryResolver(), $this->createZippy(), new Client(), $filesystem) |
53
|
|
|
), |
54
|
6 |
|
$this->createSelfUpdateCommand(), |
55
|
|
|
]); |
56
|
6 |
|
} |
57
|
|
|
|
58
|
6 |
|
private function createZippy() |
59
|
|
|
{ |
60
|
6 |
|
$adapters = AdapterContainer::load(); |
61
|
|
|
|
62
|
|
|
// Avoid using ProcessBuilder as 4.x version is not supported in zippy |
63
|
6 |
|
$adapters['Alchemy\\Zippy\\Adapter\\ZipAdapter'] = $adapters['Alchemy\\Zippy\\Adapter\\ZipExtensionAdapter']; |
64
|
|
|
|
65
|
6 |
|
$zippy = new Zippy($adapters); |
66
|
6 |
|
$zippy->addStrategy(new ZipFileStrategy($adapters)); |
67
|
6 |
|
return $zippy; |
68
|
|
|
} |
69
|
|
|
|
70
|
6 |
|
private function createSelfUpdateCommand(): SelfUpdateCommand |
71
|
|
|
{ |
72
|
6 |
|
$strategy = new GithubStrategy(); |
73
|
6 |
|
$strategy->setCurrentLocalVersion('@application_version@'); |
74
|
6 |
|
$strategy->setPharName('phpstorm-helper.phar'); |
75
|
6 |
|
$strategy->setPackageName('paysera/util-phpstorm-helper'); |
76
|
|
|
|
77
|
6 |
|
$updater = new Updater(null, false); |
78
|
6 |
|
$updater->setStrategyObject($strategy); |
79
|
|
|
|
80
|
6 |
|
return new SelfUpdateCommand($updater); |
81
|
|
|
} |
82
|
|
|
|
83
|
6 |
|
private function createDefaultSourceFolders(): array |
84
|
|
|
{ |
85
|
|
|
return [ |
86
|
6 |
|
new SourceFolder('src', SourceFolder::TYPE_SOURCE), |
87
|
6 |
|
new SourceFolder('app', SourceFolder::TYPE_SOURCE), |
88
|
6 |
|
new SourceFolder('tests', SourceFolder::TYPE_TEST_SOURCE), |
89
|
6 |
|
new SourceFolder('vendor', SourceFolder::TYPE_EXCLUDED), |
90
|
6 |
|
new SourceFolder('app/cache', SourceFolder::TYPE_EXCLUDED), |
91
|
6 |
|
new SourceFolder('app/logs', SourceFolder::TYPE_EXCLUDED), |
92
|
6 |
|
new SourceFolder('app/uploads', SourceFolder::TYPE_EXCLUDED), |
93
|
6 |
|
new SourceFolder('var', SourceFolder::TYPE_EXCLUDED), |
94
|
6 |
|
new SourceFolder('web/compiled', SourceFolder::TYPE_EXCLUDED), |
95
|
6 |
|
new SourceFolder('public/compiled', SourceFolder::TYPE_EXCLUDED), |
96
|
|
|
]; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|