Merge branch 'actions'
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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">
|
||||
|
||||
56
core/lib/Thelia/Core/Context.php
Normal file
56
core/lib/Thelia/Core/Context.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user