/** * get the application's config * * @param unknown_type $app_name * @param unknown_type $env */ public static function getAppConfig($app_name, $env) { $app_conf = new AppConfig(); $app_conf->setup(); // init frameowk's dirs // TODO Make these dirs configable rtConfig::set('rt_apps_dir', rtConfig::get('rt_project_dir') . DS . 'apps'); rtConfig::set('rt_app_dir', rtConfig::get('rt_apps_dir') . DS . $app_name); rtConfig::set('rt_app_config_dir', rtConfig::get('rt_app_dir') . DIRECTORY_SEPARATOR . 'config'); rtConfig::set('rt_app_controllers_dir', rtConfig::get('rt_app_dir') . DS . 'controllers'); rtConfig::set('rt_app_components_dir', rtConfig::get('rt_app_controllers_dir') . DS . 'components'); rtConfig::set('rt_app_views_dir', rtConfig::get('rt_app_dir') . DS . 'views'); rtConfig::set('rt_app_views_layout_dir', rtConfig::get('rt_app_views_dir') . DS . 'layout'); rtConfig::set('rt_models_dir', rtConfig::get('rt_project_dir') . DS . 'lib' . DS . 'models'); rtConfig::set('rt_app_helpers_dir', rtConfig::get('rt_app_dir') . DS . 'helper'); rtConfig::set('rt_config_dir', rtConfig::get('rt_project_dir') . DS . 'config'); rtConfig::set('rt_web_dir', rtConfig::get('rt_project_dir') . DS . 'web'); rtConfig::set('rt_data_dir', rtConfig::get('rt_project_dir') . DS . 'data'); rtAutoloader::addPath(rtConfig::get('rt_project_dir') . DS . 'lib'); rtAutoloader::addPath(rtConfig::get('rt_models_dir'), rtConfig::get('rt_models_dir') . DS . 'generated', rtConfig::get('rt_app_controllers_dir'), rtConfig::get('rt_app_components_dir')); // setup app config require rtConfig::get('rt_app_config_dir') . DS . $app_name . 'AppConfig.class.php'; $app_class_name = $app_name . 'AppConfig'; $class = new $app_class_name(); $class->setup(); return $class; }
public static function register() { self::initPath(); // register autoload function spl_autoload_register('rtAutoloader::basic_autoloader'); rtConfig::set('rt_core_dir', dirname(__FILE__)); }
public static function registerViewClasses() { $classes = array(); $views = rtConfig::get('views'); foreach ($views as $view) { $classes[] = call_user_func(array($view, 'register')); } rtConfig::set('rt.view.classes', $classes); }
function end_slot() { $slot_name = rtConfig::get('rt.response.view.slots'); if (!$slot_name) { throw new rtException("end_slot() should follow with a slot() function"); } $response = rtResponse::getInstance(); $content = ob_get_clean(); $response->setSlot($slot_name, $content); // empty it rtConfig::set('rt.response.view.current_slot', NULL); }
public function process_response() { if (!rtConfig::get('enable_toolbar', false)) { return; } $params = array('logs' => rtLogger::getLogs()); $params = array_merge($params, rtController::getMagicViewVars()); list($tpl, $view_class) = findTemplateFileName(rtConfig::get('rt_core_dir') . DS . 'default' . DS . 'toolbar'); $toolbar = new $view_class($tpl, $params); $response = rtResponse::getInstance(); $new_body = str_replace('</body>', $toolbar->getOutput() . '</body>', $response->getBody()); $response->setBody($new_body); }
public static function dispatch(rtAppConfig $config) { // Load the project's config Rythm::init(); // Load the application's config // Route the request rtRoute::route(); //============================================================ // Start Handle the request //============================================================ // Initial middleware classes $middleware_classes = rtConfig::get('middlewares', array()); $middlewares = array(); foreach ($middleware_classes as $middleware_class) { require_once "middleware/{$middleware_class}.php"; $middlewares[] = new $middleware_class(); } // =========================================== // middleware start process request $request = rtRequest::getInstance(); foreach ($middlewares as $middleware) { if (method_exists($middleware, 'process_request')) { $middleware->process_request($request); } } // middleware end process request // =========================================== // Core Process $controller = $request->getController(); $action = $request->getAction(); $controller_class = ucfirst($controller) . 'Controller'; if (!class_exists($controller_class)) { throw new rtException("Can't find Controller: {$controller_class}"); } $controller = new $controller_class(); if (!$controller instanceof rtController) { throw new rtException("Controller:{$controller_class} must extend from rtController class"); } $controller->execute($action . 'Action', $request); // End Core Process // =========================================== // start process response $response = rtResponse::getInstance(); // response middleware process in the reverse direction foreach (array_reverse($middlewares) as $middleware) { if (method_exists($middleware, 'process_response')) { $middleware->process_response($response); } } // end process response }
public function execute($component, $func, $vars = array()) { $func_up = ucwords($func); $real_func = "execute{$func_up}"; if (!method_exists($this, $real_func)) { throw new Exception("Function: '{$real_func}' doesn't exist in component:" . get_class($this)); } // call the component function call_user_func(array($this, $real_func)); // render view $this->_template_ = rtConfig::get('rt_app_views_dir') . DS . 'components' . DS . $component . DS . "_{$func}"; list($file, $view_class) = findTemplateFileName($this->_template_); // merge the use defined vars $view = new $view_class($file, array_merge($this->_view_vars_, $vars, $this->getMagicViewVars())); return $view->getOutput(); }
private function __construct() { // strip the slashes... if (get_magic_quotes_gpc() == true) { $_REQUEST = array_map('stripslashes', $_REQUEST); } $this->parameters = $_REQUEST; // TODO GET POST and URL embed // if (!rtConfig::get('url_rewrite') && strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']) == 0) { $path_info = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/'; } else { $query_str = $_SERVER['QUERY_STRING']; $path_info = $_SERVER['REQUEST_URI']; // trim the query string if ($query_str) { // +1 means the '?' before query string $path_info = substr($_SERVER['REQUEST_URI'], 0, -(strlen($query_str) + 1)); } } $this->setParameter('request_path_info', $path_info); }
public static function init($data) { self::$_data = array_merge(self::$_data, $data); }
function findTemplateFileName($file_without_ext) { $format = rtRequest::getInstance()->getParameter('format', 'html'); // choose the right view class by the file extension found $associations = rtConfig::get('rt.view.classes', array()); foreach ($associations as $association) { if (file_exists($file = $file_without_ext . ".{$format}." . $association['extension']) || file_exists($file = $file_without_ext . '.' . $association['extension']) || file_exists($file = $file_without_ext . '.html.' . $association['extension'])) { $view_class = $association['class']; break; } } if (!isset($view_class)) { throw new rtException("Can't find template: {$file_without_ext}.{format}.php"); } return array($file, $view_class); }
<?php # This should require rythm framework's autoload class to start the framework # rythm autoload require_once dirname(__FILE__) . '/../../rythm/lib/rtAutoloader.class.php'; rtAutoloader::register(); rtConfig::set('rt_project_dir', realpath(dirname(__FILE__) . DS . '..')); class AppConfig extends rtAppConfig { public function setup() { // Set your config here // rtConfig::set('your-key', $your_value); } }
/** * respond for certern format */ public function respond($formats) { foreach ($formats as $format => $params) { if ($this->getRequestParameter('format') == $format) { // layout if (isset($params['layout']) && $params['layout'] == false) { $this->setLayout(false); } // check mime-types // Load mime types $mimes = sfYaml::load(rtConfig::get('rt_config_dir') . DS . 'mime.yml'); if (isset($mimes[$format])) { $header = 'Content-Type: ' . $mimes[$format] . '; charset=' . rtConfig::get('encode'); rtResponse::getInstance()->header($header); } break; } } }
<?php require_once 'config/AppConfig.class.php'; AppConfig::getAppConfig('rblog', 'dev'); Rythm::init(); // Include your Doctrine configuration/setup here, your connections, models, etc. // Configure Doctrine Cli // Normally these are arguments to the cli tasks but if they are set here the arguments will be auto-filled and are not required for you to enter them. $config = array('data_fixtures_path' => '/path/to/data/fixtures', 'models_path' => rtConfig::get('rt_project_dir') . DS . 'lib' . DS . 'models', 'migrations_path' => ROOT_DIR . DS . 'data' . DS . 'migrations', 'sql_path' => rtConfig::get('rt_data_dir') . DS . 'sql', 'yaml_schema_path' => rtConfig::get('rt_config_dir') . DS . 'schema.yml'); $cli = new Doctrine_Cli($config); $cli->run($_SERVER['argv']);
/** * Log method * * @param string $type log type: route, controller view or something * @param string $msg */ public static function log($type, $msg) { if (rtConfig::get('enable_log')) { self::$_logs[] = array('type' => $type, 'message' => $msg, 'time' => time()); } }