예제 #1
0
<?php

use lithium\core\Libraries;
use lithium\core\ConfigException;
use lithium\template\View;
use lithium\net\http\Media;
// Define path to plugin and other constants
defined('LI3_HIERARCHY_PATH') or define('LI3_HIERARCHY_PATH', dirname(__DIR__));
/**
* Map to the new renderer
*/
Media::type('default', null, array('view' => '\\lithium\\template\\View', 'renderer' => '\\li3_hierarchy\\template\\view\\adapter\\Hierarchy', 'paths' => array('template' => array(LITHIUM_APP_PATH . '/views/{:controller}/{:template}.{:type}.php', '{:library}/views/{:controller}/{:template}.{:type}.php'), 'layout' => array(LITHIUM_APP_PATH . '/views/{:controller}/{:layout}.{:type}.php', '{:library}/views/{:controller}/{:layout}.{:type}.php'))));
Media::applyFilter('view', function ($self, $params, $chain) {
    if (isset($params['handler']['renderer']) && array_slice(explode('\\', $params['handler']['renderer']), -1, 1) == array('Hierarchy')) {
        $params['handler']['processes'] = array('all' => array('template'), 'template' => array('template'), 'element' => array('element'));
    }
    return $chain->next($self, $params, $chain);
});
예제 #2
0
파일: g11n.php 프로젝트: EHER/chegamos
//
// Inflector::rules('plural', array('rules' => array('/rata/' => '\1ratum')));
// Inflector::rules('plural', array('irregular' => array('bar' => 'foo')));
//
// Inflector::rules('transliteration', array('/É|Ê/' => 'E'));
//
// Inflector::rules('uninflected', 'bord');
// Inflector::rules('uninflected', array('bord', 'baird'));
/**
 * Integration with `View`. Embeds message translation aliases into the `View`
 * class (or other content handler, if specified) when content is rendered. This
 * enables translation functions, i.e. `<?=$t("Translated content"); ?>`.
 */
Media::applyFilter('_handle', function ($self, $params, $chain) {
    $params['handler'] += array('outputFilters' => array());
    $params['handler']['outputFilters'] += Message::aliases();
    return $chain->next($self, $params, $chain);
});
/**
 * Integration with `Validator`. You can load locale dependent rules into the `Validator`
 * by specifying them manually or retrieving them with the `Catalog` class.
 */
foreach (array('phone', 'postalCode', 'ssn') as $name) {
    Validator::add($name, Catalog::read(true, "validation.{$name}", 'en_US'));
}
/**
 * Intercepts dispatching processes in order to set the effective locale by using
 * the locale of the request or if that is not available retrieving a locale preferred
 * by the client.
 */
ActionDispatcher::applyFilter('_callable', function ($self, $params, $chain) {
예제 #3
0
<?php

use lithium\net\http\Media;
use li3_perf\extensions\util\Data;
// Apply a filter that will gather all the variables available to the view template.
Media::applyFilter('render', function ($self, $params, $chain) {
    $filter_start = microtime(true);
    $view_vars = array();
    foreach ($params['data'] as $k => $v) {
        if (is_object($v) && method_exists($v, 'data')) {
            $view_vars[$k] = $v->data();
        } else {
            $view_vars[$k] = $v;
        }
    }
    Data::append('view_vars', $view_vars);
    Data::append('timers', array('_filter_for_variables' => microtime(true) - $filter_start));
    return $chain->next($self, $params, $chain);
});
예제 #4
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;
});
예제 #5
0
 public static function initMedia()
 {
     // Response -> Handler
     Media::applyFilter('render', function ($self, $params, $chain) {
         if (isset($params['data']['info']['exception']) && $params['data']['info']['exception'] instanceof \Exception) {
             Debugger::setException($params['data']['info']['exception']);
         }
         $data = array();
         $data['start'] = microtime(true);
         $data['memory'] = memory_get_usage(true);
         $data['name'] = 'Media::render';
         $response = $chain->next($self, $params, $chain);
         $data['end'] = microtime(true);
         $data['memory'] = memory_get_usage(true) - $data['memory'];
         $data['time'] = $data['end'] - $data['start'];
         Debugger::push('events', $data);
         Debugger::inc('events.time', $data['time']);
         if ($response instanceof \lithium\action\Response) {
             Debugger::setResponse($response);
         }
         return $response;
     });
     // Handler -> string
     Media::applyFilter('_handle', function ($self, $params, $chain) {
         if ($params['handler']['type'] === 'html') {
             Debugger::setView($self, $params['handler'], $params['response']);
         }
         $data = array();
         $data['start'] = microtime(true);
         $data['memory'] = memory_get_usage(true);
         $data['name'] = 'Media::_handle';
         $result = $chain->next($self, $params, $chain);
         $data['end'] = microtime(true);
         $data['memory'] = memory_get_usage(true) - $data['memory'];
         $data['time'] = $data['end'] - $data['start'];
         Debugger::push('events', $data);
         Debugger::inc('events.time', $data['time']);
         return $result;
     });
 }
예제 #6
0
<?php

use lithium\action\Dispatcher;
use lithium\net\http\Media;
/**
 * This filter overrides the default `json` media type, only if the response type is `json`.
 * This allows to build custom `json` responses by rendering a template.
 */
Media::applyFilter('render', function ($self, $params, $chain) {
    if ($params['response']->type() === 'json') {
        $params['options'] += array('view' => 'lithium\\template\\View', 'paths' => array('layout' => false, 'template' => '{:library}/views/{:controller}/{:template}.json.php', 'element' => '{:library}/views/elements/{:template}.json.php'), 'cast' => false, 'encode' => false, 'decode' => false);
    }
    return $chain->next($self, $params, $chain);
});
예제 #7
0
 * This file contains configuration for session (and/or cookie) storage, and user or web service
 * authentication.
 */
// require __DIR__ . '/bootstrap/session.php';
/**
 * This file contains your application's globalization rules, including inflections,
 * transliterations, localized validation, and how localized text should be loaded. Uncomment this
 * line if you plan to globalize your site.
 */
date_default_timezone_set('UTC');
// require __DIR__ . '/bootstrap/g11n.php';
/**
 * This file contains configurations for handling different content types within the framework,
 * including converting data to and from different formats, and handling static media assets.
 */
require __DIR__ . '/bootstrap/media.php';
/**
 * This file configures console filters and settings, specifically output behavior and coloring.
 */
if (PHP_SAPI === 'cli') {
    require __DIR__ . '/bootstrap/console.php';
}
require __DIR__ . '/bootstrap/environment.php';
use lithium\net\http\Media;
use app\models\Testimonials;
Media::applyFilter('_handle', function ($self, $params, $chain) {
    if ($params['handler']['type'] == 'html') {
        $params['data']['testimonial'] = Testimonials::random();
    }
    return $chain->next($self, $params, $chain);
});