public static function render($print = false) { Benchmark::start(self::$benchmark_name); $template = new View('toolbar'); if (Kohana::config('debug_toolbar.panels.database')) { $template->set('queries', self::queries()); } if (Kohana::config('debug_toolbar.panels.logs')) { $template->set('logs', self::logs()); } if (Kohana::config('debug_toolbar.panels.vars_and_config')) { $template->set('configs', self::configs()); } if (Kohana::config('debug_toolbar.panels.files')) { $template->set('files', self::files()); } if (Kohana::config('debug_toolbar.firephp_enabled')) { self::firephp(); } switch (Kohana::config('debug_toolbar.align')) { case 'right': case 'center': case 'left': $template->set('align', Kohana::config('debug_toolbar.align')); break; default: $template->set('align', 'left'); } $template->set('scripts', file_get_contents(Kohana::find_file('views', 'toolbar', true, 'js'))); Benchmark::stop(self::$benchmark_name); if (Kohana::config('debug_toolbar.panels.benchmarks')) { $template->set('benchmarks', self::benchmarks()); } if (Event::$data) { if (Kohana::config('debug_toolbar.auto_render') or Kohana::config('debug_toolbar.secret_key') !== FALSE and isset($_GET[Kohana::config('debug_toolbar.secret_key')])) { // try to add css to <head>, otherwise, send to template $styles = file_get_contents(Kohana::find_file('views', 'toolbar', false, 'css')); if (stripos(Event::$data, '</head>') !== FALSE) { Event::$data = str_ireplace('</head>', $styles . '</head>', Event::$data); } else { $template->set('styles', $styles); } // try to add js and HTML just before the </body> tag, // otherwise just append it to the output if (stripos(Event::$data, '</body>') !== FALSE) { Event::$data = str_ireplace('</body>', $template->render() . '</body>', Event::$data); } else { Event::$data .= $template->render(); } } } else { if ($print) { $template->render(TRUE); } else { return $template->render(); } } }
public function execute($input_parameters = null) { try { $this->benchmark->start(); return parent::execute($input_parameters); } finally { $this->benchmark->end(); } }
public function testBenchmarkObjectMethod() { Benchmark::__reset(); $b = Benchmark::start($this, __METHOD__); $this->assertEqual($b->get_benchmark_class(), "TestBenchmark", "La classe del benchmark non corrisponde"); $this->assertEqual($b->get_benchmark_method(), "testBenchmarkObjectMethod", "Il metodo del benchmark non corrisponde"); $this->assertEqual($b->get_benchmark_signature(), "TestBenchmark@testBenchmarkObjectMethod"); $this->assertFalse($b->is_finished(), "Il benchmark risulta terminato!"); Benchmark::stop(); $this->assertTrue($b->is_finished(), "Il benchmark non risulta terminato!"); }
public function add_as_author_of(User_Model $author, ORM $object) { if ($this->is_possible_to_add_authors_to($object)) { Benchmark::start('add_as_author_of'); try { $database = new Database(); $database->from('workshop_data'); $database->set(array('object_name' => $object->object_name, 'user_id' => $author->id, 'object_id' => $object->id)); $database->insert(); } catch (Kohana_Database_Exception $e) { if (strstr($e->getMessage(), 'Duplicate entry')) { throw new Workshop_Duplicate_Author_Exception($author, $object); } else { throw $e; } } Benchmark::stop('add_as_author_of'); } else { throw new Workshop_Max_Limit_Exception($object, $this->get_number_of_authors_of($object), 1, $this->config_delegate->max_authors_for($object)); } }
} } } // Set default controller and action define('DEFAULT_CONTROLLER', $route['_default']); define('DEFAULT_ACTION', 'index'); // Load core files require SYSPATH . '/core/Model' . EXT; require SYSPATH . '/core/View' . EXT; require SYSPATH . '/core/Controller' . EXT; require SYSPATH . '/helpers/Inflector' . EXT; require SYSPATH . '/core/Benchmark' . EXT; require SYSPATH . '/core/Observer' . EXT; require SYSPATH . '/core/Autoloader' . EXT; require SYSPATH . '/core/Simplengine' . EXT; Benchmark::start('total'); // Set view suffix define('VIEW_SUFFIX', $config['view_suffix']); // Set base url define('BASE_URL', $config['base_url']); if (isset($config[$db_group]['host'])) { // Database setup define('DB_DSN', $db_driver . ':dbname=' . $config[$db_group]['database'] . ';host=' . $config[$db_group]['host']); define('DB_USER', $config[$db_group]['username']); define('DB_PASS', $config[$db_group]['password']); define('TABLE_PREFIX', $config[$db_group]['prefix']); define('USE_PDO', $config[$db_group]['pdo']); if (USE_PDO) { try { $__SE_CONN__ = new PDO(DB_DSN, DB_USER, DB_PASS); } catch (PDOException $error) {
private function echo_formatted_data($data, $datatype) { Benchmark::start('echo_formatted_data'); switch (strtolower($datatype)) { case 'json': header('Content-type: application/json'); $json = json_encode($data); $callback = $this->input->get('jsonp_callback'); if ($callback) { echo $callback . '(' . $json . ');'; } else { echo $json; } break; case 'xml': header('Content-type: application/xml'); $xml = '<?xml version="1.0" encoding="UTF-8"?><result></result>'; $xml = simplexml_load_string($xml); $this->create_xml_object($xml, $data); $dom = new DOMDocument('1.0'); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->loadXML($xml->asXML()); echo $dom->saveXML(); break; case 'csv': header('Content-type: text/csv'); $outstream = fopen("php://output", 'w'); if (!isset($data[0])) { $data = current($data); } $firstElm = current($data); if (!isset($firstElm[0])) { fputcsv($outstream, array_keys(get_object_vars(current(current($data)))), ',', '"'); } else { fputcsv($outstream, array_keys(get_object_vars(current($data))), ',', '"'); } function __outputCSV(&$vals, $key, $filehandler) { if (!isset($vals[0])) { fputcsv($filehandler, get_object_vars(current($vals)), ',', '"'); } else { fputcsv($filehandler, get_object_vars($vals), ',', '"'); } } array_walk($data, '__outputCSV', $outstream); fclose($outstream); break; default: throw new Kohana_404_Exception(); break; } Benchmark::stop('echo_formatted_data'); }
/** * Initializes all necessary FLOWLite objects * * @see run() */ public function initialize() { $this->initializeApplication(); $this->initializeSystem(); $this->initializeClassLoader(); $this->initializeFrameworkNamespace(); Benchmark::start('SYS'); $this->initializeExceptions(); $this->initializeErrorHandling(); $this->initializeObjectManager(); $this->initializeConfiguration(); $this->initializeRegistry(); $this->initializeSession(); $this->initializeProtocol(); $this->initializeLocale(); $this->initializeTrace(); $this->initializeRepeater(); # $this->initializeSecurity(); $this->initializeNamespace(); #Benchmark::stop('Dev'); #echo "DEV "; #BaseHelperMessage::showMessage(Benchmark::getBenchmarkTime('Dev'),array(BaseHelperEscapeChars::getEscapeChar('BR'))); #Benchmark::start('NSP'); #Benchmark::stop('SYS'); #echo "SYS "; #BaseHelperMessage::showMessage(Benchmark::getBenchmarkTime('SYS'),array(BaseHelperEscapeChars::getEscapeChar('BR'))); #Benchmark::start('SYS'); #Benchmark::stop('SYS'); #echo "SYS "; #BaseHelperMessage::showMessage(Benchmark::getBenchmarkTime('SYS'),array(BaseHelperEscapeChars::getEscapeChar('BR'))); #Benchmark::stop('SYS'); #echo "SYS "; #BaseHelperMessage::showMessage(Benchmark::getBenchmarkTime('SYS'),array(BaseHelperEscapeChars::getEscapeChar('BR'))); #Benchmark::stop('NSP'); #echo "NSP "; #BaseHelperMessage::showMessage(Benchmark::getBenchmarkTime('NSP'),array(BaseHelperEscapeChars::getEscapeChar('BR'))); #Benchmark::start('SYS'); $this->initializeCache(); $this->initializeORM(); $this->initializeDatabase(); $this->initializeShutdown(); #Benchmark::stop('SYS'); #echo "SYS "; #BaseHelperMessage::showMessage(Benchmark::getBenchmarkTime('SYS'),array(BaseHelperEscapeChars::getEscapeChar('BR'))); }
/** * Parse the CSS * * @return string - The processes css file as a string * @author Anthony Short **/ public static function parse_css() { # If the cache is stale or doesn't exist if (self::config('core.cache.mod_time') <= self::config('core.request.mod_time')) { # Start the timer Benchmark::start("parse_css"); # Compress it before parsing CSS::compress(CSS::$css); # Import CSS files Import::parse(); if (self::config('core.auto_include_mixins') === true) { # Import the mixins in the plugin/module folders Mixins::import_mixins('framework/mixins'); } # Parse our css through the plugins foreach (self::$plugins as $plugin) { call_user_func(array($plugin, 'import_process')); } # Compress it before parsing CSS::compress(CSS::$css); # Parse the constants Constants::parse(); foreach (self::$plugins as $plugin) { call_user_func(array($plugin, 'pre_process')); } # Parse the @grid Layout::parse_grid(); # Replace the constants Constants::replace(); # Parse @for loops Iteration::parse(); foreach (self::$plugins as $plugin) { call_user_func(array($plugin, 'process')); } # Compress it before parsing CSS::compress(CSS::$css); # Parse the mixins Mixins::parse(); # Find missing constants Constants::replace(); # Compress it before parsing CSS::compress(CSS::$css); foreach (self::$plugins as $plugin) { call_user_func(array($plugin, 'post_process')); } # Parse the expressions Expression::parse(); # Parse the nested selectors NestedSelectors::parse(); # Convert all url()'s to absolute paths if required if (self::config('core.absolute_urls') === true) { CSS::convert_to_absolute_urls(); } # Replaces url()'s that start with ~ to lead to the CSS directory CSS::replace_css_urls(); # Add the extra string we've been storing CSS::$css .= CSS::$append; # If they want to minify it if (self::config('core.minify_css') === true) { Minify::compress(); } else { CSS::pretty(); } # Formatting hook foreach (self::$plugins as $plugin) { call_user_func(array($plugin, 'formatting_process')); } # Validate the CSS if (self::config('core.validate') === true) { Validate::check(); } # Stop the timer... Benchmark::stop("parse_css"); if (self::config('core.show_header') === TRUE) { CSS::$css = "/* Processed by CSScaffold on " . gmdate('r') . " in " . Benchmark::get("parse_css", "time") . " seconds */\n\n" . CSS::$css; } # Write the css file to the cache self::cache_write(CSS::$css); # Output process hook for plugins to display views. # Doesn't run in production mode. if (!IN_PRODUCTION) { foreach (array_merge(self::$plugins, self::$modules) as $plugin) { call_user_func(array($plugin, 'output')); } } } }
$sql = "INSERT INTO posts (category_id, title, contents) VALUES (0, '%s', '%s')"; for ($i = 0; $i < 5000; $i++) { $r = mt_rand(0, 2); $db->query(sprintf($sql, $records[$r]->title, $records[$r]->contents)); } } if (isset($_SERVER['argv'][1]) and $_SERVER['argv'][1] == 'fill') { echo 'Generating test data.' . PHP_EOL; for ($i = 0; $i < 10; $i++) { fill_db(); echo ($i + 1) * 5000 . ' records generated.' . PHP_EOL; } exit; } Benchmark::start('select records'); $records = $db->query('SELECT id, title, contents FROM posts')->fetchAll(PDO::FETCH_OBJ); Benchmark::stop('select records'); Benchmark::start('index'); $data = array('title' => 'Craiglist ads', 'records' => $records); $index = parse('index.tpl', $data); create('index', $index); Benchmark::stop('index'); Benchmark::start('pages'); foreach ($records as $page) { $data = array('page' => $page); $content = parse('page.tpl', $data); create($page->id, $content); } Benchmark::stop('pages'); Benchmark::stop('page'); var_dump(Benchmark::get(TRUE));
<?php $time = array(); $mem = array(); include 'Benchmark.php'; $benchmark = new Benchmark(); if (!empty($_POST)) { ob_start(); foreach ($_POST['code'] as $code) { for ($n = 0; $n < $_POST['iterations']; $n++) { $benchmark->start(); eval($code); $benchmark->finish(); } $time[] = $benchmark->get_time(); $mem[] = $benchmark->get_memory(); $benchmark->flush(); } ob_end_clean(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PHP Benchmark</title> <style type="text/css"> * { margin:0; padding:0; } body { font:90% Arial, Helvetica, sans-serif; padding:2em; } form textarea, form input { font-family:"Courier New", Courier, monospace; } .block { float:left; }
/** * Renders the Debug Toolbar * * @param bool print rendered output * @return string debug toolbar rendered output */ public static function render($print = false) { Benchmark::start(self::$benchmark_name); $template = new View('toolbar'); // Database panel if (Kohana::config('debug_toolbar.panels.database') === TRUE) { $template->set('queries', self::get_queries()); } // Logs panel if (Kohana::config('debug_toolbar.panels.logs') === TRUE) { $template->set('logs', self::get_logs()); } // Vars and Config panel if (Kohana::config('debug_toolbar.panels.vars_and_config') === TRUE) { $template->set('configs', self::get_configs()); } // Files panel if (Kohana::config('debug_toolbar.panels.files') === TRUE) { $template->set('files', self::get_files()); } // FirePHP if (Kohana::config('debug_toolbar.firephp_enabled') === TRUE) { self::firephp(); } // Set alignment for toolbar switch (Kohana::config('debug_toolbar.align')) { case 'right': case 'center': case 'left': $template->set('align', Kohana::config('debug_toolbar.align')); break; default: $template->set('align', 'left'); } // Javascript for toolbar $template->set('scripts', file_get_contents(Kohana::find_file('views', 'toolbar', TRUE, 'js'))); // CSS for toolbar $styles = file_get_contents(Kohana::find_file('views', 'toolbar', FALSE, 'css')); Benchmark::stop(self::$benchmark_name); // Benchmarks panel if (Kohana::config('debug_toolbar.panels.benchmarks') === TRUE) { $template->set('benchmarks', self::get_benchmarks()); } if (Event::$data and self::is_enabled()) { // Try to add css just before the </head> tag if (stripos(Event::$data, '</head>') !== FALSE) { Event::$data = str_ireplace('</head>', $styles . '</head>', Event::$data); } else { // No </head> tag found, append styles to output $template->set('styles', $styles); } // Try to add js and HTML just before the </body> tag if (stripos(Event::$data, '</body>') !== FALSE) { Event::$data = str_ireplace('</body>', $template->render() . '</body>', Event::$data); } else { // Closing <body> tag not found, just append toolbar to output Event::$data .= $template->render(); } } else { $template->set('styles', $styles); return $template->render($print); } }
public static function executeAction($controller, $action, $params) { $controller_class = Inflector::camelize($controller); $controller_class_name = $controller_class . 'Controller'; // get a instance of that controller if (class_exists($controller_class_name)) { $controller = new $controller_class_name(); } if (!$controller instanceof Controller) { throw new Exception("Class '{$controller_class_name}' does not extends Controller class!"); } Observer::notify('system.execute'); Benchmark::start('execute'); // execute the action $controller->execute($action, $params); }
is_link(KOHANA) and chdir(dirname(realpath(__FILE__))); $kohana_application = file_exists($kohana_application) ? $kohana_application : DOCROOT . $kohana_application; $kohana_modules = file_exists($kohana_modules) ? $kohana_modules : DOCROOT . $kohana_modules; $kohana_system = file_exists($kohana_system) ? $kohana_system : DOCROOT . $kohana_system; define('APPPATH', str_replace('\\', '/', realpath($kohana_application)) . '/'); define('MODPATH', str_replace('\\', '/', realpath($kohana_modules)) . '/'); define('SYSPATH', str_replace('\\', '/', realpath($kohana_system)) . '/'); unset($kohana_application, $kohana_modules, $kohana_system); //From Bootstrap.php define('KOHANA_VERSION', '2.3.4'); define('KOHANA_CODENAME', 'buteo regalis'); define('KOHANA_IS_WIN', DIRECTORY_SEPARATOR === '\\'); define('SYSTEM_BENCHMARK', 'system_benchmark'); require SYSPATH . 'core/Benchmark' . EXT; Benchmark::start(SYSTEM_BENCHMARK . '_total_execution'); Benchmark::start(SYSTEM_BENCHMARK . '_kohana_loading'); require SYSPATH . 'core/utf8' . EXT; require SYSPATH . 'core/Event' . EXT; require SYSPATH . 'core/Kohana' . EXT; Kohana::setup(); //Extras restore_error_handler(); restore_exception_handler(); class Console extends Controller { var $template = 'kohana_error_disabled'; public static function debug($message = NULL) { echo $message . "\n"; } }
<?php // Start Benchmark include 'class/benchmark.php'; Benchmark::start('Load Time'); $app->add_event('after_render_layout', 'show_load_time'); function show_load_time($layout) { $layout .= '<style type="text/css"> div.cms_debug{ background-color: white; position: fixed; bottom:0; -moz-box-shadow:0 -1px 4px #000; box-shadow:0 -1px 4px #000; -webkit-box-shadow:0 -1px 4px #000; padding: 2px 4px 0 4px; left:10px; opacity:0.3; } div.cms_debug:hover{ opacity:1; } </style>'; Benchmark::stop('Load Time'); $layout .= '<div class="cms_debug">'; foreach (Benchmark::get_totals() as $total) { $layout .= $total . '<br>'; } $layout .= '</div>'; }
private function echo_formatted_data($data, $datatype) { Benchmark::start('echo_formatted_data'); switch (strtolower($datatype)) { case 'json': header('Content-type: application/json'); $json = json_encode($data); $callback = $this->input->get('jsonp_callback'); if ($callback) { echo $callback . '(' . $json . ');'; } else { echo $json; } break; case 'xml': header('Content-type: application/xml'); $xml = '<?xml version="1.0" encoding="UTF-8"?><result></result>'; $xml = simplexml_load_string($xml); $this->create_xml_object($xml, $data); $dom = new DOMDocument('1.0'); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->loadXML($xml->asXML()); echo $dom->saveXML(); break; default: throw new Kohana_404_Exception(); break; } Benchmark::stop('echo_formatted_data'); }
define('KOHANA_CODENAME', 'efímera'); // Test of Kohana is running in Windows define('KOHANA_IS_WIN', PHP_SHLIB_SUFFIX === 'dll'); // Kohana benchmarks are prefixed to prevent collisions define('SYSTEM_BENCHMARK', 'system_benchmark'); // Load benchmarking support require SYSPATH . 'core/Benchmark' . EXT; // Start total_execution Benchmark::start(SYSTEM_BENCHMARK . '_total_execution'); // Start kohana_loading Benchmark::start(SYSTEM_BENCHMARK . '_kohana_loading'); // Load core files require SYSPATH . 'core/utf8' . EXT; require SYSPATH . 'core/Event' . EXT; require SYSPATH . 'core/Kohana' . EXT; // Prepare the environment Kohana::setup(); // End kohana_loading Benchmark::stop(SYSTEM_BENCHMARK . '_kohana_loading'); // Start system_initialization Benchmark::start(SYSTEM_BENCHMARK . '_system_initialization'); // Prepare the system Event::run('system.ready'); // Determine routing Event::run('system.routing'); // End system_initialization Benchmark::stop(SYSTEM_BENCHMARK . '_system_initialization'); // Make the magic happen! Event::run('system.execute'); // Clean up and exit Event::run('system.shutdown');
/** * request to load controller */ static function action() { // benchmark $benchmark = new Benchmark(); $benchmark->start(); $request = new Request(); $request->setBaseUri(Application::getBaseUrl()); // auth checkc if (self::$auth) { foreach (self::$auth as $auth) { $auth->check($request->getUri()); } } $routing = new Routing(); if (!($data = $routing::getRouleClass($request->getUri()))) { if ($data = $routing::getRouleClass($request->getUri() . '/')) { Server::redirect(Application::getBaseUrl() . $request->getUri() . '/'); } } if (empty($data)) { $data = array('class' => 'core:default:error_404'); } else { if ($data['class'] == '') { $data = array('class' => 'core:default:index'); } } // pearse class method if (preg_match("/^([0-9a-zA-Z\\-_]+):([0-9a-zA-Z\\-_]+):?([0-9a-zA-Z\\-_]*)\$/", $data['class'], $matchs)) { $project = $matchs[1]; $class = $matchs[2]; $method = $matchs[3]; $method = !empty($method) ? $method : "index"; } else { throw new PMPException('Error Class Method or Class Name(`' . $data['class'] . '` is not routing find).'); } $benchmark->setMark("routing"); try { $path = self::$source_dir . '/' . $project; $filename = $path . '/conf'; dir_include_all($filename); $filename = $path . '/class'; dir_include_all($filename); $filename = $path . '/controller/' . $class . '.php'; if (file_exists($filename)) { include_once $filename; } else { $path = dirname(__FILE__) . '/../../component'; $filename = $path . '/controller/' . $class . '.php'; if (file_exists($filename)) { include_once $filename; } } $classname = $class . 'Controller'; $controller = new $classname($path, $class, $method, $project); $controller->addDefaultTemplatefiles(dirname(__FILE__) . '/../../component/view/form.tpl'); $benchmark->setMark('included'); if (isset($data['param'])) { $reflection = new \ReflectionClass($controller); $reflection_method = $reflection->getMethod($method); $params = array(); foreach ($reflection_method->getParameters() as $key => $p) { if (array_key_exists($p->getName(), $data['param'])) { $params[$key] = $data['param'][$p->getName()]; } else { if ($p->isDefaultValueAvailable()) { $params[$key] = $p->getDefaultValue(); } else { throw new PMPException(sprintf('Not Found Controller Paramater %s In %s', get_class($controller) . ':' . $method, $p->getName())); } } } call_user_func_array(array($controller, $method), $params); } else { $controller->{$method}(); } $benchmark->setMark("action"); $benchmark->stop(); //$benchmark->display(false); } catch (\Exception $e) { throw new PMPException($e); } }
/** * Constructor * * Sets template path * * @param string $template_path Path to Grid templates, default: null * * @return none * @access public * * @author Thorsten Schmidt * @date 10.08.2009 * @version 1.0 * @since 1.0 */ public function __construct($template_path = null) { Benchmark::start('GridModule Loading'); if ($template_path) { $this->template_path = $template_path; } Kohana::log('debug', 'Grid :: Grid_Core Module loaded'); }
/** * Loads the controller and initializes it. Runs the pre_controller, * post_controller_constructor, and post_controller events. Triggers * a system.404 event when the route cannot be mapped to a controller. * * This method is benchmarked as controller_setup and controller_execution. * * @return object instance of controller */ public static function &instance() { if (self::$instance === nil) { // Routing has been completed Event::run('system.post_routing'); Benchmark::start(SYSTEM_BENCHMARK . '_controller_setup'); // Log the current routing state for debugging purposes Eight::log('debug', 'Routing "' . Router::$current_uri . '" using the "' . Router::$current_route . '" route, ' . Router::$controller . '::' . Router::$method); try { // Start validation of the controller $class = new ReflectionClass('Controller_' . ucfirst(Router::$controller)); } catch (ReflectionException $e) { // Controller does not exist Event::run('system.404'); } if ($class->isAbstract() or IN_PRODUCTION and $class->getConstant('ALLOW_PRODUCTION') == FALSE) { // Controller is not allowed to run in production Event::run('system.404'); } // Run system.pre_controller Event::run('system.pre_controller'); // Create a new controller instance $controller = $class->newInstance(); // Controller constructor has been executed Event::run('system.post_controller_constructor'); try { // Load the controller method $method = $class->getMethod(Router::$method); // Method exists if (Router::$method[0] === '_') { // Do not allow access to hidden methods Event::run('system.404'); } if ($method->isProtected() or $method->isPrivate()) { // Do not attempt to invoke protected or private methods throw new ReflectionException('protected controller method'); } // Default arguments $arguments = Router::$arguments; } catch (ReflectionException $e) { // Use __call instead $method = $class->getMethod('__call'); // Use arguments in __call format $arguments = array(Router::$method, Router::$arguments); } // Stop the controller setup benchmark Benchmark::stop(SYSTEM_BENCHMARK . '_controller_setup'); // Start the controller execution benchmark Benchmark::start(SYSTEM_BENCHMARK . '_controller_execution'); // We MAY want to prevent a method from running sometimes if (Eight::$run_method) { // Execute the controller method $method->invokeArgs($controller, $arguments); } // Controller method has been executed Event::run('system.post_controller'); // Stop the controller execution benchmark Benchmark::stop(SYSTEM_BENCHMARK . '_controller_execution'); } return Eight::$instance; }
/** * Loads the controller and initializes it. Runs the pre_controller, * post_controller_constructor, and post_controller events. Triggers * a system.404 event when the route cannot be mapped to a controller. * * This method is benchmarked as controller_setup and controller_execution. * * @return object instance of controller */ public static function &instance() { if (self::$instance === NULL) { Benchmark::start(SYSTEM_BENCHMARK . '_controller_setup'); if (Router::$method[0] === '_') { // Do not allow access to hidden methods Event::run('system.404'); } // Include the Controller file require Router::$controller_path; try { // Start validation of the controller $class = new ReflectionClass(ucfirst(Router::$controller) . '_Controller'); } catch (ReflectionException $e) { // Controller does not exist Event::run('system.404'); } if ($class->isAbstract() or IN_PRODUCTION and $class->getConstant('ALLOW_PRODUCTION') == FALSE) { // Controller is not allowed to run in production Event::run('system.404'); } // Run system.pre_controller Event::run('system.pre_controller'); // Begin benchmark for the controller Benchmark::f_start(ucfirst(Router::$controller) . '_Controller'); // Create a new controller instance $controller = $class->newInstance(); // End benchmark for the controller Benchmark::f_stop(ucfirst(Router::$controller) . '_Controller'); // Controller constructor has been executed Event::run('system.post_controller_constructor'); try { // Load the controller method $method = $class->getMethod(Router::$method); if ($method->isProtected() or $method->isPrivate()) { // Do not attempt to invoke protected methods throw new ReflectionException('protected controller method'); } // Default arguments $arguments = Router::$arguments; } catch (ReflectionException $e) { // Use __call instead $method = $class->getMethod('__call'); // Use arguments in __call format $arguments = array(Router::$method, Router::$arguments); } // Stop the controller setup benchmark Benchmark::stop(SYSTEM_BENCHMARK . '_controller_setup'); // Start the controller execution benchmark Benchmark::start(SYSTEM_BENCHMARK . '_controller_execution'); // Execute the controller method $method->invokeArgs($controller, $arguments); // Controller method has been executed Event::run('system.post_controller'); // Stop the controller execution benchmark Benchmark::stop(SYSTEM_BENCHMARK . '_controller_execution'); } return self::$instance; }
public function partials() { $data = $this->templateData(); Benchmark::start('grid'); $grid = DataGrid_Factory::create('test'); $grid->table->border = 1; for ($column = 1; $column <= count($data['head']); $column++) { $grid->addField('key' . $column, 'Header ' . $column); } $grid->addColumn('static data', 'Static Head'); $template = $grid->render('partials'); $this->view->template = $template['template']; Benchmark::stop('grid'); $benchmark = Benchmark::get('grid'); $this->view->time = $benchmark['time']; $this->view->partials = json_encode($template['partials']); $this->view->data = json_encode($this->templateData()); }