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": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Anthony Ferrara",
|
"name": "Anthony Ferrara",
|
||||||
"email": "ircmaxell@ircmaxell.com",
|
"email": "ircmaxell@php.net",
|
||||||
"homepage": "http://blog.ircmaxell.com"
|
"homepage": "http://blog.ircmaxell.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -772,12 +772,12 @@
|
|||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/fzaninotto/Faker.git",
|
"url": "https://github.com/fzaninotto/Faker.git",
|
||||||
"reference": "c2b06f9741106c35eb7e21dda4c72a54415277dd"
|
"reference": "202c8517478011464e0e50923cab2bcd6344453b"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/fzaninotto/Faker/zipball/c2b06f9741106c35eb7e21dda4c72a54415277dd",
|
"url": "https://api.github.com/repos/fzaninotto/Faker/zipball/202c8517478011464e0e50923cab2bcd6344453b",
|
||||||
"reference": "c2b06f9741106c35eb7e21dda4c72a54415277dd",
|
"reference": "202c8517478011464e0e50923cab2bcd6344453b",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@@ -791,7 +791,8 @@
|
|||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": {
|
"psr-0": {
|
||||||
"Faker": "src/"
|
"Faker": "src/",
|
||||||
|
"Faker\\PHPUnit": "test/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
@@ -809,7 +810,7 @@
|
|||||||
"faker",
|
"faker",
|
||||||
"fixtures"
|
"fixtures"
|
||||||
],
|
],
|
||||||
"time": "2013-05-13 07:57:43"
|
"time": "2013-05-20 20:34:10"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"aliases": [
|
"aliases": [
|
||||||
|
|||||||
@@ -4,6 +4,13 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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">
|
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>
|
<services>
|
||||||
|
|
||||||
<service id="thelia.action.cart" class="Thelia\Action\Cart">
|
<service id="thelia.action.cart" class="Thelia\Action\Cart">
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class ControllerListener implements EventSubscriberInterface
|
|||||||
$request = $event->getRequest();
|
$request = $event->getRequest();
|
||||||
if (false !== $action = $request->get("action")) {
|
if (false !== $action = $request->get("action")) {
|
||||||
//search corresponding 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());
|
$dispatcher->dispatch("action.".$action, $event->createActionEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,19 +39,16 @@ class ActionEventFactory
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $className = array(
|
protected $className;
|
||||||
"addArticle" => "Thelia\Core\Event\CartEvent",
|
|
||||||
"deleteArticle" => "Thelia\Core\Event\CartEvent",
|
|
||||||
"modifyArticle" => "Thelia\Core\Event\CartEvent",
|
|
||||||
);
|
|
||||||
|
|
||||||
protected $defaultClassName = "Thelia\Core\Event\DefaultActionEvent";
|
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->request = $request;
|
||||||
$this->action = $action;
|
$this->action = $action;
|
||||||
$this->dispatcher = $dispatcher;
|
$this->dispatcher = $dispatcher;
|
||||||
|
$this->className = $className;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createActionEvent()
|
public function createActionEvent()
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ use Thelia\Model;
|
|||||||
|
|
||||||
class TheliaHttpKernel extends HttpKernel
|
class TheliaHttpKernel extends HttpKernel
|
||||||
{
|
{
|
||||||
|
|
||||||
|
protected $container;
|
||||||
|
|
||||||
public function __construct(EventDispatcherInterface $dispatcher, ContainerInterface $container, ControllerResolverInterface $controllerResolver)
|
public function __construct(EventDispatcherInterface $dispatcher, ContainerInterface $container, ControllerResolverInterface $controllerResolver)
|
||||||
{
|
{
|
||||||
parent::__construct($dispatcher, $controllerResolver);
|
parent::__construct($dispatcher, $controllerResolver);
|
||||||
@@ -46,6 +49,11 @@ class TheliaHttpKernel extends HttpKernel
|
|||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getContainer()
|
||||||
|
{
|
||||||
|
return $this->container;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a Request to convert it to a Response.
|
* Handles a Request to convert it to a Response.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user