<?php
/**
* Copyright(c) 2019 SYSTEM_KD
* Date: 2019/06/15
*/
namespace Plugin\MultiCutDx\EventSubscriber;
use Plugin\MultiCutDx\Config\ConfigSetting;
use Plugin\MultiCutDx\Controller\ShippingMultipleControllerEx;
use Plugin\MultiCutDx\Service\PlgConfigService\ConfigService;
use Psr\Container\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class KernelEventSubscriber implements EventSubscriberInterface
{
protected $configService;
public function __construct(ConfigService $configService)
{
$this->configService = $configService;
}
public function onKernelController(ControllerEvent $event)
{
$request = $event->getRequest();
$route = $request->attributes->get('_route');
if ('shopping_shipping_multiple' == $route
|| 'shopping_shipping_multiple_edit' == $route) {
// 複数配送停止の場合
if ($this->configService->isKeyBool(ConfigSetting::GROUP_MULTI)) {
// Shoppingへ戻す
$shippingMultipleControllerEx = new ShippingMultipleControllerEx();
$event->setController([$shippingMultipleControllerEx, 'index']);
}
}
}
/**
* Returns an array of event names this subscriber wants to listen to.
*
* The array keys are event names and the value can be:
*
* * The method name to call (priority defaults to 0)
* * An array composed of the method name to call and the priority
* * An array of arrays composed of the method names to call and respective
* priorities, or 0 if unset
*
* For instance:
*
* * ['eventName' => 'methodName']
* * ['eventName' => ['methodName', $priority]]
* * ['eventName' => [['methodName1', $priority], ['methodName2']]]
*
* @return array The event names to listen to
*/
public static function getSubscribedEvents()
{
return [
KernelEvents::CONTROLLER => ['onKernelController', -10],
];
}
}