/** * 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; }); } }
/** * initialize the ship * * @return void */ public function wake() { // wrap the assets \CCFinder::alias('CCAsset', __DIR__ . '/CCAsset' . EXT); // map the other classes \CCFinder::package(__DIR__ . '/', array('Packtacular' => 'Packtacular' . EXT, 'Packtacular\\Theme' => 'Theme' . EXT, 'lessc' => 'lib/lessc.inc' . EXT)); // add writeable directory hook \CCEvent::mind('ccdoctor.permissions', function () { return PUBLICPATH . \CCConfig::create("Packtacular::packtacular")->path; }); }
/** * Static init * When we are in development then we append the qurey log to body * * @codeCoverageIgnore * * @return void */ public static function _init() { 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-db')); $table->header(array('#', 'query')); foreach (static::log() as $key => $item) { $table->row(array($key + 1, $item)); } return str_replace('</body>', $table . "\n</body>", $output); }); } }
/** * 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); }); } }
/** * Handler::sign_in keep login tests */ public function test_sign_in_keeper() { Auth\Handler::kill_instance('main'); $example_user = clone static::$current_user; $auth = Auth\Handler::create(); $auth->sign_in($example_user, false); $this->assertTrue($auth->user instanceof DB\Model); $this->assertEquals(static::$current_user->id, $auth->user->id); // test valid Auth\Handler::kill_instance('main'); $auth = Auth\Handler::create(); $this->assertTrue($auth->valid()); // lets create an keeper login now $this->create_keeper_login(); // lets test the login store event $this->assertEquals(null, $auth->login()->client_ip); $auth->session->destroy(); CCEvent::mind('auth.store_login', function ($data) { $data['client_ip'] = '127.0.0.1'; return $data; }); Auth\Handler::kill_instance('main'); $auth = Auth\Handler::create(); $this->assertTrue($auth->valid()); $this->assertEquals('127.0.0.1', $auth->login()->client_ip); // now lets modify some data to force restore failure // changing the the current client ip will force failure CCIn::instance(new CCIn_Instance(array(), array(), array(), array(), array('REMOTE_ADDR' => '192.168.1.42'))); $this->keeper_login_false(); // next lets modify the users password wich will force a failure $this->create_keeper_login(); $this->keeper_login_true(); static::$current_user->password = "******"; static::$current_user->save(); $this->keeper_login_false(); // modifiy the restore_id $this->create_keeper_login(); $this->keeper_login_true(); CCCookie::set('ccauth-restore-id', '34'); $this->keeper_login_false(); // modifiy the restore_token $this->create_keeper_login(); $this->keeper_login_true(); CCCookie::set('ccauth-restore-token', 'wrong'); $this->keeper_login_false(); // delete the user $this->create_keeper_login(); $this->keeper_login_true(); static::$current_user->delete(); $this->keeper_login_false(); // create him again static::$current_user->save(); }
/** * 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(); }