-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventSubscriber.php
More file actions
90 lines (74 loc) · 2.38 KB
/
EventSubscriber.php
File metadata and controls
90 lines (74 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
declare(strict_types=1);
/*
* This file is part of the dotfiles project.
*
* (c) Anthonius Munthi <me@itstoni.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Dotfiles\Plugins\PHPCSFixer;
use Dotfiles\Core\DI\Parameters;
use Dotfiles\Core\Event\PatchEvent;
use Dotfiles\Core\Util\Downloader;
use Dotfiles\Core\Util\Filesystem;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class EventSubscriber implements EventSubscriberInterface
{
public const URL = 'http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar';
/**
* @var \Dotfiles\Core\DI\Parameters
*/
private $config;
/**
* @var Downloader
*/
private $downloader;
/**
* @var LoggerInterface
*/
private $logger;
/**
* @var OutputInterface
*/
private $output;
public function __construct(Parameters $config, Downloader $downloader, OutputInterface $output, LoggerInterface $logger)
{
$this->config = $config;
$this->downloader = $downloader;
$this->output = $output;
$this->logger = $logger;
}
public static function getSubscribedEvents()
{
return array(
'dotfiles.install' => 'onInstallEvent',
);
}
public function onInstallEvent(PatchEvent $event): void
{
$config = $this->config;
$downloader = $this->downloader;
$dryRun = $config->get('dotfiles.dry_run');
$tempDir = $config->get('dotfiles.temp_dir');
$targetFile = $tempDir.'/phpcs/php-cs-fixer.phar';
$installDir = $config->get('dotfiles.bin_dir');
$installFile = $installDir.DIRECTORY_SEPARATOR.$config->get('phpcs.file_name');
if (is_file($installFile)) {
$this->output->writeln('PHP-CS-Fixer already installed, skipping');
return;
}
if (!is_file($targetFile)) {
$downloader->run(static::URL, $targetFile, $dryRun);
}
if (is_file($targetFile)) {
$fs = new Filesystem();
$fs->copy($targetFile, $installFile);
$fs->chmod($installFile, 0755);
$this->output->writeln('PHP-CS-Fixer installed to: <comment>'.$installFile.'</comment>');
}
}
}