-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventSubscriber.php
More file actions
62 lines (52 loc) · 1.66 KB
/
EventSubscriber.php
File metadata and controls
62 lines (52 loc) · 1.66 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
<?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\PHPBrew;
use Dotfiles\Core\Constant;
use Dotfiles\Core\DI\Parameters;
use Dotfiles\Core\Event\PatchEvent;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class EventSubscriber implements EventSubscriberInterface
{
/**
* @var Parameters
*/
private $config;
/**
* @var LoggerInterface
*/
private $logger;
public function __construct(Parameters $config, LoggerInterface $logger)
{
$this->config = $config;
$this->logger = $logger;
}
public static function getSubscribedEvents()
{
return array(
Constant::EVENT_PRE_PATCH => 'onPrePatchEvent',
);
}
public function onPrePatchEvent(PatchEvent $event): void
{
$config = $this->config;
if ($config->get('phpbrew.set_prompt')) {
$event->addPatch('.bashrc', 'export PHPBREW_SET_PROMPT=1');
$this->logger->debug('+phpbrew configured <comment>PHPBREW_USE_PROMPT</comment>');
}
if ($config->get('phpbrew.rc_enable')) {
$event->addPatch('.bashrc', 'export PHPBREW_RC_ENABLE=1');
$this->logger->debug('+phpbrew configured <comment>PHPBREW_RC_ENABLE</comment>');
}
$phpBrewScript = $config->get('dotfiles.home_dir').'/.phpbrew/bashrc';
$event->addPatch('.bashrc', 'source "'.$phpBrewScript.'"');
}
}