/** * Static init * * @return void */ public static function _init() { // select the current builder $builder_class = \ClanCats::$config->get('ui.builder', "\\UI\\Builder_Bootstrap"); static::$builder = new $builder_class(); // load the ui configuration static::$config = \CCConfig::create('ui'); }
/** * prepare the configuration * * @return void */ public static function setUpBeforeClass() { parent::setUpBeforeClass(); CCConfig::create('auth')->_data = CCConfig::create('Core::phpunit/auth')->_data; $user = new Auth\User(); $user->email = "*****@*****.**"; $user->password = "******"; $user->save(); static::$current_user = $user; }
/** * reset and run the migrations */ public static function wake() { // complete overwrite of DB configuration CCConfig::create('database')->_data = CCConfig::create('Core::phpunit/database')->_data; // delete all database table DB\Migrator::hard_reset(); DB\Migrator::hard_reset('phpunit'); // run the migrations DB\Migrator::migrate(true); }
/** * 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 * * @return void */ public static function _init() { if (!($path = CCConfig::create("Packtacular::packtacular")->path)) { throw new CCException("CCPacktacular - please set your packtacular path!"); } // is there a cache dir? if (!is_dir(PUBLICPATH . $path)) { if (!mkdir(PUBLICPATH . $path, 0755, true)) { throw new CCException("CCPacktacular - could not create Packtacular folder at: {$path}"); } } static::$path = '/' . $path; }
/** * Application initialization. * do your inital stuff here like getting the current user object ect.. * You can return a CCResponse wich will cancle all other actions * if enebaled ( see. main.config -> send_app_wake_response ) * * @return void | CCResponse */ public static function wake() { /* * Start the session by adding the current uri */ CCSession::set('uri', CCServer::uri()); /* * try to authenticate the user */ //static::$user =& CCAuth::handler()->user; /* * load the App configuration */ static::$config = CCConfig::create('app'); }
/** * CCMail::send catch all setting tests */ public function test_catch_all() { // configure catch all CCConfig::create('mail')->set('catch_all.enabled', true); CCConfig::create('mail')->set('catch_all.addresses', array('*****@*****.**' => 'ClanCats', '*****@*****.**' => 'Some Other')); CCConfig::create('mail')->set('catch_all.transporter', 'alias'); // create a new mail $mail = CCMail::create(); $mail->to('*****@*****.**'); $mail->bcc('*****@*****.**'); $mail->send(); // check data $mail_data = CCArr::last(Mail\Transporter_Array::$store); $this->assertEquals($mail_data['to'], array('*****@*****.**' => 'ClanCats', '*****@*****.**' => 'Some Other')); $this->assertEquals($mail_data['bcc'], array()); CCConfig::create('mail')->set('catch_all.enabled', false); }
/** * prepare the configuration * * @return void */ public static function setUpBeforeClass() { CCConfig::create('session')->_data = CCConfig::create('Core::phpunit/session')->_data; }
/** * test delete failure without name */ public function testNoNameDelete() { $this->setExpectedException('CCException'); $config = CCConfig::create(); $config->_delete(); }
/** * generates an file header string * * @param string $title * @param array $data * @return string */ public function make_comment_header($title, $data = array()) { // get author $authors = \CCArr::get('authors', $data, \CCConfig::create('shipyard')->get('defaults.authors')); // author if (is_array($authors)) { foreach ($authors as $person) { $author_str .= $person['name'] . " "; if (array_key_exists('email', $person)) { $author_str .= "<" . $person['email'] . ">"; } $author_str .= ", "; } $author_str = substr($author_str, 0, -2); } return "{$title}\n" . "*\n" . "\n" . "@package " . \CCArr::get('package', $data, \CCConfig::create('shipyard')->get('defaults.package')) . "\n" . "@author " . $author_str . "\n" . "@version " . \CCArr::get('version', $data, \CCConfig::create('shipyard')->get('defaults.version')) . "\n" . "@copyright " . \CCArr::get('copyright', $data, \CCConfig::create('shipyard')->get('defaults.copyright')) . "\n"; }
/** * 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(); }
/** * init the orbit data */ public static function _init() { static::$data = CCConfig::create(ClanCats::$config->get('orbit.data'), 'json'); }
/** * Prepare the message for sending to the transport * * @return void */ public function send() { // load the mail configuration $config = \CCConfig::create('mail'); // when mailing is disabled do nothing just return if ($config->disabled === true) { return; } // we cannot send a mail without recipients if (empty($this->to)) { throw new Exception("Cannot send mail without recipients."); } // is a catch all enabled? if ($config->get('catch_all.enabled') === true) { // to be able to modify the mail without removing // the user options we have to clone the mail $mail = clone $this; // we have to remove all recipients ( to, ccc, bcc ) and set them // to our catch all recipients $mail->to = array(); $mail->cc = array(); $mail->bcc = array(); $mail->to($config->get('catch_all.addresses')); // transport the cloned mail return $mail->transport($config->get('catch_all.transporter')); } // transport the mail $this->transport(); }
/** * prepare the configuration * * @return void */ public static function setUpBeforeClass() { CCConfig::create('main')->set('language.available', array('de' => array('de', 'ch'), 'en' => array('us', 'gb'), 'fr' => array('fr'))); }
/** * static theme init * * @return void */ public static function _init() { static::$config = \CCConfig::create(static::view_namespace() . '::theme'); }
/** * 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; }); }
/** * static theme init * * @return void */ public static function _init() { static::$config = \CCConfig::create(__NAMESPACE__ . '::theme'); }
/** * Init the migrator directory */ public static function _init() { \ClanCats::directories(array('migration' => 'database/')); // read the migration configuration static::$config = \CCConfig::create('migrator', 'json'); }
/** * Auth instance constructor * * @param string $name * @param array $config * @return void */ public function __construct($name, $config = null) { if (is_null($config)) { $config = \CCConfig::create('auth')->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('auth')->get($config); } } if (!is_array($config)) { throw new Exception("Auth\\Handler::create - Invalid auth handler (" . $name . ")."); } // also don't forget to set the name manager name becaue we need him later. $this->name = $name; // assign defaults and create the configuration object $this->config = \CCDataObject::assign(\CCArr::merge(array('session_manager' => null, 'session_key' => 'user_id', 'user_key' => 'id', 'user_model' => "\\Auth\\User", 'identifiers' => array('email'), 'logins' => array('handler' => null, 'table' => 'auth_logins'), 'restore' => array('id_cookie' => 'ccauth-restore-id', 'token_cookie' => 'ccauth-restore-token', 'lifetime' => \CCDate::months(1))), $config)); // set the session handler $this->session = \CCSession::manager($this->config->session_manager); $user_model = $this->config->user_model; // set a empty default user object to avoid // on a non object errors $this->user = new $user_model(); // do we already have a user id means are we // logged in? if (!is_null($session_key = $this->session_user_id())) { if ($user = $user_model::find($this->config->user_key, $session_key)) { $this->user = $user; return $this->authenticated = true; } } else { $restore_id_cookie = $this->config->get('restore.id_cookie'); $restore_token_cookie = $this->config->get('restore.token_cookie'); if (CCCookie::has($restore_id_cookie) && CCCookie::has($restore_token_cookie)) { // get the restore cookies $restore_id = CCCookie::get($restore_id_cookie); $restore_token = CCCookie::get($restore_token_cookie); // get the restore login $login = $this->select_logins()->where('restore_id', $restore_id)->where('restore_token', $restore_token)->limit(1); // if no login found kill the cookies and return if (!($login = $login->run())) { $this->kill_restore(); return $this->authenticated = false; } // Invalid user? kill the cookies and return if (!($user = $user_model::find($this->config->user_key, $restore_id))) { $this->kill_restore(); return $this->authenticated = false; } // validate the restore key if invalid // once again kill the cookies and return if ($login->restore_token != $this->restore_key($user)) { $this->kill_restore(); return $this->authenticated = false; } // If everything is fine sign the user in and // update the restore keys $this->sign_in($user, true); return $this->authenticated = true; } } return $this->authenticated = false; }
/** * This function should provide the application routes. * By default its going to use the router.config file. * * @return array */ public static function routes() { return CCConfig::create(ClanCats::$config->get('router.map'))->raw(); }
/** * Try to etablish a connetion to the database. Also assign the connection * and query builder to the current DB driver. * * @param string|array $name When passing an array it will be uesed as configuration. * @return void */ protected function connect($name) { if ($this->_connected) { return true; } // check if the name is an array. This way we can // pass the configuration directly. We need this // to create for example an handler without having // the configuration in the database conf file. if (is_array($name)) { $config = $name; } else { $config = \CCConfig::create('database')->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('database')->get($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__ . "\\Handler_" . ucfirst($config['driver']); if (!class_exists($driver_class)) { throw new Exception("DB\\Handler::connect - The driver (" . $driver_class . ") is invalid."); } $this->set_driver($driver_class); // setup the builder the same way as the handler. $driver_class = __NAMESPACE__ . "\\Builder_" . ucfirst($config['driver']); if (!class_exists($driver_class)) { throw new Exception("DB\\Handler::connect - The builder (" . $driver_class . ") is invalid."); } $this->set_builder($driver_class); // finally try to connect the driver with the databse if ($this->driver()->connect($config)) { return $this->_connected = true; } return $this->_connected = false; }
/** * prepare the configuration * * @return void */ public static function setUpBeforeClass() { CCConfig::create('ui')->_data = CCConfig::create('Core::ui')->_data; }
/** * Transporter instance constructor * * @param string $name * @param array $config * @return void */ public function __construct($name, $config = null) { if (is_null($config)) { $config = \CCConfig::create('mail')->get('transporter.' . $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('mail')->get('transporter.' . $config); } } if (!is_array($config)) { throw new Exception("Auth\\Handler::create - Invalid auth handler (" . $name . ")."); } // also don't forget to set the name manager name becaue we need him later. $this->name = $name; // assign defaults and create the configuration object $this->config = \CCDataObject::assign(\CCArr::merge(array('driver' => 'sendmail'), $config)); // load the driver $driver_class = __NAMESPACE__ . '\\Transporter_' . ucfirst($this->config->driver); if (!class_exists($driver_class)) { throw new Exception("Invalid mail driver '" . $this->config->driver . "'"); } $this->driver = new $driver_class($this->config); }
* * By default the the environment detector defines the current * environment. But you can force another one using the this var. */ $environment = 'phpunit'; /* *--------------------------------------------------------------- * Require CCF *--------------------------------------------------------------- * * load the framework file wich wil initialize CCF. */ require_once __DIR__ . "/../framework.php"; /* *--------------------------------------------------------------- * CCUnit resources *--------------------------------------------------------------- * * For the unit tests we need some additional resources like * controllers, views, ect... */ CCOrbit::enter(COREPATH . 'orbit/CCUnit'); // write header CCCli::line("==============================\n _____ _____ ______ \n / ____/ ____| ____|\n | | | | | |__ \n | | | | | __| \n | |___| |____| | \n \\_____\\_____|_| ramework\n==============================\n", 'cyan'); // complete overwrite of DB configuration CCConfig::create('database')->_data = CCConfig::create('Core::phpunit/database')->_data; // delete all database table DB\Migrator::hard_reset(); DB\Migrator::hard_reset('phpunit'); // run the migrations DB\Migrator::migrate(true);
/** * Get the current builder output * * @return string */ public function output() { $namespace = null; $class = $this->name; extract(\CCConfig::create('shipyard')->defaults); // get namespace from the param if (strpos($class, '::') !== false) { list($namespace, $class) = explode('::', $this->name); // try to get the ship from namespace if ($ship = \CCOrbit::ship_by_namespace($namespace)) { $package = $ship->name; $version = $ship->version; $authors = $ship->authors; } } // create forge instance $forge = new \CCForge_Php($namespace); // add header $forge->comment($this->file_header($class, array('package' => $package, 'authors' => $authors, 'version' => $version, 'copyright' => $copyright))); $class_string = 'class ' . $class; // superclasses if ($this->extends) { $class_string .= ' extends ' . $this->extends; } // interface implementations if (!empty($this->implements)) { $class_string .= ' implements ' . implode(', ', $this->implements); } // create the closure $forge->closure($class_string, $this->output); return $forge->buffer; }