/** * 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(); } }
/** * exception handler * * @param Exception $exception * @return void */ public static function exception($exception) { // clean the main output buffer while (ob_get_level() > 0) { ob_end_clean(); } $error_handler = "\\" . CCCORE_NAMESPACE . "\\CCError_Handler" . (ClanCats::is_cli() ? '_Cli' : ''); $error_inspector = "\\" . CCCORE_NAMESPACE . "\\CCError_Inspector"; if (is_object(ClanCats::$config) && ClanCats::$config instanceof CCConfig) { $error_handler = ClanCats::$config->get('error.' . (ClanCats::is_cli() ? 'cli_' : '') . 'handler', $error_handler); $error_inspector = ClanCats::$config->get('error.inspector', $error_inspector); } $inspector = new $error_inspector($exception); $handler = new $error_handler($inspector); $handler->handle(); }
/** * Is CCFile able to print information * * @return bool */ protected static function _can_print() { return ClanCats::is_cli() && static::$_print_infos ? true : false; }
/** * Test CC cli */ public function testIs_cli() { $this->assertTrue(\ClanCats::is_cli()); }
/** * Revert the last migration * * @return void */ public static function rollback() { // first of all we have to filter only the already migrated versions $available = static::available(); foreach ($available as $key => $migrations) { foreach ($migrations as $time => $migration) { if ($time > static::$config->get($key . '.revision', 0)) { unset($available[$key][$time]); } } } $revisions = array(); foreach ($available as $key => $value) { if (empty($value)) { continue; } foreach ($value as $name => $path) { $revisions[$name . '::' . $key] = $path; } } // nothing to rollback? if (empty($revisions)) { if (\ClanCats::is_cli()) { \CCCli::warning('nothing to rollback to.'); } return false; } ksort($revisions); end($revisions); list($time, $key) = explode('::', key($revisions)); $migration = new static(array_pop($revisions)); // rollback the migration $migration->down(); // get the lastet migration from the group $others = \CCArr::get($key, $available); ksort($others); array_pop($others); end($others); // update the config static::$config->set($key . '.revision', key($others)); static::$config->write(); return true; }
function _dd($var) { if (ClanCats::is_cli()) { var_dump($var); } else { echo "<pre>"; var_dump($var); echo "</pre>"; } die; }
* * Lets wake the ccf and pass the environment. */ ClanCats::wake($environment); unset($environment); // at this point ccf has completet its own boot CCProfiler::check("CCF - Boot completed."); /* *--------------------------------------------------------------- * output buffer *--------------------------------------------------------------- * * Start output buffering if it isn't disabled and we are not * running ccf from the command line interface. */ if (!ClanCats::is_cli() && ClanCats::$config->output_buffering) { ob_start(); } /* *--------------------------------------------------------------- * timezone *--------------------------------------------------------------- * * Sets the default timezone used by all php native date/time * functions in the application. */ if (ClanCats::$config->timezone) { if (!date_default_timezone_set(ClanCats::$config->timezone)) { throw new CCException("CCF - The given timezone is invalid. check main config -> timezone."); } }
/** * Session constructor * * @param string $name * @param array $config */ protected function __construct($name, $config = null) { if (is_null($config)) { $config = \CCConfig::create('session')->get($name); // check for an alias. If you set a string // in your config file we use the config // with the passed key. if (is_string($config)) { $config = \CCConfig::create('session')->get($config); } } if (empty($config)) { throw new Exception("Session\\Manager::create - Invalid session manager (" . $name . ")."); } // also don't forget to set the name manager name becaue we need him later. $this->_name = $name; // keep the configuration array $this->_config = $config; // Setup the driver class. We simply use name // from the confif file and make the first letter // capital. example: Handler_Mysql, Handler_Sqlite etc. $driver_class = __NAMESPACE__ . "\\Manager_" . ucfirst($config['driver']); if (!class_exists($driver_class)) { throw new Exception("Session\\Manager::create - The driver (" . $driver_class . ") is invalid."); } $this->set_driver($driver_class); // try to get the id from cookie $this->id = $this->cookie_session_id(); // set the fingerprint $this->fingerprint = sha1($this->id); // Before reading we might have to kill old sessions using // the Garbage collector if (\CCArr::get('gc.enabled', $this->_config, true)) { if (mt_rand(1, \CCArr::get('gc.factor', $this->_config, 25)) == 1) { $this->gc(); } } // Register a shutdown event to write the session down // This should not happen on shutdown if we using command line if (!\ClanCats::is_cli()) { \CCEvent::mind('CCF.shutdown', array($this, 'write')); } // Now get the inital data from our driver $this->read(); }