public static function _init() { try { static::setEngine(Config::getVal('view', 'engine')); } catch (EngineNotFoundException $e) { static::$engine = false; } static::loadDefaultHelpers(); }
public static function load() { $file = Config::getVal('path', 'app_path', true) . DIRECTORY_SEPARATOR . Config::getVal('path', 'cache', true) . DIRECTORY_SEPARATOR . "cookie.dat"; try { $data = file_get_contents($file); } catch (Exception $e) { throw new CouldNotWriteToCacheException($e->getMessage()); } static::$registry = unserialize($data); static::cleanUp(); }
public final function __construct() { if (!static::$_driver) { $class = 'dioxid\\model\\engine\\' . Config::getVal('database', 'driver', true) . 'Engine'; } else { $class = 'dioxid\\model\\engine\\' . static::$_driver . 'Engine'; } if (class_exists($class)) { static::$_engine = call_user_func_array(array($class, 'getInstance'), array(static::$_name)); } else { throw new EngineNotFoundException($class . ' not found'); } static::_init(); }
public static function _init($document) { if (!$document) { throw new NoDatabaseTableNameException(); } $con = Config::getVal('database', 'host') . ":" . Config::getVal('database', 'port'); static::$mongo = new Mongo($con); if (Config::getVal('database', 'user') != "" && Config::getVal('database', 'password') != "") { $ret = static::$mongo->authenticate(Config::getVal('database', 'user'), Config::getVal('database', 'password')); if ($ret['ok'] === 0) { throw new CantEtablishDatabaseConnectionException($ret['errmsg']); } } static::$document = static::$mongo->{$document}; }
/** * Method: _init * Constructor. Sets the MySQL specific DSN. * */ public static function _init() { $dsn = 'mysql:dbname=' . Config::getVal('database', 'database', true) . ';host=' . Config::getVal('database', 'host', true); $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'', PDO::MYSQL_ATTR_COMPRESS => true); parent::_init($dsn, $options); }
/** * Method: _getBaseUrl * Returns the BaseUrl * @return string */ public static function _getBaseUrl() { return static::$baseUrl['scheme'] . '://' . static::$baseUrl['host'] . (@static::$baseUrl['port'] ? ':' . @static::$baseUrl['port'] : "") . (Config::getVal('misc', 'dispatcher_limit') ? '/' . trim(Config::getVal('misc', 'dispatcher_limit'), '/') : ""); }
/** * Method: registerCustom404 * Displays your own 404 error pages when debugmode is turned off. * The 404 file has to be somewhare in the template directory. * * @param string $path * @throws TemplateNotFoundException */ public static function registerCustom404($path) { if (file_exists(Config::getVal('path', 'app_path')) . $path) { static::$custom404 = Config::getVal('path', 'app_path') . DIRECTORY_SEPARATOR . Config::getVal('path', 'template_path') . DIRECTORY_SEPARATOR . $path; } else { throw new TemplateNotFoundException('Errorpage not found at ' . $path); } }
public function loadLayout($folder = false, $template = false, $w_ext = false) { $path = $fqtp = Config::getVal('path', 'app_path') . Config::getVal('path', 'template_path') . DIRECTORY_SEPARATOR; $path .= ($folder ? $folder : "layout") . DIRECTORY_SEPARATOR; $path .= $template ? $template : "default" . Config::getVal('view', 'extension'); $path .= $w_ext ? Config::getVal('view', 'extension') : ""; if (file_exists($path)) { $this->_layout = $path; } else { throw new TemplateNotFoundException("Layout not found in {$path}"); } }
/** * Method: dispatch * Crawls the URL and calls the requested Controller and Action */ public static function dispatch() { // Build the reuqest URL // taken and modified from http://stackoverflow.com/questions/5216172/getting-current-url $req_url = @$_SERVER["HTTPS"] == "on" ? "https://" : "http://"; $req_url .= $_SERVER["HTTP_HOST"]; $req_url .= $_SERVER["REQUEST_URI"]; $req_url = static::$calledUrl = parse_url($req_url); // If theres no dispatcher limit dont replace anything if (Config::getVal('misc', 'dispatcher_limit') != "" || Config::getVal('misc', 'dispatcher_limit') != 0) { $request = str_replace(Config::getVal('misc', 'dispatcher_limit', true), '', $req_url['path']); } else { $request = $req_url['path']; } $request = trim($request, '/'); //Dispatch Static Routes $sroutes = Router::matchRoutes($request); if ($sroutes) { static::load(Config::getVal('misc', 'controller_namespace', true) . $sroutes['class'], $sroutes['method'], $sroutes['param']); return; } $chunks = explode('/', $request); // Parse the GET Params $GET = array(); $param = array(); if (count($chunks) >= 2) { $GET = array_merge($GET, array_slice($chunks, 2)); } if (@$req_url['query'] != "") { $pairs = explode('&', $req_url['query']); foreach ($pairs as $pair) { $parts = explode('=', $pair); $GET = array_merge($GET, $parts); } } for ($i = 0; $i <= count($GET) - 1; $i += 2) { $param[$GET[$i]] = $GET[$i + 1]; if ($GET[$i] == "" && $GET[$i + 1] == "") { break; } } // If no controller is provided if ($chunks[0] == "") { if (static::$customIndex) { static::load(Config::getVal('misc', 'controller_namespace', true) . static::$customIndex['class'], static::$customIndex['method']); } else { static::load(Config::getVal('misc', 'controller_namespace', true) . 'Index', '_index', $param); } return; } $class = Config::getVal('misc', 'controller_namespace', true) . ucfirst($chunks[0]); // This fixes a weired bug where it tries to load a namespace without controller if (substr($class, -1) == "\\") { return; } // If a Controller but no Action is provided if (count($chunks) == 1 && $chunks[0] != "") { static::load($class, 'index', $param); } // If a Controller and an Action is provided if (count($chunks) >= 2) { $method = $chunks[1]; static::load($class, $method, $param); } }
* */ namespace example; // Your Project Basenamespace // Load the dioxid loader require_once 'path/to/dioxid/common/Loader.php'; use dioxid\Loader; // setup the app namespace to use the loader on user written classes and the basepath for the loadding // for each different base namespace in your app add an entry in the array in the scheme NAMESAPCE => BASEPATH Loader::setup(array(__NAMESPACE__ => __DIR__)); //register the loader Loader::register(); use dioxid\config\Config; // We need to read the config use dioxid\controller\Dispatcher; // We have to dispatch the Controller/Action pair use dioxid\controller\Router; // We Only need this if we have static routes use dioxid\error\ErrorHandler; // And at least we want to have some Errorhandling ;) Config::loadConfig(__DIR__ . '/config.ini', true); //Load the Config, remeber to give it the full path to your config.ini ErrorHandler::register(); // Register the Errorhandler // Register your static routes. Take a look at dioxid\controller\Router.php for more documentation ;) Router::registerStaticRoutes(':lang:/index', array('index' => 'test')); // What is your default controller and your default action? By Default this is index/index! Dispatcher::registerIndex('index', 'test'); // Lets Dispatch the Controller/Action pair ;) Dispatcher::dispatch();
public function base() { return $this->baseUrl['scheme'] . '://' . $this->baseUrl['host'] . (@$this->baseUrl['port'] ? ':' . @$this->baseUrl['port'] : "") . (Config::getVal('misc', 'dispatcher_limit') ? '/' . trim(Config::getVal('misc', 'dispatcher_limit'), '/') : ""); }