diff --git a/core/lib/Thelia/Action/BaseAction.php b/core/lib/Thelia/Action/BaseAction.php index f827e0dbd..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,6 +152,17 @@ 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")->getContext(); + } + 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 new file mode 100644 index 000000000..23c57ec2a --- /dev/null +++ b/core/lib/Thelia/Core/Context.php @@ -0,0 +1,56 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core; + + +class Context +{ + const CONTEXT_FRONT_OFFICE = 'front'; + const CONTEXT_BACK_OFFICE = 'admin'; + + protected $defineContext = array( + self::CONTEXT_BACK_OFFICE, + 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 e3e19d63b..3792c22cc 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('thelia.envContext')->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..7621fa65d 100755 --- a/core/lib/Thelia/Core/HttpFoundation/Request.php +++ b/core/lib/Thelia/Core/HttpFoundation/Request.php @@ -23,14 +23,11 @@ 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; - public function getProductId() { return $this->get("product_id"); @@ -51,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