refactor action factory, className are inject from service container
This commit is contained in:
13
composer.lock
generated
13
composer.lock
generated
@@ -76,7 +76,7 @@
|
||||
"authors": [
|
||||
{
|
||||
"name": "Anthony Ferrara",
|
||||
"email": "ircmaxell@ircmaxell.com",
|
||||
"email": "ircmaxell@php.net",
|
||||
"homepage": "http://blog.ircmaxell.com"
|
||||
}
|
||||
],
|
||||
@@ -772,12 +772,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/fzaninotto/Faker.git",
|
||||
"reference": "c2b06f9741106c35eb7e21dda4c72a54415277dd"
|
||||
"reference": "202c8517478011464e0e50923cab2bcd6344453b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/fzaninotto/Faker/zipball/c2b06f9741106c35eb7e21dda4c72a54415277dd",
|
||||
"reference": "c2b06f9741106c35eb7e21dda4c72a54415277dd",
|
||||
"url": "https://api.github.com/repos/fzaninotto/Faker/zipball/202c8517478011464e0e50923cab2bcd6344453b",
|
||||
"reference": "202c8517478011464e0e50923cab2bcd6344453b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -791,7 +791,8 @@
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Faker": "src/"
|
||||
"Faker": "src/",
|
||||
"Faker\\PHPUnit": "test/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
@@ -809,7 +810,7 @@
|
||||
"faker",
|
||||
"fixtures"
|
||||
],
|
||||
"time": "2013-05-13 07:57:43"
|
||||
"time": "2013-05-20 20:34:10"
|
||||
}
|
||||
],
|
||||
"aliases": [
|
||||
|
||||
@@ -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