forked from ezsystems/ezpublish-kernel
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ezsystems#1366 from wizhippo/EZP-2469
Fix EZP-24691: Move scope change to event so legacy-bridge can build …
- Loading branch information
Showing
3 changed files
with
84 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
eZ/Bundle/EzPublishCoreBundle/EventListener/ConsoleCommandListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters