diff --git a/core/lib/Thelia/Action/BaseAction.php b/core/lib/Thelia/Action/BaseAction.php deleted file mode 100644 index 3739f234d..000000000 --- a/core/lib/Thelia/Action/BaseAction.php +++ /dev/null @@ -1,59 +0,0 @@ -. */ -/* */ -/*************************************************************************************/ - -namespace Thelia\Action; - -use Symfony\Component\EventDispatcher\EventDispatcherInterface; - -/** - * - * - * @author Manuel Raynaud - */ - -abstract class BaseAction -{ - /** - * - * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface - */ - protected $dispatcher; - - /** - * - * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher - */ - public function __construct(EventDispatcherInterface $dispatcher) - { - $this->dispatcher = $dispatcher; - } - - /** - * - * @return \Symfony\Component\EventDispatcher\EventDispatcherInterface - */ - public function getDispatcher() - { - return $this->dispatcher; - } -} diff --git a/core/lib/Thelia/Action/Cart.php b/core/lib/Thelia/Action/Cart.php index 739f3e402..5d85f774f 100644 --- a/core/lib/Thelia/Action/Cart.php +++ b/core/lib/Thelia/Action/Cart.php @@ -24,17 +24,19 @@ namespace Thelia\Action; use Symfony\Component\HttpFoundation\Request; -use Thelia\Action\BaseAction; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Thelia\Core\Event\ActionEvent; -class Cart extends BaseAction + +class Cart implements EventSubscriberInterface { /** * * add an article to cart * - * @param \Symfony\Component\HttpFoundation\Request $request + * @param \Thelia\Core\Event\ActionEvent $event */ - public function addCart(Request $request) + public function addArticle(ActionEvent $event) { } @@ -43,9 +45,9 @@ class Cart extends BaseAction * * Delete specify article present into cart * - * @param \Symfony\Component\HttpFoundation\Request $request + * @param \Thelia\Core\Event\ActionEvent $event */ - public function deleteArticle(Request $request) + public function deleteArticle(ActionEvent $event) { } @@ -54,10 +56,39 @@ class Cart extends BaseAction * * Modify article's quantity * - * @param \Symfony\Component\HttpFoundation\Request $request + * @param \Thelia\Core\Event\ActionEvent $event */ - public function modifyArticle(Request $request) + public function modifyArticle(ActionEvent $event) { } + + /** + * 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: + * + * * array('eventName' => 'methodName') + * * array('eventName' => array('methodName', $priority)) + * * array('eventName' => array(array('methodName1', $priority), array('methodName2')) + * + * @return array The event names to listen to + * + * @api + */ + public static function getSubscribedEvents() + { + return array( + "action.addArticle" => array("addArticle", 128), + "action.deleteArticle" => array("deleteArticle", 128), + "action.modifyArticle" => array("modifyArticle", 128), + ); + } } diff --git a/core/lib/Thelia/Action/Customer.php b/core/lib/Thelia/Action/Customer.php index 1fc74f123..6dca6dcd2 100644 --- a/core/lib/Thelia/Action/Customer.php +++ b/core/lib/Thelia/Action/Customer.php @@ -23,23 +23,54 @@ namespace Thelia\Action; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; +use Thelia\Core\Event\ActionEvent; -class Customer +class Customer implements EventSubscriberInterface { - public function create(Request $request) + public function create(ActionEvent $event) { } - public function modify(Request $request) + public function modify(ActionEvent $event) { } - public function modifyPassword(Request $request) + public function modifyPassword(ActionEvent $event) { } + + /** + * 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: + * + * * array('eventName' => 'methodName') + * * array('eventName' => array('methodName', $priority)) + * * array('eventName' => array(array('methodName1', $priority), array('methodName2')) + * + * @return array The event names to listen to + * + * @api + */ + public static function getSubscribedEvents() + { + return array( + "action.createCustomer" => array("create", 128), + "action.modifyCustomer" => array("modify", 128) + ); + } + } diff --git a/core/lib/Thelia/Core/Event/ActionEvent.php b/core/lib/Thelia/Core/Event/ActionEvent.php index 7915b7812..183ec2feb 100644 --- a/core/lib/Thelia/Core/Event/ActionEvent.php +++ b/core/lib/Thelia/Core/Event/ActionEvent.php @@ -47,12 +47,6 @@ class ActionEvent extends Event */ protected $action; - /** - * - * @var string - */ - protected $controller; - /** * * @param \Symfony\Component\HttpFoundation\Request $request @@ -80,25 +74,4 @@ class ActionEvent extends Event { return $this->request; } - - /** - * - * @param string $controller - */ - public function setController($controller) - { - $this->controller = $controller; - } - - public function getController() - { - return $this->controller; - } - - public function hasController() - { - return null !== $this->controller; - } - - } diff --git a/core/lib/Thelia/Core/EventListener/RequestListener.php b/core/lib/Thelia/Core/EventListener/RequestListener.php index 989a99135..29b1bead9 100644 --- a/core/lib/Thelia/Core/EventListener/RequestListener.php +++ b/core/lib/Thelia/Core/EventListener/RequestListener.php @@ -25,25 +25,29 @@ namespace Thelia\Core\EventListener; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\GetResponseEvent; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Thelia\Core\Event\ActionEvent; +use Thelia\Core\Event\TheliaEvents; class RequestListener implements EventSubscriberInterface { - protected $container; - public function __construct(ContainerInterface $container) - { - $this->container = $container; - } - public function onKernelRequest(GetResponseEvent $event) - { - } + public function onKernelRequest(GetResponseEvent $event) + { + $dispatcher = $event->getDispatcher(); + $request = $event->getRequest(); + if (false !== $action = $request->get("action")) { + //search corresponding action + $event = new ActionEvent($request, $action); + $dispatcher->dispatch("action.".$action, $event); + } + + } public static function getSubscribedEvents() { - return array( - KernelEvents::REQUEST => array('onKernelRequest', 30) - ); + return array( + KernelEvents::REQUEST => array('onKernelRequest', 0) + ); } } diff --git a/core/lib/Thelia/config.xml b/core/lib/Thelia/config.xml index 4126b9512..8d9bbf7de 100644 --- a/core/lib/Thelia/config.xml +++ b/core/lib/Thelia/config.xml @@ -28,21 +28,21 @@ - + -255 - + @@ -50,6 +50,17 @@ + + + + + + + + + + +