From 298c13ce1fdcee078d041dfca6aff0cbf63e6c6a Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 12 Aug 2013 12:38:23 +0200 Subject: [PATCH 1/4] create context class --- core/lib/Thelia/Core/Context.php | 31 +++++++++++++++++++ .../ContainerAwareAdmin.php | 4 +-- .../Thelia/Core/HttpFoundation/Request.php | 5 ++- 3 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 core/lib/Thelia/Core/Context.php diff --git a/core/lib/Thelia/Core/Context.php b/core/lib/Thelia/Core/Context.php new file mode 100644 index 000000000..aceb000a9 --- /dev/null +++ b/core/lib/Thelia/Core/Context.php @@ -0,0 +1,31 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core; + + +class Context +{ + const CONTEXT_FRONT_OFFICE = 'front'; + const CONTEXT_BACK_OFFICE = 'admin'; +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/DependencyInjection/ContainerAwareAdmin.php b/core/lib/Thelia/Core/DependencyInjection/ContainerAwareAdmin.php index e3e19d63b..b2ad967cf 100644 --- a/core/lib/Thelia/Core/DependencyInjection/ContainerAwareAdmin.php +++ b/core/lib/Thelia/Core/DependencyInjection/ContainerAwareAdmin.php @@ -27,7 +27,7 @@ namespace Thelia\Core\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -use Thelia\Core\Security\SecurityContext; +use Thelia\Core\Context; class ContainerAwareAdmin implements ContainerAwareInterface { @@ -47,7 +47,7 @@ class ContainerAwareAdmin implements ContainerAwareInterface { */ public function setContainer(ContainerInterface $container = null) { - $container->get('request')->setContext(SecurityContext::CONTEXT_BACK_OFFICE); + $container->get('request')->setContext(Context::CONTEXT_BACK_OFFICE); $this->container = $container; } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/HttpFoundation/Request.php b/core/lib/Thelia/Core/HttpFoundation/Request.php index f3711a7dd..8c17d99f9 100755 --- a/core/lib/Thelia/Core/HttpFoundation/Request.php +++ b/core/lib/Thelia/Core/HttpFoundation/Request.php @@ -23,13 +23,12 @@ namespace Thelia\Core\HttpFoundation; use Symfony\Component\HttpFoundation\Request as BaseRequest; -use Thelia\Core\Security\SecurityContext; - +use Thelia\Core\Context; class Request extends BaseRequest { - protected $context = SecurityContext::CONTEXT_FRONT_OFFICE; + protected $context = Context::CONTEXT_FRONT_OFFICE; public function getProductId() { From b505d785caedae668cbda2ed189be19940c58b2b Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 12 Aug 2013 12:51:21 +0200 Subject: [PATCH 2/4] remove context from the request --- core/lib/Thelia/Core/Context.php | 10 ++++++++++ core/lib/Thelia/Core/HttpFoundation/Request.php | 13 ------------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/core/lib/Thelia/Core/Context.php b/core/lib/Thelia/Core/Context.php index aceb000a9..4d8e39bca 100644 --- a/core/lib/Thelia/Core/Context.php +++ b/core/lib/Thelia/Core/Context.php @@ -28,4 +28,14 @@ class Context { const CONTEXT_FRONT_OFFICE = 'front'; const CONTEXT_BACK_OFFICE = 'admin'; + + protected $defineContext = array( + self::CONTEXT_BACK_OFFICE, + self::CONTEXT_FRONT_OFFICE + ); + + public function isValidContext($context) + { + return in_array($context, $this->defineContext); + } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/HttpFoundation/Request.php b/core/lib/Thelia/Core/HttpFoundation/Request.php index 8c17d99f9..7621fa65d 100755 --- a/core/lib/Thelia/Core/HttpFoundation/Request.php +++ b/core/lib/Thelia/Core/HttpFoundation/Request.php @@ -28,8 +28,6 @@ use Thelia\Core\Context; class Request extends BaseRequest { - protected $context = Context::CONTEXT_FRONT_OFFICE; - public function getProductId() { return $this->get("product_id"); @@ -50,15 +48,4 @@ class Request extends BaseRequest } return $uri . $additionalQs; } - - public function setContext($context) - { - $this->context = $context; - } - - public function getContext() - { - return $this->context; - } - } \ No newline at end of file From b4c489837490e7a01fbecdeae9a531fa300ba80e Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 12 Aug 2013 14:49:43 +0200 Subject: [PATCH 3/4] change context by Class and service context --- core/lib/Thelia/Action/BaseAction.php | 5 +++++ core/lib/Thelia/Config/Resources/config.xml | 3 +++ core/lib/Thelia/Core/Context.php | 15 +++++++++++++++ .../DependencyInjection/ContainerAwareAdmin.php | 2 +- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/core/lib/Thelia/Action/BaseAction.php b/core/lib/Thelia/Action/BaseAction.php index f827e0dbd..f351b59bb 100644 --- a/core/lib/Thelia/Action/BaseAction.php +++ b/core/lib/Thelia/Action/BaseAction.php @@ -152,6 +152,11 @@ class BaseAction return $securityContext; } + protected function getContext() + { + return $this->container->get("thelia.envContext"); + } + protected function redirect($url, $status = 302) { $response = new RedirectResponse($url, $status); diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index f9a55fe13..a5e593a85 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -60,6 +60,7 @@ + diff --git a/core/lib/Thelia/Core/Context.php b/core/lib/Thelia/Core/Context.php index 4d8e39bca..23c57ec2a 100644 --- a/core/lib/Thelia/Core/Context.php +++ b/core/lib/Thelia/Core/Context.php @@ -34,8 +34,23 @@ class Context self::CONTEXT_FRONT_OFFICE ); + protected $currentContext = self::CONTEXT_FRONT_OFFICE; + public function isValidContext($context) { return in_array($context, $this->defineContext); } + + public function setContext($context) + { + if($this->isValidContext($context)) + { + $this->currentContext = $context; + } + } + + public function getContext() + { + return $this->currentContext; + } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/DependencyInjection/ContainerAwareAdmin.php b/core/lib/Thelia/Core/DependencyInjection/ContainerAwareAdmin.php index b2ad967cf..3792c22cc 100644 --- a/core/lib/Thelia/Core/DependencyInjection/ContainerAwareAdmin.php +++ b/core/lib/Thelia/Core/DependencyInjection/ContainerAwareAdmin.php @@ -47,7 +47,7 @@ class ContainerAwareAdmin implements ContainerAwareInterface { */ public function setContainer(ContainerInterface $container = null) { - $container->get('request')->setContext(Context::CONTEXT_BACK_OFFICE); + $container->get('thelia.envContext')->setContext(Context::CONTEXT_BACK_OFFICE); $this->container = $container; } } \ No newline at end of file From bb2676a7193bc546f43ceffcc8ee54abe9d6f3f1 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 12 Aug 2013 14:58:28 +0200 Subject: [PATCH 4/4] retrieve context value in BaseAction --- core/lib/Thelia/Action/BaseAction.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Action/BaseAction.php b/core/lib/Thelia/Action/BaseAction.php index f351b59bb..a66ed8301 100644 --- a/core/lib/Thelia/Action/BaseAction.php +++ b/core/lib/Thelia/Action/BaseAction.php @@ -53,7 +53,7 @@ class BaseAction * @param BaseForm $aBaseForm the form * @param string $expectedMethod the expected method, POST or GET, or null for any of them * @throws FormValidationException is the form contains error, or the method is not the right one - * @return Symfony\Component\Form\Form Form the symfony form object + * @return \Symfony\Component\Form\Form Form the symfony form object */ protected function validateForm(BaseForm $aBaseForm, $expectedMethod = null) { @@ -152,9 +152,15 @@ class BaseAction return $securityContext; } + /** + * + * return the environnement context contain in \Thelia\Core\Context class + * + * @return string + */ protected function getContext() { - return $this->container->get("thelia.envContext"); + return $this->container->get("thelia.envContext")->getContext(); } protected function redirect($url, $status = 302)