コード例 #1
0
ファイル: variables.php プロジェクト: tmaiaroto/li3_perf
<?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);
});
コード例 #2
0
ファイル: dispatcher.php プロジェクト: tmaiaroto/li3_perf
    // The next time we'll be working with the same response is under the next filter below on
    // run() AFTER $result = $chain->next() is called... That's the end of the dispatch cycle.
    // The $result = part below is actually before this filter and the filter on _callable() above.
    Data::append('timers', array('li3_perf_end_call' => microtime(true)));
    return $result;
});
// Apply a filter that will render the toolbar and mark some timers.
Dispatcher::applyFilter('run', function ($self, $params, $chain) {
    if (substr($params['request']->url, 0, 17) == '/li3_perf/profile') {
        return $chain->next($self, $params, $chain);
    }
    Data::append('timers', array('li3_perf_start_dispatch' => microtime(true)));
    $result = $chain->next($self, $params, $chain);
    // Mark the end of li3_perf.
    // Note: The time it takes to render the toolbar will not be included.
    Data::append('timers', array('li3_perf_end' => microtime(true)));
    // Render the toolbar (unless it's an asset from the li3_perf library)
    // Why? See li3_perf\extensions\util\Asset
    $content_type = isset($result->headers['Content-Type']) ? $result->headers['Content-Type'] : '';
    $content_type = explode(';', $content_type, 2);
    $content_type = array_shift($content_type);
    if (!isset($params['request']->params['asset_type']) && (!$content_type || $content_type == 'text/html')) {
        $skip = false;
        $li3_perf = Libraries::get('li3_perf');
        if (isset($li3_perf['skip'])) {
            $controller = isset($params['request']->params['controller']) ? $params['request']->params['controller'] : null;
            $action = isset($params['request']->params['action']) ? $params['request']->params['action'] : null;
            $library = isset($params['request']->params['library']) ? $params['request']->params['library'] : null;
            // Check to see if the toolbar should be shown for this library
            if (isset($li3_perf['skip']['library'])) {
                if (in_array($library, $li3_perf['skip']['library'])) {