Example #1
0
    public static function init(){
        ob_start();

        self::$request = new Request();
        Router::init();
        Router::route();
    }
 public function index()
 {
     // Taken from repos
     # The DOC_ROOT and APP_PATH constant have to happen in the actual app
     # Document root, ex: /path/to/home/app.com/../ (uses ./ on CLI)
     define('DOC_ROOT', empty($_SERVER['DOCUMENT_ROOT']) ? './' : realpath($_SERVER['DOCUMENT_ROOT']) . '/../');
     # App path, ex: /path/to/home/app.com/
     define('APP_PATH', realpath(dirname(__FILE__)) . '/');
     # Environment
     require_once DOC_ROOT . 'environment.php';
     # Where is core located?
     define('CORE_PATH', $_SERVER['DOCUMENT_ROOT'] . "/../core/");
     # Load app configs
     require APP_PATH . "/config/config.php";
     require APP_PATH . "/config/feature_flags.php";
     # Bootstrap
     require CORE_PATH . "bootstrap.php";
     # Routing
     Router::$routes = array('/' => '/index');
     # Match requested uri to any routes and instantiate controller
     Router::init();
     # Display environment details
     require CORE_PATH . "environment-details.php";
     echo "This is the index page";
 }
 /**
  * It processes the request and connects the necessary classes and methods
  * @access public
  * @static
  * @return void
  */
 public static function run()
 {
     require_once ROOT . '/core/Loader.php';
     $autoload = new Loader();
     $registry = Registry::getInstance();
     $router = new Router($registry->getObject('request'));
     $router->init();
 }
Example #4
0
 /**
  * Routing defaults 
  *
  * app: Admin
  * class: Admin
  * method: user()
  * args: /my/extra/args
  * domain: meagr.com
  * subdomain: member.
  * 
  * @return array
  */
 public static function routes()
 {
     return array('home' => array('uri' => '__HOME__', 'pattern' => '\\Meagr\\Controller::GET_index'), '404' => array('uri' => '__404__', 'pattern' => '\\Meagr\\Controller::GET_404'), 'mvc' => array('uri' => '{domain}/{class}/{method}/', 'pattern' => '\\{modules}\\{controllers}\\{class}::{method}'), 'hmvc' => array('uri' => '{domain}/{class}/{method}/', 'pattern' => '\\{modules}\\{class}\\{controllers}\\{class}::{method}'), 'subcontroller' => array('uri' => '{domain}/{class}/{method}/', 'pattern' => '\\{modules}\\{class}\\{controllers}\\{subclass}::{submethod}'), 'subdomain' => array('uri' => '{subdomain}.{domain}/{class}/{method}/', 'pattern' => '\\{modules}\\{subdomain}\\{class}\\{controllers}\\{class}::{method}', 'filter' => function ($object, $args = null) {
         // instantiate our router singleton
         $router = Router::init();
         //check if there is a {class} value set
         if ($object->routeMapKeyExists('{class}') === false or $router->getRouteMap('{class}') == '/') {
             //get the subdomain thats been set in the url and the config
             $subdomain = $router->getRouteMap('{subdomain}');
             //if not, set it to the subdomain
             $router->setRouteMap('{class}', $subdomain);
             //lets not double up
             $router->setRouteMap('{subdomain}', '');
             //make the pattern namespace compatible
             $object = Router::namespaceRoutePattern($object);
             //update the pattern
             $object = $router->translatePattern($object);
             //set the class back to empty
             $router->setRouteMap('{class}', '');
             $object->uri_mapped = rtrim($object->uri_mapped, '/');
         }
         //return our object
         return $object;
     }), 'pages' => array('uri' => '{domain}/{args}', 'pattern' => '\\{modules}\\{controllers}\\Page::{args}', 'filter' => function ($object, $args = null) {
         //if we have no args, just return as we dont need to do anything
         if (!is_array($args) or empty($args)) {
             return $object;
         }
         // instantiate our router singleton
         $router = Router::init();
         //if we have arguments, get the first
         $page = $args[0];
         //create the string
         $args_string = implode('/', $args);
         //unset the first
         unset($args[0]);
         //reorder the remaining
         sort($args);
         //set the router route map arg to be our page
         $router->setRouteMap('{args}', $page);
         //translate the pattern
         $object = $router->translatePattern($object);
         //namespace the pattern
         $object = Router::namespaceRoutePattern($object);
         //trim the uri
         $object->uri_mapped = rtrim($object->uri_mapped, '/');
         //put the args back on the url for matching
         $router->setRouteMap('{args}', $args_string);
         //...and translate
         $object = $router->translateUri($object);
         //set the new pattern, minus the argument string, instead use the first argument
         $object->setMappedPattern(str_replace($args_string, $page, $object->getMappedPattern()));
         $object->setMappedUri($object->uri_mapped);
         //return
         return $object;
     }));
 }
 public static function init()
 {
     if (!self::$app) {
         $config = Autoload::load('App\\config');
         self::$app = new self($config);
         Autoload::init();
         $modules = self::app()->getConfig('Modules');
         foreach ($modules as $item) {
             $module = 'Modules/' . $item;
             Autoload::load($module, 1);
         }
         Session::init();
         Router::init();
     }
 }
Example #6
0
 public function run($config)
 {
     Conf::init($config);
     //设置app路由
     if ($_SERVER['REQUEST_URI'] != "/") {
         $server_request_uri = parse_url($_SERVER['REQUEST_URI']);
         $domainInfo = Router::init()->parseDomain($server_request_uri['path'], Conf::init()->getConf("ROUTER"), Conf::init()->getConf("ROUTER")['default']);
         Conf::init()->setAppInfo($domainInfo);
         //注册应用地址
     }
     Autoloader::register(Conf::init()->getAppPath());
     //获取路由表
     $routers = Conf::init()->getRouter();
     //解析url路径
     $actArr = array();
     if ($_SERVER['REQUEST_URI'] === "/") {
         $actArr = Router::init()->getDefaultAct();
     } else {
         $server_request_uri = parse_url($_SERVER['REQUEST_URI']);
         $actArr = Router::init()->parse($server_request_uri['path'], $routers);
     }
     Router::init()->load(Conf::init()->getAppPath(), $actArr);
 }
Example #7
0
                return 'audio/mpeg';
            case 'ogg':
                return 'audio/ogg';
            case 'ra':
                return 'audio/x-realaudio';
            case '3gpp':
            case '3gp':
                return 'video/3gpp';
            case 'mpeg':
            case 'mpg':
                return 'video/mpeg';
            case 'mp4':
                return 'video/mp4';
            case 'mov':
                return 'video/quicktime';
            case 'flv':
                return 'video/x-flv';
            case 'mng':
                return 'video/x-mng';
            case 'asx':
            case 'asf':
                return 'video/x-ms-asf';
            case 'wmv':
                return 'video/x-ms-wmv';
            default:
                return 'application/octet-stream';
        }
    }
}
Router::init();
Example #8
0
define('API_DIR', BASE_DIR . 'api' . DIRECTORY_SEPARATOR);
define('MODULES_DIR', BASE_DIR . 'modules' . DIRECTORY_SEPARATOR);
define('VIEWS_DIR', BASE_DIR . 'views' . DIRECTORY_SEPARATOR);
define('LOCALES_DIR', BASE_DIR . 'locales' . DIRECTORY_SEPARATOR);
require INC_DIR . 'Exceptions.php';
require INC_DIR . 'Val.php';
require INC_DIR . 'Config.php';
require INC_DIR . 'Localizer.php';
require INC_DIR . 'Router.php';
require INC_DIR . 'ControllerDispatcher.php';
Config::load(CONFIG_DIR . 'cfg.json');
$baseUrl = Config::get('baseurl');
if (!$baseUrl) {
    throw new \Exception('Invalid configuration. Missing "baseurl" definition.');
}
Localizer::load(LOCALES_DIR);
Router::init($baseUrl);
/* Setup propel
---------------------------------------------*/
set_include_path(get_include_path() . PATH_SEPARATOR . ENTITIES_CLASSES_DIR . LIB_DIR . PATH_SEPARATOR . BASE_DIR . PATH_SEPARATOR);
require_once LIB_DIR . '/propel/runtime/lib/Propel.php';
try {
    \Propel::init(ENTITIES_DIR . 'build' . DIRECTORY_SEPARATOR . 'conf' . DIRECTORY_SEPARATOR . PROJECT_NAME . '-conf.php');
    \Propel::getDB()->setCharset(\Propel::getConnection(), 'UTF8');
    \Transaction::initAmounts(Config::get('amounts', TYPE_ARRAY), Config::get('member_fee', TYPE_FLOAT), Config::get('base_currency'));
} catch (\Exception $e) {
    // Do NOT output stacktrace because it holds the plain pg password.
    echo $e->getMessage();
    error_log($e->__toString());
    exit;
}
Example #9
0
<?php

//if (session_id==""){
session_start();
//}
//error_reporting(0);
$dir = dirname(__FILE__);
$dir = str_replace("\\", "/", $dir);
$xmldir = "D:/H1 PSL/virtu/xml/query/";
define("LOCAL_DIR", $dir);
define("XML_DIR", $xmldir);
require_once LOCAL_DIR . "/core/Router.php";
$objRouter = new Router();
$objRouter->init();
Example #10
0
require INC_DIR . 'Exceptions.php';
require INC_DIR . 'Val.php';
require INC_DIR . 'Config.php';
require INC_DIR . 'Localizer.php';
require INC_DIR . 'Router.php';
require INC_DIR . 'ControllerDispatcher.php';
Config::load(defined('CONFIG_FILE_PATH') ? CONFIG_FILE_PATH : CONFIG_DIR . 'cfg.php');
$baseUrl = Config::get('baseurl');
if (!$baseUrl) {
    throw new \Exception('Invalid configuration. Missing "baseurl" definition.');
}
// $basePath = Config::get('basepath');
// if ( !$basePath )
//   throw new \Exception('Invalid configuration. Missing "basepath" definition.');
Localizer::load(LOCALES_DIR);
Router::init($baseUrl, '');
/* Setup propel
---------------------------------------------*/
set_include_path(get_include_path() . PATH_SEPARATOR . ENTITIES_CLASSES_DIR . LIB_DIR . PATH_SEPARATOR . BASE_DIR . PATH_SEPARATOR);
require_once LIB_DIR . '/propel/runtime/lib/Propel.php';
try {
    \Propel::init(ENTITIES_DIR . 'build' . DIRECTORY_SEPARATOR . 'conf' . DIRECTORY_SEPARATOR . PROJECT_NAME . '-conf.php');
    \Propel::getDB()->setCharset(\Propel::getConnection(), 'UTF8');
    \Transaction::initAmounts(Config::get('amounts', TYPE_ARRAY), Config::get('member_fee', TYPE_FLOAT), Config::get('base_currency'));
} catch (\Exception $e) {
    // Do NOT output stacktrace because it holds the plain pg password.
    echo $e->getMessage();
    error_log($e->__toString());
    exit;
}
define('BOOTSTRAP_DONE', true);
Example #11
0
 /**
  * returns the value of the objects route_map key
  *
  * @param key string The key of the route map array
  * 
  * @return mixed[string|array]
  */
 public function routeMapKeyExists($key)
 {
     //get our singleton object
     $router = Router::init();
     return trim($router->getRouteMap($key)) !== '' ? true : false;
 }
<?php

include '_lib/router.php';
$router = new Router();
$controller = $router->get_controller();
$param = $router->get_param();
$router->init($controller, $param);
Example #13
0
 /**
  * @brief init LogX 全局初始化方法
  *
  * @return void
  */
 public static function init()
 {
     // 输出 Logo
     if (isset($_GET['591E-D5FC-8065-CD36-D3E8-E45C-DB86-9197'])) {
         Response::logo();
     }
     // 非 DEBUG 模式下关闭错误输出
     if (defined('LOGX_DEBUG')) {
         error_reporting(E_ALL);
     } else {
         error_reporting(0);
     }
     // 设置自动载入函数
     function __autoLoad($className)
     {
         if (substr($className, -7) == 'Library' && is_file(LOGX_LIB . $className . '.php')) {
             @(require_once LOGX_LIB . $className . '.php');
         }
     }
     // 设置错误与异常处理函数
     set_error_handler(array(__CLASS__, 'error'));
     set_exception_handler(array(__CLASS__, 'exception'));
     // 运行环境检查
     if (!version_compare(PHP_VERSION, '5.0.0', '>=')) {
         throw new LogXException(sprintf(_t('LogX needs PHP 5.0.x or higher to run. You are currently running PHP %s.'), PHP_VERSION));
     }
     if (!version_compare(PHP_VERSION, '5.2.0', '>=')) {
         // 针对低版本 PHP 的兼容代码
         @(require_once LOGX_CORE . 'Compat.php');
     }
     // 设置语言
     if (defined('LOGX_LANGUAGE')) {
         Language::set(LOGX_LANGUAGE);
     } else {
         Language::set('zh-cn');
     }
     // 预编译核心文件
     global $coreFiles;
     if (!defined('LOGX_DEBUG') && !file_exists(LOGX_CACHE . '~core.php')) {
         Compile::build(LOGX_CACHE, $coreFiles, 'core');
     } elseif (!defined('LOGX_DEBUG')) {
         $file_time = filemtime(LOGX_CACHE . '~core.php');
         foreach ($coreFiles as $file) {
             if (filemtime($file) > $file_time) {
                 Compile::build(LOGX_CACHE, $coreFiles, 'core');
                 break;
             }
         }
     }
     self::$_globalVars = array('RUN' => array('TIME' => microtime(TRUE), 'MEM' => function_exists('memory_get_usage') ? memory_get_usage() : 0, 'LANG' => 'zh-cn'), 'SYSTEM' => array('OS' => PHP_OS, 'HTTP' => Request::S('SERVER_SOFTWARE', 'string'), 'PHP' => PHP_VERSION, 'MYSQL' => ''), 'SUPPORT' => array('MYSQL' => function_exists('mysql_connect'), 'GD' => function_exists('imagecreate'), 'MEMCACHE' => function_exists('memcache_connect'), 'SHMOP' => function_exists('shmop_open'), 'GZIP' => function_exists('ob_gzhandler'), 'TIMEZONE' => function_exists('date_default_timezone_set'), 'AUTOLOAD' => function_exists('spl_autoload_register')), 'INI' => array('ALLOW_CALL_TIME_PASS_REFERENCE' => ini_get('allow_call_time_pass_reference'), 'MAGIC_QUOTES_GPC' => ini_get('magic_quotes_gpc'), 'REGISTER_GLOBALS' => ini_get('register_globals'), 'ALLOW_URL_FOPEN' => ini_get('allow_url_fopen'), 'ALLOW_URL_INCLUDE' => ini_get('allow_url_include'), 'SAFE_MODE' => ini_get('safe_mode'), 'MAX_EXECUTION_TIME' => ini_get('max_execution_time'), 'MEMORY_LIMIT' => ini_get('memory_limit'), 'POST_MAX_SIZE' => ini_get('post_max_size'), 'FILE_UPLOADS' => ini_get('file_uploads'), 'UPLOAD_MAX_FILESIZE' => ini_get('upload_max_filesize'), 'MAX_FILE_UPLOADS' => ini_get('max_file_uploads')));
     // 清除不需要的变量,防止变量注入
     $defined_vars = get_defined_vars();
     foreach ($defined_vars as $key => $value) {
         if (!in_array($key, array('_POST', '_GET', '_COOKIE', '_SERVER', '_FILES'))) {
             ${$key} = '';
             unset(${$key});
         }
     }
     // 对用户输入进行转义处理
     if (!get_magic_quotes_gpc()) {
         $_GET = self::addSlashes($_GET);
         $_POST = self::addSlashes($_POST);
         $_COOKIE = self::addSlashes($_COOKIE);
     }
     // 开启输出缓存
     if (defined('LOGX_GZIP') && self::$_globalVars['SUPPORT']['GZIP']) {
         ob_start('ob_gzhandler');
     } else {
         ob_start();
     }
     // 连接到数据库
     Database::connect(DB_HOST, DB_USER, DB_PWD, DB_NAME, DB_PCONNECT);
     self::$_globalVars['SYSTEM']['MYSQL'] = Database::version();
     // 设定时区
     if (self::$_globalVars['SUPPORT']['TIMEZONE']) {
         date_default_timezone_set(OptionLibrary::get('timezone'));
     }
     // 连接到缓存
     Cache::connect(CACHE_TYPE);
     // 初始化路由表
     Router::init();
     // 初始化主题控制器
     Theme::init();
     // 初始化 Plugin
     Plugin::initPlugins();
     // 初始化全局组件
     Widget::initWidget('Global');
     Widget::initWidget('Widget');
     Widget::initWidget('Page');
     Widget::initWidget('User');
     // 尝试自动登录
     Widget::getWidget('User')->autoLogin();
     // 启动路由分发
     Router::dispatch();
 }