/** * CCController factory * * @param string $path * @return CCController */ public static function create($path) { $class = static::find($path); // if class already loaded if (!class_exists($class, false)) { // register the controller with the autoloader \CCFinder::bind($class, CCPath::get($path, CCDIR_CONTROLLER, 'Controller' . EXT)); } // create new controller instance and assign the name $controller = new $class(); $controller->name = $path; return $controller; }
* * Session managment bundle */ // namepace \CCFinder::map('Session', COREPATH . 'bundles/Session/'); // and the shdaow \CCFinder::shadow('CCSession', 'Session', COREPATH . 'bundles/Session/CCSession' . EXT); /* *--------------------------------------------------------------- * Authentication Bundle *--------------------------------------------------------------- * * The Authentication bundle for basic a basic user and login */ // namepace \CCFinder::map('Auth', COREPATH . 'bundles/Auth/'); // and the shdaow \CCFinder::shadow('CCAuth', 'Auth', COREPATH . 'bundles/Auth/CCAuth' . EXT); /* *--------------------------------------------------------------- * Email Bundle *--------------------------------------------------------------- * * The Email bundle mostly wraps phpmailer */ // namepace \CCFinder::map('Mail', COREPATH . 'bundles/Mail/'); // phpmailer \CCFinder::bind(array("Mail\\PHPMailer\\PHPMailer" => COREPATH . 'bundles/Mail/PHPMailer/class.phpmailer' . EXT, "Mail\\PHPMailer\\POP3" => COREPATH . 'bundles/Mail/PHPMailer/class.php3' . EXT, "Mail\\PHPMailer\\SMTP" => COREPATH . 'bundles/Mail/PHPMailer/class.smtp' . EXT)); // and the shdaow \CCFinder::shadow('CCMail', 'Mail', COREPATH . 'bundles/Mail/CCMail' . EXT);
/** * start the ccf app lifecycle * * This method registers the App class and runs the wake events. * * @param string $app The used app class = APPATH/<$app>.php * @return void */ public static function wake_app($app) { static::$runtime_class = $app; \CCFinder::bind($app, static::$paths['app'] . $app . EXT); // run the application wake $response = $app::wake(); // when the application wake returns an response we display it if ($response instanceof CCResponse) { if (static::$config->send_app_wake_response) { $response->send(true); die; } } $response = null; // run the environment wake if (method_exists($app, 'wake_' . static::$environment)) { $response = call_user_func($app . '::wake_' . static::$environment); // when the application env wake returns an response we display it if ($response instanceof CCResponse) { if (static::$config->send_app_wake_response) { $response->send(true); die; } } } // add routes from the app CCRouter::on($app::routes()); }
/** * Run a console script * * @param string $controller * @param string $action * @param array $params */ public static function run($controller, $action = null, $params = array()) { // always enable the file infos // this allows CCFile to print an info when a file gets created or deleted. CCFile::enable_infos(); // execute by default the help action if (empty($action)) { $action = 'default'; } $path = CCPath::get($controller, CCDIR_CONSOLE, EXT); // check if the file exists, if not try with core path if (!file_exists($path)) { if (!CCPath::contains_namespace($controller)) { $path = CCPath::get(CCCORE_NAMESPACE . '::' . $controller, CCDIR_CONSOLE, EXT); } } // still nothing? if (!file_exists($path)) { CCCli::line("Could not find controller {$controller}.", 'red'); return false; } // all console classes should be on the CCConsole namespace // this way you can easly overwrite a console script $class = 'CCConsole\\' . $controller; // add the class to the autoloader \CCFinder::bind($class, $path); // create an instance $class = new $class($action, $params); // run wake function if (method_exists($class, 'wake')) { call_user_func(array($class, 'wake'), $params); } // run the execution call_user_func(array($class, '_execute'), $action, $params); // run sleep if (method_exists($class, 'sleep')) { call_user_func(array($class, 'sleep'), $params); } }