forked from ezsystems/ezpublish-kernel
/
ConsoleCommandListener.php
74 lines (63 loc) · 2.06 KB
/
ConsoleCommandListener.php
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
<?php
/**
* File containing the ConsoleCommandListener class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*
* @version //autogentag//
*/
namespace eZ\Bundle\EzPublishCoreBundle\EventListener;
use eZ\Publish\Core\MVC\Symfony\Event\ScopeChangeEvent;
use eZ\Publish\Core\MVC\Symfony\MVCEvents;
use eZ\Publish\Core\MVC\Symfony\SiteAccess;
use eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessAware;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* ConsoleCommandListener event listener.
*/
class ConsoleCommandListener implements EventSubscriberInterface, SiteAccessAware
{
/**
* @var string
*/
private $defaultSiteAccessName;
/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;
/**
* @var
*/
private $siteAccess;
/**
* ConsoleCommandListener constructor.
*/
public function __construct($defaultSiteAccessName, EventDispatcherInterface $eventDispatcher)
{
$this->defaultSiteAccessName = $defaultSiteAccessName;
$this->eventDispatcher = $eventDispatcher;
}
public static function getSubscribedEvents()
{
return [
ConsoleEvents::COMMAND => [
['onConsoleCommand', -1],
],
];
}
public function onConsoleCommand(ConsoleCommandEvent $event)
{
$siteAccessName = $event->getInput()->getParameterOption('--siteaccess', null);
$this->siteAccess->name = $siteAccessName ?: $this->defaultSiteAccessName;
$this->siteAccess->matchingType = 'cli';
$this->eventDispatcher->dispatch(MVCEvents::CONFIG_SCOPE_CHANGE, new ScopeChangeEvent($this->siteAccess));
}
public function setSiteAccess(SiteAccess $siteAccess = null)
{
$this->siteAccess = $siteAccess;
}
}