refactor action factory, className are inject from service container
This commit is contained in:
@@ -4,6 +4,13 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">
|
||||
|
||||
<parameters>
|
||||
<parameter key="thelia.actionEvent" type="collection">
|
||||
<parameter key="addArticle">Thelia\Core\Event\CartEvent</parameter>
|
||||
<parameter key="modifyArticle">Thelia\Core\Event\CartEvent</parameter>
|
||||
<parameter key="deleteArticle">Thelia\Core\Event\CartEvent</parameter>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<services>
|
||||
|
||||
<service id="thelia.action.cart" class="Thelia\Action\Cart">
|
||||
|
||||
@@ -48,7 +48,7 @@ class ControllerListener implements EventSubscriberInterface
|
||||
$request = $event->getRequest();
|
||||
if (false !== $action = $request->get("action")) {
|
||||
//search corresponding action
|
||||
$event = new ActionEventFactory($request, $action, $event->getDispatcher());
|
||||
$event = new ActionEventFactory($request, $action, $event->getDispatcher(), $event->getKernel()->getContainer()->getParameter("thelia.actionEvent"));
|
||||
$dispatcher->dispatch("action.".$action, $event->createActionEvent());
|
||||
}
|
||||
|
||||
|
||||
@@ -39,19 +39,16 @@ class ActionEventFactory
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $className = array(
|
||||
"addArticle" => "Thelia\Core\Event\CartEvent",
|
||||
"deleteArticle" => "Thelia\Core\Event\CartEvent",
|
||||
"modifyArticle" => "Thelia\Core\Event\CartEvent",
|
||||
);
|
||||
protected $className;
|
||||
|
||||
protected $defaultClassName = "Thelia\Core\Event\DefaultActionEvent";
|
||||
|
||||
public function __construct(Request $request, $action, EventDispatcherInterface $dispatcher)
|
||||
public function __construct(Request $request, $action, EventDispatcherInterface $dispatcher, $className)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->action = $action;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->className = $className;
|
||||
}
|
||||
|
||||
public function createActionEvent()
|
||||
|
||||
@@ -39,6 +39,9 @@ use Thelia\Model;
|
||||
|
||||
class TheliaHttpKernel extends HttpKernel
|
||||
{
|
||||
|
||||
protected $container;
|
||||
|
||||
public function __construct(EventDispatcherInterface $dispatcher, ContainerInterface $container, ControllerResolverInterface $controllerResolver)
|
||||
{
|
||||
parent::__construct($dispatcher, $controllerResolver);
|
||||
@@ -46,6 +49,11 @@ class TheliaHttpKernel extends HttpKernel
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a Request to convert it to a Response.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user