當前位置: 首頁>>代碼示例>>PHP>>正文


PHP HttpCache\HttpCache類代碼示例

本文整理匯總了PHP中Symfony\Component\HttpKernel\HttpCache\HttpCache的典型用法代碼示例。如果您正苦於以下問題:PHP HttpCache類的具體用法?PHP HttpCache怎麽用?PHP HttpCache使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了HttpCache類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testTerminateDelegatesTerminationOnlyForTerminableInterface

    public function testTerminateDelegatesTerminationOnlyForTerminableInterface()
    {
        $storeMock = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\HttpCache\\StoreInterface')
            ->disableOriginalConstructor()
            ->getMock();

        // does not implement TerminableInterface
        $kernelMock = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\HttpKernelInterface')
            ->disableOriginalConstructor()
            ->getMock();

        $kernelMock->expects($this->never())
            ->method('terminate');

        $kernel = new HttpCache($kernelMock, $storeMock);
        $kernel->terminate(Request::create('/'), new Response());

        // implements TerminableInterface
        $kernelMock = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Kernel')
            ->disableOriginalConstructor()
            ->setMethods(array('terminate', 'registerBundles', 'registerContainerConfiguration'))
            ->getMock();

        $kernelMock->expects($this->once())
            ->method('terminate');

        $kernel = new HttpCache($kernelMock, $storeMock);
        $kernel->terminate(Request::create('/'), new Response());
    }
開發者ID:usefulthink,項目名稱:symfony,代碼行數:29,代碼來源:HttpCacheTest.php

示例2: buildAndCacheResponse

 /**
  *
  */
 protected function buildAndCacheResponse()
 {
     $controllerResolver = new ControllerResolver(array($this, 'buildResponse'));
     $kernel = new HttpKernel(new EventDispatcher(), $controllerResolver);
     if ($this->adapter->isCachingEnabled($this->request)) {
         $kernel = new HttpCache($kernel, $this->adapter->getStore($this->request), $this->adapter->getSurrogate($this->request), $this->adapter->getHttpCacheOptions($this->request));
     }
     $response = $kernel->handle($this->request);
     $this->shutDownFunctionEnabled = false;
     $response->send();
     $kernel->terminate($this->request, $response);
 }
開發者ID:mindgruve,項目名稱:mg-reverse-proxy,代碼行數:15,代碼來源:CachedReverseProxy.php

示例3: handle

 /**
  * {@inheritdoc}
  */
 public function handle(HttpCache $cache, $uri, $alt, $ignoreErrors)
 {
     $subRequest = Request::create($uri, Request::METHOD_GET, array(), $cache->getRequest()->cookies->all(), array(), $cache->getRequest()->server->all());
     try {
         $response = $cache->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true);
         if (!$response->isSuccessful()) {
             throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %s).', $subRequest->getUri(), $response->getStatusCode()));
         }
         return $response->getContent();
     } catch (\Exception $e) {
         if ($alt) {
             return $this->handle($cache, $alt, '', $ignoreErrors);
         }
         if (!$ignoreErrors) {
             throw $e;
         }
     }
 }
開發者ID:MisatoTremor,項目名稱:symfony,代碼行數:21,代碼來源:AbstractSurrogate.php

示例4: array

<?php

ini_set('display_errors', 1);
require_once __DIR__ . '/../vendor/autoload.php';
use Simplex;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel;
use Symfony\Component\DependencyInjection\Reference;
$request = Request::createFromGlobals();
$sc = (include __DIR__ . '/../src/container.php');
$sc->setParameter('routes', include __DIR__ . '/../src/routes.php');
$sc->register('listener.string_response', Simplex\StringResponseListener::class);
$sc->getDefinition('dispatcher')->addMethodCall('addSubscriber', array(new Reference('listener.string_response')));
$framework = $sc->get('framework');
$framework = new HttpKernel\HttpCache\HttpCache($framework, new HttpKernel\HttpCache\Store(__DIR__ . '/../cache'));
$response = $framework->handle($request);
$response->send();
開發者ID:vanekt,項目名稱:framework,代碼行數:17,代碼來源:index.php

示例5: render_template

<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing;
use Symfony\Component\HttpKernel;
use Symfony\Component\EventDispatcher\EventDispatcher;
function render_template(Request $request)
{
    extract($request->attributes->all(), EXTR_SKIP);
    ob_start();
    include sprintf(__DIR__ . '/../src/pages/%s.php', $_route);
    return new Response(ob_get_clean());
}
$request = Request::createFromGlobals();
$routes = (include __DIR__ . '/../src/app.php');
$context = new Routing\RequestContext();
$matcher = new Routing\Matcher\UrlMatcher($routes, $context);
$resolver = new HttpKernel\Controller\ControllerResolver();
$dispatcher = new EventDispatcher();
$dispatcher->addSubscriber(new Simplex\ContentLengthListener());
$dispatcher->addSubscriber(new Simplex\GoogleListener());
/*
$dispatcher = new EventDispatcher();
$dispatcher->addListener('response', array(new Simplex\ContentLengthListener(), 'onResponse'));
$dispatcher->addListener('response', array(new Simplex\GoogleListener(), 'onResponse'), -255);
*/
$framework = new Simplex\Framework($dispatcher, $matcher, $resolver);
$framework = new HttpKernel\HttpCache\HttpCache($framework, new HttpKernel\HttpCache\Store(__DIR__ . '/../cache'));
$framework->handle($request)->send();
開發者ID:Guillaume-RICHARD,項目名稱:micro-framework,代碼行數:31,代碼來源:front.php

示例6: forward

 /**
  * Forwards the Request to the backend and returns the Response.
  *
  * @param Request  $request A Request instance
  * @param Boolean  $raw     Whether to catch exceptions or not
  * @param Response $entry   A Response instance (the stale entry if present, null otherwise)
  *
  * @return Response A Response instance
  */
 protected function forward(Request $request, $raw = false, Response $entry = null)
 {
     $this->getKernel()->boot();
     /** @var $container \Shopware\Components\DependencyInjection\Container */
     $container = $this->getKernel()->getContainer();
     $container->set('HttpCache', $this);
     return parent::forward($request, $raw, $entry);
 }
開發者ID:GerDner,項目名稱:luck-docker,代碼行數:17,代碼來源:AppCache.php

示例7: forward

    /**
     * Forwards the Request to the backend and returns the Response.
     *
     * @param Request $request A Request instance
     * @param Boolean $raw Whether to catch exceptions or not
     * @param Response $entry A Response instance (the stale entry if present, null otherwise)
     *
     * @return Response A Response instance
     */
    protected function forward(Request $request, $raw = false, Response $entry = null)
    {
        /** @var $bootstrap \Shopware_Bootstrap */
        $bootstrap = $this->getKernel()->getApp()->Bootstrap();

        $bootstrap->registerResource('HttpCache', $this);
        $bootstrap->registerResource('Esi', $this->esi);

        return parent::forward($request, $raw, $entry);
    }
開發者ID:nhp,項目名稱:shopware-4,代碼行數:19,代碼來源:AppCache.php

示例8: forward

 /**
  * Forwards the Request to the backend and returns the Response.
  *
  * @param Request  $request A Request instance
  * @param Boolean  $raw     Whether to catch exceptions or not
  * @param Response $entry   A Response instance (the stale entry if present, null otherwise)
  *
  * @return Response A Response instance
  */
 protected function forward(Request $request, $raw = false, Response $entry = null)
 {
     $this->getKernel()->boot();
     $this->getKernel()->getContainer()->set('cache', $this);
     $this->getKernel()->getContainer()->set('esi', $this->getEsi());
     return parent::forward($request, $raw, $entry);
 }
開發者ID:netconstructor,項目名稱:symfony,代碼行數:16,代碼來源:HttpCache.php

示例9: handle

 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);
 }
開發者ID:margery,項目名稱:thelia,代碼行數:7,代碼來源:HttpCache.php

示例10: invalidate

 /**
  * {@inheritDoc}
  *
  * Adding the Events::PRE_INVALIDATE event.
  */
 protected function invalidate(Request $request, $catch = false)
 {
     if ($this->getEventDispatcher()->hasListeners(Events::PRE_INVALIDATE)) {
         $event = new CacheEvent($this, $request);
         $this->getEventDispatcher()->dispatch(Events::PRE_INVALIDATE, $event);
         if ($event->getResponse()) {
             return $event->getResponse();
         }
     }
     return parent::invalidate($request, $catch);
 }
開發者ID:stof,項目名稱:FOSHttpCache,代碼行數:16,代碼來源:EventDispatchingHttpCache.php


注:本文中的Symfony\Component\HttpKernel\HttpCache\HttpCache類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。