Example #1
0
 public static function getInstance()
 {
     if (self::$instance === null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #2
0
 public static function getInstance($reset = false)
 {
     if (null === Router::$instance || $reset) {
         Router::$instance = new Router();
     }
     return Router::$instance;
 }
Example #3
0
 /**
  * 
  * @return Router
  */
 public static function getInstance($index)
 {
     if (!isset(self::$instance)) {
         self::$instance = new self($index);
     }
     return self::$instance;
 }
Example #4
0
 public static function instance($uri)
 {
     if (!self::$instance instanceof Router) {
         self::$instance = new Router($uri);
     }
     return self::$instance;
 }
Example #5
0
 /**
  * Ensure the Router object is a singleton.
  * 
  * @return Router single instance.
  * @author anza
  */
 public static function getInstance($registry)
 {
     if (!self::$instance) {
         self::$instance = new Router($registry);
     }
     return self::$instance;
 }
Example #6
0
 public static function me()
 {
     if (is_null(self::$instance)) {
         self::$instance = new Router();
     }
     return self::$instance;
 }
Example #7
0
 public function __construct($config)
 {
     $this->_objects['app'] = App::instance();
     $this->_objects['router'] = Router::instance();
     $this->_objects['inputs'] = Inputs::instance();
     $this->_objects['session'] = Session::instance();
     $this->_objects['log'] = Log::factory();
     if (!isset($this->app->config['database']['redis'][$config['serverId']])) {
         $config['serverId'] = 0;
     }
     $current = $this->app->config['database']['redis'][$config['serverId']];
     $current['serverId'] = $config['serverId'];
     $this->_objects['db'] = Db::factory($current);
     $this->_objects['infoModel'] = new Info_Model($current);
     $info = $this->db->info();
     $dbs = $this->infoModel->getDbs($info);
     if (!isset($current['max_databases'])) {
         $databasesConfig = $this->_objects['db']->config('GET', 'databases');
         $current['max_databases'] = $databasesConfig['databases'];
     }
     // Take care of invalid dbId's. If invalid, set to first available database
     if (!is_numeric($config['dbId']) || $config['dbId'] < 0 || $config['dbId'] >= $current['max_databases']) {
         $config['dbId'] = $dbs[0];
     }
     $current['newDB'] = !in_array($config['dbId'], $dbs) ? true : false;
     $current['database'] = $config['dbId'];
     // Extract number of keys
     foreach ($dbs as $i) {
         if (preg_match('/^keys=([0-9]+),expires=([0-9]+)/', $info["db{$i}"], $matches)) {
             $current['dbs'][$i] = array('id' => $i, 'keys' => $matches[1], 'name' => isset($current['dbNames'][$i]) ? $current['dbNames'][$i] : null);
         }
     }
     $this->db->select($current['database']);
     $this->app->current = $current;
 }
Example #8
0
 static function &getInstance()
 {
     if (!self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #9
0
 public static function singleton()
 {
     if (!isset(self::$instance)) {
         $c = __CLASS__;
         self::$instance = new $c();
     }
     return self::$instance;
 }
Example #10
0
 static function disconnect()
 {
     if (!self::open()) {
         return null;
     }
     self::$instance->disconnect();
     self::$instance = null;
 }
Example #11
0
 public function __construct()
 {
     ini_set('output_buffering', 'On');
     ini_set('short_open_tag', 'On');
     $this->_dir = '../views/';
     $this->app = App::instance();
     $this->router = Router::instance();
 }
Example #12
0
 static function model($name)
 {
     Router::instance()->loadModel($name);
     //print $x ? '111' :  '222';
     $className = ucfirst($name) . 'Model';
     // print($name);
     return new $className();
 }
Example #13
0
 public function __construct($config)
 {
     $this->_objects['app'] = App::instance();
     $this->_objects['router'] = Router::instance();
     $this->_objects['session'] = Session::instance();
     $this->_objects['db'] = Db::factory($config);
     $this->_objects['log'] = Log::factory();
 }
Example #14
0
/**
 * Assemble URL based on a specific route
 * 
 * Supported options:
 * 
 * - url_base (string): base for URL-s, default is an empty string
 * - query_arg_separator (string): what to use to separate query string 
 *   arguments, default is '&'
 * - anchor (string): name of the URL anchor
 *
 * @param string $name
 * @param array $params
 * @param array $options
 * @return string
 */
function assemble_url($name, $params = null, $options = null)
{
    static $instance;
    if ($instance === null) {
        $instance =& Router::instance();
    }
    // if
    return $instance->assemble($name, $params, $options);
}
Example #15
0
 private static function _getRequest()
 {
     if (self::$_request === NULL) {
         $router = Router::instance();
         // TODO: Try to access the previously matched object
         self::$_request = $router->match(ANGIE_PATH_INFO, ANGIE_QUERY_STRING);
     }
     return self::$_request;
 }
Example #16
0
 public static function get($options = null)
 {
     if (!self::$instance) {
         $class = __CLASS__;
         self::$instance = new $class();
         self::$instance->init($options);
     }
     return self::$instance;
 }
 public static function getInstance()
 {
     if (isset(self::$instance) and self::$instance instanceof self) {
         return self::$instance;
     } else {
         self::$instance = new self();
         return self::$instance;
     }
 }
Example #18
0
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new Router();
     }
     if (isset($_SESSION['educaskPreviousPage'])) {
         self::$previousURL = $_SESSION['educaskPreviousPage'];
     } else {
         self::$previousURL = null;
     }
     if (empty($_GET['p'])) {
         self::$currentURL = 'home';
         return self::$instance;
     }
     $cleanURL = filter_var($_GET['p'], FILTER_SANITIZE_URL);
     self::$currentURL = $cleanURL;
     return self::$instance;
 }
Example #19
0
 static function model($name)
 {
     Router::instance()->loadModel($name);
     $className = ucfirst($name) . 'Model';
     return new $className();
 }
Example #20
0
 public function process()
 {
     if (Config::log_level_at_least("short")) {
         register_shutdown_function(array("\\HalfMoon\\Request", "log_runtime"), $this);
     }
     try {
         ob_start();
         Router::instance()->takeRouteForRequest($this);
         /* if we received an If-None-Match header from the client and our
          * generated etag matches it, send a not-modified header and no
          * data */
         if (empty($this->redirected_to) && $this->etag_matches_inm()) {
             $headers = (array) headers_sent();
             ob_end_clean();
             foreach ($headers as $header) {
                 header($header);
             }
             Request::send_status_header(304);
         } else {
             if (empty($this->redirected_to)) {
                 $this->send_etag_header();
             }
             if (ob_get_level()) {
                 ob_end_flush();
             }
         }
     } catch (\Exception $e) {
         /* rescue, log, notify (if necessary), exit */
         if (class_exists("\\HalfMoon\\Rescuer")) {
             Rescuer::rescue_exception($e, $this);
         } else {
             throw $e;
         }
     }
 }
Example #21
0
 public function application()
 {
     if (!class_exists('\\Router')) {
         throw new RouterException("No Router class found in " . LEAN_APP_ROOT);
     }
     return \Router::instance();
 }
Example #22
0
<?php

//print '123';
//1.
include '../common.php';
session_start();
header('Content-Type: text/html; charset=utf-8');
mb_internal_encoding('UTF-8');
define('DOC_ROOT', __DIR__);
define('BASE_URL', '/course_work');
define('AVATAR_PATH', '/course_work/avatars');
include_once DOC_ROOT . '/system/Router.php';
include_once DOC_ROOT . '/system/view.php';
foreach (['Router', 'view', 'Model', 'Zed'] as $file) {
    include_once DOC_ROOT . "/system/{$file}.php";
}
$router = Router::instance();
$router->load();
$router->run();
 /**
  * Construct Angie application instance
  *
  * @param void
  * @return AngieApplication
  */
 function __construct()
 {
     $this->router =& Router::instance();
     $this->events_manager =& EventsManager::instance();
     $this->smarty =& Smarty::instance();
 }
Example #24
0
<?php

function __autoload($class)
{
    $path = '../';
    if (preg_match('/^(.*)_Controller$/', $class, $matches)) {
        $class = $matches[1];
        $dir = 'controllers';
    } elseif (preg_match('/^(.*)_Model$/', $class, $matches)) {
        $class = $matches[1];
        $dir = 'models';
    } elseif (preg_match('/^(.*)_Helper$/', $class, $matches)) {
        $class = $matches[1];
        $dir = 'helpers';
    } else {
        $dir = 'libraries';
    }
    include_once $path . $dir . '/' . strtolower($class) . '.php';
}
if (isset(App::instance()->config['timezone'])) {
    date_default_timezone_set(App::instance()->config['timezone']);
}
$error = new Error();
Router::instance()->route();
Example #25
0
 public function get($key, $default = null)
 {
     $result = Router::instance()->query($key, $default);
     return $result ? $result : $default;
 }
Example #26
0
 /** 
  * Returns the instance of Rewrite-obj
  * @static
  * @returns object
  */
 public static function getInstance()
 {
     if (Router::$instance == NULL) {
         Router::$instance = new Router();
     }
     return Router::$instance;
 }
Example #27
0
 public static function execute()
 {
     // only run once per request
     if (self::$instance === NULL) {
         try {
             // start validation of the controller
             $class = new ReflectionClass(self::$controller . '_controller');
         } catch (ReflectionException $e) {
             // controller does not exist
             return self::__404();
         }
         // create a new controller instance
         self::$instance = $class->newInstance();
         try {
             // load the controller method
             // Replace any hypens with underscores (want to use hypens in url, but underscores in method name)
             $method = $class->getMethod(str_replace("-", "_", self::$method));
             // methods prefixed with an underscore are hidden
             if (self::$method[0] === '_') {
                 // do not allow access to hidden methods
                 return self::__404();
             }
             if ($method->isProtected() or $method->isPrivate()) {
                 // do not attempt to invoke protected methods
                 return self::__404();
             }
             // default arguments
             $arguments = self::$arguments;
         } catch (ReflectionException $e) {
             try {
                 // try to use __call instead
                 $method = $class->getMethod('__call');
                 // use arguments in __call format
                 $arguments = array(self::$method, self::$arguments);
             } catch (ReflectionException $e) {
                 // method or __call does not exist
                 return self::__404();
             }
         }
         // execute the controller method
         $method->invokeArgs(self::$instance, $arguments);
     }
 }
Example #28
0
        $function_name = $stackPoint['function'];
        if (isset($stackPoint['class']) and isset($stackPoint['type'])) {
            $function_name = $stackPoint['class'] . $stackPoint['type'] . $function_name;
        }
        $result[] = sprintf($traceline, $key, $stackPoint['file'], $stackPoint['line'], $function_name, implode(', ', $stackPoint['args']));
    }
    $result[] = '<td>' . ++$key . '</td><td>{main}</td><td></td>';
    $msg = sprintf($msg, get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine(), implode("</tr><tr>\n", $result), $exception->getFile(), $exception->getLine());
    $msg = '<style>' . $styles . '</style>' . $msg;
    echo "<div id='error-{$code}'>" . $msg . "</div>";
};
set_exception_handler($handler);
register_shutdown_function(function () use($handler) {
    $error = error_get_last();
    if ($error !== NULL) {
        ob_end_clean();
        $exception = new ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']);
        $handler($exception);
    }
});
Core::DI()['router'] = Core::DI()->share(function ($c) {
    Loader::add('singleton');
    Loader::add('router');
    return Router::instance();
});
$router = Core::DI()['router'];
Loader::autoload();
Loader::add('routing');
$router->init();
$controller_class = $router->getController();
$controller = new $controller_class();