diff --git a/composer.json b/composer.json index 98ee55967..94e9f93f4 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,8 @@ "wiki" : "http://thelia.net/wiki" }, "require":{ + "php": ">=5.4.0", + "ircmaxell/password-compat": "dev-master", "propel/propel1" : "1.6.*", "psr/log" : "dev-master", "symfony/class-loader": "2.1.*", @@ -15,8 +17,7 @@ "symfony/dependency-injection" : "2.1.*", "symfony/event-dispatcher" : "2.1.*", "symfony/http-kernel" : "2.1.*", - "symfony/routing" : "2.1.*", - "symfony-cmf/routing" : "1.0.*@dev" + "symfony/routing" : "2.1.*" }, "minimum-stability": "stable", "config" : { diff --git a/core/lib/Thelia/Action/BaseAction.php b/core/lib/Thelia/Action/BaseAction.php new file mode 100644 index 000000000..76ac786d8 --- /dev/null +++ b/core/lib/Thelia/Action/BaseAction.php @@ -0,0 +1,58 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Action; + +use Symfony\Component\EventDispatcher\EventDispatcherInterface; + +/** + * + * + * @author Manuel Raynaud + */ + +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; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Action/Cart.php b/core/lib/Thelia/Action/Cart.php new file mode 100644 index 000000000..94e00ab81 --- /dev/null +++ b/core/lib/Thelia/Action/Cart.php @@ -0,0 +1,64 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Action; + +use Symfony\Component\HttpFoundation\Request; +use Thelia\Action\BaseAction; + +class Cart extends BaseAction +{ + /** + * + * add an article to cart + * + * @param \Symfony\Component\HttpFoundation\Request $request + */ + public function addCart(Request $request) + { + var_dump($this->getDispatcher()); exit; + } + + /** + * + * Delete specify article present into cart + * + * @param \Symfony\Component\HttpFoundation\Request $request + */ + public function deleteArticle(Request $request) + { + + } + + /** + * + * Modify article's quantity + * + * @param \Symfony\Component\HttpFoundation\Request $request + */ + public function modifyArticle(Request $request) + { + + } +} + diff --git a/core/lib/Thelia/Action/Customer.php b/core/lib/Thelia/Action/Customer.php new file mode 100644 index 000000000..b66396289 --- /dev/null +++ b/core/lib/Thelia/Action/Customer.php @@ -0,0 +1,45 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Action; + +use Symfony\Component\HttpFoundation\Request; + +class Customer +{ + + public function create(Request $request) + { + + } + + public function modify(Request $request) + { + + } + + public function modifyPassword(Request $request) + { + + } +} diff --git a/core/lib/Thelia/Controller/DefaultController.php b/core/lib/Thelia/Controller/DefaultController.php index 4d8f45c6c..b143af56a 100644 --- a/core/lib/Thelia/Controller/DefaultController.php +++ b/core/lib/Thelia/Controller/DefaultController.php @@ -1,5 +1,25 @@ . */ +/* */ +/*************************************************************************************/ namespace Thelia\Controller; use Thelia\Controller\NullControllerInterface; diff --git a/core/lib/Thelia/Core/Bundle/TheliaBundle.php b/core/lib/Thelia/Core/Bundle/TheliaBundle.php index 3d1e46d64..a95082e73 100644 --- a/core/lib/Thelia/Core/Bundle/TheliaBundle.php +++ b/core/lib/Thelia/Core/Bundle/TheliaBundle.php @@ -101,6 +101,11 @@ class TheliaBundle extends Bundle ->addMethodCall('addSubscriber', array(new Reference('listener.router'))) ->addMethodCall('addSubscriber', array(new Reference('thelia.listener.view'))) ; + + + // TODO : save listener from plugins + + $container->getDefinition('matcher.action')->addMethodCall("setDispatcher", array(new Reference('dispatcher'))); $container->register('http_kernel','Thelia\Core\TheliaHttpKernel') ->addArgument(new Reference('dispatcher')) diff --git a/core/lib/Thelia/Core/Event/ActionEvent.php b/core/lib/Thelia/Core/Event/ActionEvent.php new file mode 100644 index 000000000..7915b7812 --- /dev/null +++ b/core/lib/Thelia/Core/Event/ActionEvent.php @@ -0,0 +1,104 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; + +use Symfony\Component\EventDispatcher\Event; +use Symfony\Component\HttpFoundation\Request; +/** + * + * Class thrown on Thelia.action event + * + * call setAction if action match yours + * + */ +class ActionEvent extends Event +{ + + /** + * + * @var Symfony\Component\HttpFoundation\Request + */ + protected $request; + + /** + * + * @var string + */ + protected $action; + + /** + * + * @var string + */ + protected $controller; + + /** + * + * @param \Symfony\Component\HttpFoundation\Request $request + * @param string $action + */ + public function __construct(Request $request, $action) { + $this->request = $request; + $this->action = $action; + } + + /** + * + * @return string + */ + public function getAction() + { + return $this->action; + } + + /** + * + * @return \Symfony\Component\HttpFoundation\Request + */ + public function getRequest() + { + 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/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php new file mode 100644 index 000000000..8d5bb258c --- /dev/null +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -0,0 +1,43 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; + +/** + * + * Class containing all Thelia events name using in Thelia Core + * + * + * @author Manuel Raynaud + */ + +final class TheliaEvents +{ + + /** + * ACTION event + * + * Send if no action are already present in Thelia action process ( see Thelia\Routing\Matcher\ActionMatcher) + */ + const ACTION = "thelia.action"; +} \ No newline at end of file diff --git a/core/lib/Thelia/Routing/Matcher/ActionMatcher.php b/core/lib/Thelia/Routing/Matcher/ActionMatcher.php index 4b4431652..538814d7b 100644 --- a/core/lib/Thelia/Routing/Matcher/ActionMatcher.php +++ b/core/lib/Thelia/Routing/Matcher/ActionMatcher.php @@ -26,22 +26,68 @@ namespace Thelia\Routing\Matcher; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Matcher\RequestMatcherInterface; use Symfony\Component\Routing\Exception\ResourceNotFoundException; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; + +use Thelia\Core\Event\ActionEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Action\Cart; + +/** + * Matcher using action param in get or post method to perform actions. For exemple index.php?action=addCart will find the good controller that can perform this action. + * + * @author Manuel Raynaud + */ class ActionMatcher implements RequestMatcherInterface { + /** + * + * @var Symfony\Component\EventDispatcher\EventDispatcherInterface + */ + protected $dispatcher; + + public function setDispatcher(EventDispatcherInterface $dispatcher) + { + $this->dispatcher = $dispatcher; + } + public function matchRequest(Request $request) { if (false !== $action = $request->get("action")) { - //search corresponding action - + return $this->dispatchAction($request, $action); } throw new ResourceNotFoundException("No action parameter found"); } - protected function findActionParam(Request $request) + protected function dispatchAction(Request $request, $action) { + $controller = null; + switch ($action) { + case 'addProduct': + $controller = array( + new Cart($this->dispatcher), + "addCart" + ); + break; + default : + $event = new ActionEvent($request, $action); + $event->setDispatcher($this->dispatcher); + $this->dispatcher->dispatch(TheliaEvents::ACTION, $event); + if ($event->hasController()) { + $controller = $event->getController(); + } + break; + } + + if ($controller) { + return array( + '_controller' => $controller + ); + } + + throw new ResourceNotFoundException("No action parameter found"); } }