diff --git a/core/lib/Thelia/Core/Event/ActionEvent.php b/core/lib/Thelia/Core/Event/ActionEvent.php index 183ec2feb..5af624240 100644 --- a/core/lib/Thelia/Core/Event/ActionEvent.php +++ b/core/lib/Thelia/Core/Event/ActionEvent.php @@ -32,7 +32,7 @@ use Symfony\Component\HttpFoundation\Request; * call setAction if action match yours * */ -class ActionEvent extends Event +abstract class ActionEvent extends Event { /** diff --git a/core/lib/Thelia/Core/Event/ActionEventClass.php b/core/lib/Thelia/Core/Event/ActionEventClass.php new file mode 100644 index 000000000..d09cdefb4 --- /dev/null +++ b/core/lib/Thelia/Core/Event/ActionEventClass.php @@ -0,0 +1,53 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; + + +use Symfony\Component\EventDispatcher\Event; + +class ActionEventClass extends Event +{ + protected $className; + protected $action; + + public function __construct($action) + { + $this->action = $action; + } + + public function setClassName($className) + { + $this->className = $className; + } + + public function hasClassName() + { + return $this->className !== null; + } + + public function getClassName() + { + return $this->className; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/DefaultActionEvent.php b/core/lib/Thelia/Core/Event/DefaultActionEvent.php new file mode 100644 index 000000000..a4599fa6a --- /dev/null +++ b/core/lib/Thelia/Core/Event/DefaultActionEvent.php @@ -0,0 +1,16 @@ +getRequest(); if (false !== $action = $request->get("action")) { //search corresponding action - $event = new ActionEvent($request, $action); - $dispatcher->dispatch("action.".$action, $event); + $event = new ActionEventFactory($request, $action, $event->getDispatcher()); + $dispatcher->dispatch("action.".$action, $event->createActionEvent()); } } diff --git a/core/lib/Thelia/Core/Factory/ActionEventFactory.php b/core/lib/Thelia/Core/Factory/ActionEventFactory.php new file mode 100644 index 000000000..26ff2d3cc --- /dev/null +++ b/core/lib/Thelia/Core/Factory/ActionEventFactory.php @@ -0,0 +1,73 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Factory; + +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Thelia\Core\Event\ActionEventClass; + +class ActionEventFactory +{ + + protected $request; + protected $action; + protected $dispatcher; + + public function __construct(Request $request, $action, EventDispatcherInterface $dispatcher) + { + $this->request = $request; + $this->action = $action; + $this->dispatcher = $dispatcher; + } + + public function createActionEvent() + { + $className = "Thelia\\Core\\Event\\".$this->action."Event"; + $class = null; + if (class_exists($className)) { + $class = new \ReflectionClass($className); + // return $class->newInstance($this->request, $this->action); + } else { + $actionEventClass = new ActionEventClass($this->action); + $this->dispatcher->dispatch("action.searchClass", $actionEventClass); + + if ($actionEventClass->hasClassName()) { + $class = new \ReflectionClass($className); + } + } + + if( is_null($class)) { + $class = new \ReflectionClass("Thelia\Core\Event\DefaultActionEvent"); + } + + if ($class->isSubclassOf("Thelia\Core\Event\ActionEvent") === false) { + + } + + return $class->newInstance($this->request, $this->action); + } + + + +} \ No newline at end of file