Beispiel #1
0
    $cacheKey = $params['request']->params['controller'] . 'Controller::' . $params['request']->params['action'];
    if (isset($response->varnish) && !empty($response->varnish)) {
        $cache = Varnish::cache($cacheKey, true);
        if (is_array($response->varnish)) {
            $cache += $response->varnish;
        }
    } else {
        $cache = Varnish::cache($cacheKey);
    }
    if (!empty($cache)) {
        $varnishHeaders = Varnish::headers($cache);
        foreach ($varnishHeaders as $key => $val) {
            $response->headers($key, $val);
        }
    }
    return $response;
});
// filter to set esi includes around partials
Media::applyFilter('view', function ($self, $params, $chain) {
    $view = $chain->next($self, $params, $chain);
    $view->applyFilter('_step', function ($self, $params, $chain) {
        $content = $chain->next($self, $params, $chain);
        if (isset($params['options']['esi']) && $params['options']['esi'] == true) {
            if (!empty($content)) {
                $content = \lithium\util\String::insert(Varnish::config('template'), array('url' => Router::match(array('controller' => 'Esi', 'action' => 'show', 'type' => $params['step']['path'], 'name' => $params['options']['template'])), 'content' => $content));
            }
        }
        return $content;
    });
    return $view;
});
Beispiel #2
0
<?php

/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2012, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */
/**
 * The routes file is where you define your URL structure, which is an important part of the
 * [information architecture](http://en.wikipedia.org/wiki/Information_architecture) of your
 * application. Here, you can use _routes_ to match up URL pattern strings to a set of parameters,
 * usually including a controller and action to dispatch matching requests to. For more information,
 * see the `Router` and `Route` classes.
 *
 * @see lithium\net\http\Router
 * @see lithium\net\http\Route
 */
use lithium\net\http\Router;
use lithium\core\Environment;
use li3_varnish\extensions\util\Varnish;
$url = trim(Varnish::config('esiUrl'), '/');
Router::connect('/' . $url . '/{:type}/{:name}', array('controller' => 'Esi', 'action' => 'show'));