tweak httpFoundation cache part for compatibility with
Thelia\HttpFoundation part
This commit is contained in:
@@ -63,8 +63,6 @@ class ModuleActivateCommand extends BaseModuleGenerate
|
||||
}
|
||||
|
||||
try {
|
||||
new \TheliaDebugBar\TheliaDebugBar();
|
||||
|
||||
$moduleReflection = new \ReflectionClass($module->getFullNamespace());
|
||||
|
||||
$moduleInstance = $moduleReflection->newInstance();
|
||||
|
||||
@@ -71,7 +71,9 @@
|
||||
<argument type="service" id="event_dispatcher"/>
|
||||
</service>
|
||||
|
||||
|
||||
<service id="thelia.response.listener" class="Thelia\Core\EventListener\ResponseListener">
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
</services>
|
||||
|
||||
</config>
|
||||
|
||||
76
core/lib/Thelia/Core/EventListener/ResponseListener.php
Normal file
76
core/lib/Thelia/Core/EventListener/ResponseListener.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?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\EventListener;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
|
||||
|
||||
/**
|
||||
* Class ResponseListener
|
||||
* @package Thelia\Core\EventListener
|
||||
* @author manuel raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class ResponseListener implements EventSubscriberInterface
|
||||
{
|
||||
|
||||
public function onResponse(FilterResponseEvent $event)
|
||||
{
|
||||
$request = $event->getRequest();
|
||||
|
||||
if($request->headers->has('Surrogate-Capability'))
|
||||
{
|
||||
$response = $event->getResponse();
|
||||
$response->headers->set('Surrogate-Control', 'content="ESI/1.0"');
|
||||
$event->setResponse($response);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of event names this subscriber wants to listen to.
|
||||
*
|
||||
* The array keys are event names and the value can be:
|
||||
*
|
||||
* * The method name to call (priority defaults to 0)
|
||||
* * An array composed of the method name to call and the priority
|
||||
* * An array of arrays composed of the method names to call and respective
|
||||
* priorities, or 0 if unset
|
||||
*
|
||||
* For instance:
|
||||
*
|
||||
* * array('eventName' => 'methodName')
|
||||
* * array('eventName' => array('methodName', $priority))
|
||||
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
|
||||
*
|
||||
* @return array The event names to listen to
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
KernelEvents::RESPONSE => array('onResponse', 0)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -23,17 +23,20 @@
|
||||
|
||||
namespace Thelia\Core\HttpKernel\HttpCache;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\HttpCache\Esi;
|
||||
use Symfony\Component\HttpKernel\HttpCache\HttpCache as BaseHttpCache;
|
||||
use Symfony\Component\HttpKernel\HttpCache\Store;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
use Thelia\Core\HttpFoundation\Request as TheliaRequest;
|
||||
|
||||
/**
|
||||
* Class HttpCache
|
||||
* @package Thelia\Core\HttpKernel\HttpCache
|
||||
* @author manuel raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class HttpCache extends BaseHttpCache
|
||||
class HttpCache extends BaseHttpCache implements HttpKernelInterface
|
||||
{
|
||||
|
||||
public function __construct(HttpKernelInterface $kernel, $options = array())
|
||||
@@ -49,4 +52,20 @@ class HttpCache extends BaseHttpCache
|
||||
);
|
||||
}
|
||||
|
||||
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
|
||||
{
|
||||
if (!($request instanceof \Thelia\Core\HttpFoundation\Request)) {
|
||||
$request = TheliaRequest::create(
|
||||
$request->getUri(),
|
||||
$request->getMethod(),
|
||||
$request->getMethod() == 'GET' ? $request->query->all() : $request->request->all(),
|
||||
$request->cookies->all(),
|
||||
$request->files->all(),
|
||||
$request->server->all(),
|
||||
$request->getContent()
|
||||
);
|
||||
}
|
||||
return parent::handle($request, $type, $catch);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -43,6 +43,7 @@ use Thelia\Model;
|
||||
|
||||
class TheliaHttpKernel extends HttpKernel
|
||||
{
|
||||
protected static $session;
|
||||
|
||||
protected $container;
|
||||
|
||||
@@ -79,8 +80,11 @@ class TheliaHttpKernel extends HttpKernel
|
||||
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
|
||||
{
|
||||
//$request->headers->set('X-Php-Ob-Level', ob_get_level());
|
||||
$request = $this->initSession($request);
|
||||
$this->initParam($request);
|
||||
if ($type == HttpKernelInterface::MASTER_REQUEST) {
|
||||
$request = $this->initSession($request);
|
||||
$this->initParam($request);
|
||||
}
|
||||
|
||||
$this->container->enterScope('request');
|
||||
$this->container->set('request', $request, 'request');
|
||||
|
||||
@@ -211,26 +215,29 @@ class TheliaHttpKernel extends HttpKernel
|
||||
|
||||
protected function initSession(Request $request)
|
||||
{
|
||||
if(null === self::$session) {
|
||||
$storage = new Session\Storage\NativeSessionStorage();
|
||||
|
||||
$storage = new Session\Storage\NativeSessionStorage();
|
||||
if (Model\ConfigQuery::read("session_config.default")) {
|
||||
$storage->setSaveHandler(new Session\Storage\Handler\NativeFileSessionHandler(Model\ConfigQuery::read("session_config.save_path", THELIA_ROOT . '/local/session/')));
|
||||
} else {
|
||||
$handlerString = Model\ConfigQuery::read("session_config.handlers", 'Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler');
|
||||
|
||||
if (Model\ConfigQuery::read("session_config.default")) {
|
||||
$storage->setSaveHandler(new Session\Storage\Handler\NativeFileSessionHandler(Model\ConfigQuery::read("session_config.save_path", THELIA_LOCAL_DIR . 'session/')));
|
||||
$handler = new $handlerString;
|
||||
|
||||
$storage->setSaveHandler($handler);
|
||||
}
|
||||
|
||||
if (Model\ConfigQuery::read("session_config.config", null)) {
|
||||
$storage->setOptions(json_decode(Model\ConfigQuery::read("session_config.config")));
|
||||
}
|
||||
|
||||
self::$session = $session = new \Thelia\Core\HttpFoundation\Session\Session($storage);
|
||||
} else {
|
||||
$handlerString = Model\ConfigQuery::read("session_config.handlers", 'Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler');
|
||||
|
||||
$handler = new $handlerString;
|
||||
|
||||
$storage->setSaveHandler($handler);
|
||||
$session = self::$session;
|
||||
}
|
||||
|
||||
if (Model\ConfigQuery::read("session_config.config", null)) {
|
||||
$storage->setOptions(json_decode(Model\ConfigQuery::read("session_config.config")));
|
||||
}
|
||||
|
||||
$session = new \Thelia\Core\HttpFoundation\Session\Session($storage);
|
||||
$session->start();
|
||||
|
||||
$request->setSession($session);
|
||||
|
||||
return $request;
|
||||
|
||||
@@ -44,9 +44,10 @@ if ( false === in_array($request->getClientIp(), $trustedIp)) {
|
||||
$response = Response::create('Forbidden', 403)->send();
|
||||
$thelia->terminate($request, $response);
|
||||
} else {
|
||||
//$thelia = new HttpCache($thelia);
|
||||
$response = $thelia->handle($request)->prepare($request)->send();
|
||||
$thelia->terminate($request, $response);
|
||||
$thelia = new HttpCache($thelia);
|
||||
$response = $thelia->handle($request)->send();
|
||||
//$thelia->terminate($request, $response);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user