change context by Class and service context

This commit is contained in:
Manuel Raynaud
2013-08-12 14:49:43 +02:00
parent b505d785ca
commit b4c4898374
4 changed files with 24 additions and 1 deletions

View File

@@ -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);

View File

@@ -60,6 +60,7 @@
<argument type="service" id="thelia.parser.context"/>
</service>
<!--
A ControllerResolver that supports "a:b:c", "service:method" and class::method" notations,
thus allowing the definition of controllers as service (see http://symfony.com/fr/doc/current/cookbook/controller/service.html)
@@ -81,6 +82,8 @@
<argument type="service" id="request" />
</service>
<service id="thelia.envContext" class="Thelia\Core\Context"/>
<!-- Parser context -->
<service id="thelia.parser.context" class="Thelia\Core\Template\ParserContext" scope="request">

View File

@@ -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;
}
}

View File

@@ -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;
}
}