/** * The Autoloader initialisation * * @return void */ public static function _init() { // is the profiler enabled? if (!(static::$_enabled = ClanCats::$config->get('profiler.enabled'))) { return; } // enable profiling only in development mode if (ClanCats::in_development()) { // add a hook to the resposne so that we can // append a table with the profiler data to the body CCEvent::mind('response.output', function ($output) { if (strpos($output, '</body>') === false) { return $output; } $table = \UI\Table::create(array('style' => array('width' => '100%'), 'cellpadding' => '5', 'class' => 'table debug-table debug-table-profiler')); $table->header(array('#', 'message', 'memory', 'time')); foreach (\CCProfiler::data() as $key => $item) { $table->row(array($key + 1, $item[0], $item[1], $item[2])); } // add the table before the body end return str_replace('</body>', $table . "\n</body>", $output); }); // also add an error inspector hook so that we can access the // profiler data in the error handler CCError_Inspector::info_callback('Profiler', function () { $table = array(); foreach (\CCProfiler::data() as $key => $check) { $table['#' . ($key + 1) . ': ' . $check[2]] = $check[0]; } return $table; }); } }
/** * trigger the handler * * @return void */ public function handle() { $this->log(); // when not in development we respond using a route if (!ClanCats::in_development() && !ClanCats::is_cli()) { CCResponse::error(500)->send(true); } else { $this->respond(); } }
/** * initialize the ship * * @return void */ public function wake() { if (!\ClanCats::in_development()) { return; } // get all controllers in the dev namespace foreach (\CCFile::ls(\CCPath::controllers('Dev::*Controller' . EXT)) as $path) { $name = \CCStr::cut(basename($path), 'Controller' . EXT); \CCRouter::on('dev/' . \CCStr::lower($name), 'Dev::' . $name); } }
/** * error class init * * @return void */ public static function _init() { // we capture non fatal errors only in dev environments if (ClanCats::in_development()) { // add a hook to the main resposne CCEvent::mind('response.output', function ($output) { if (strpos($output, '</body>') === false) { return $output; } $table = \UI\Table::create(array('style' => array('width' => '100%'), 'cellpadding' => '5', 'class' => 'table debug-table debug-table-errors')); $table->header(array('#', 'message', 'file')); foreach (\CCError::$non_fatals as $key => $item) { $table->row(array($key + 1, $item->getMessage(), CCStr::strip($item->getFile(), CCROOT) . ':' . $item->getLine())); } return str_replace('</body>', $table . "\n</body>", $output); }); } }
/** * print information about this application * * @param array $params */ public function action_info($params) { $app = \ClanCats::runtime(); // print the app name $this->line(\CCForge_Php::make('comment', $app::$name . PHP_EOL . "*" . PHP_EOL . "Running on ClanCatsFramework " . \ClanCats::VERSION . PHP_EOL . "© 2010 - " . date('Y') . " ClanCats GmbH" . PHP_EOL), 'cyan'); // list printer $list = function ($array) { foreach ($array as $key => $value) { $this->line($key . ': ' . CCCli::color($value, 'green')); } }; // print info $list(array('Runtime Class' => $app, 'CCF Version' => \ClanCats::version(), 'CCF Environment' => \ClanCats::environment(), 'Development env' => var_export(\ClanCats::in_development(), true), 'File extention' => EXT, 'Core namespace' => CCCORE_NAMESPACE)); // paths $this->line(PHP_EOL . "Paths", 'cyan'); $list(\ClanCats::paths()); // paths $this->line(PHP_EOL . "Directories", 'cyan'); $list(\ClanCats::directories()); // autoloader $this->line(PHP_EOL . "Autoloader - namespaces", 'cyan'); $list(\CCFinder::$namespaces); }
/** * Test CC development */ public function testIn_development() { $this->assertTrue(\ClanCats::in_development()); }
/** * start the ccf lifecycle * * this method sets the current environment, loads the configuration * and wakes the application * * @param string $environment * @return void */ public static function wake($environment) { if (!is_null(static::$environment)) { throw new CCException("ClanCats::wake - you cannot wake the application twice."); } // set environment static::$environment = $environment; // load the main configuration static::$config = CCConfig::create('main'); // setup the application error tables CCError_Inspector::info_callback('ClanCatsFramework', function () { return array('Runtime Class' => \ClanCats::runtime(), 'CCF Version' => \ClanCats::version(), 'CCF Environment' => \ClanCats::environment(), 'Development env' => var_export(\ClanCats::in_development(), true), 'File extention' => EXT, 'Core namespace' => CCCORE_NAMESPACE); }); CCError_Inspector::info_callback('CCF Paths', array('ClanCats', 'paths')); CCError_Inspector::info_callback('CCF Directories', array('ClanCats', 'directories')); CCError_Inspector::info_callback('Namespaces', function () { return \CCFinder::$namespaces; }); }
echo to('@auth.sign_in'); ?> ">Sign In</a> </li> <li> <a href="<?php echo to('@auth.sign_up'); ?> ">Sign Up</a> </li> <?php } ?> <?php if (ClanCats::in_development()) { ?> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dev Toolbox <b class="caret"></b></a> <ul class="dropdown-menu"> <li><a href="<?php echo to('dev/session/'); ?> ">Session Sandbox</a></li> <li><a href="<?php echo to('dev/mail/'); ?> ">Mail Sandbox</a></li> <li><a href="<?php echo to('dev/common/phpinfo'); ?>
/** * Run the query and return the PDO statement * * @param string $query * @param array $params * @return array */ public function statement($query, $params = array()) { // we alway prepare the query even if we dont have parameters $sth = $this->driver()->connection()->prepare($query); // because we set pdo the throw exception on db errors // we catch them here to throw our own exception. try { $sth->execute($params); } catch (\PDOException $e) { throw new Exception("DB\\Handler - PDOException: {$e->getMessage()} \n Query: {$query}"); } // In development we alway log the query into an array. if (\ClanCats::in_development()) { $keys = array(); foreach ($params as $key => $value) { if (is_string($key)) { $keys[] = '/:' . $key . '/'; } else { $keys[] = '/[?]/'; } } static::$_query_log[] = preg_replace($keys, $params, $query, 1); } return $sth; }