コード例 #1
0
ファイル: App.class.php プロジェクト: discophp/framework
 /**
  * Set up the application path, domain, configs, services, factories, 
  *
  *
  * @param null|string $path Absolute path to root of the project.
  * @param null|string $domain The domain name the app is serving.
  */
 public function __construct($path = null, $domain = null)
 {
     //construct the PimpContainer
     parent::__construct();
     //Are we running in CLI mode?
     if (php_sapi_name() == 'cli') {
         $_SERVER['SERVER_NAME'] = null;
         if ($path === null) {
             $this->path = dirname(dirname(array_pop(debug_backtrace())['file']));
         } else {
             $this->path = $path;
         }
         //el
         $this->cli = true;
         global $argv;
         if (isset($argv[1]) && $argv[1] == 'routes') {
             \Disco\classes\Router::$base = '\\Disco\\manage\\Router';
         }
         //if
     } else {
         if ($path === null) {
             $this->path = dirname($_SERVER['DOCUMENT_ROOT']);
         } else {
             $this->path = $path;
         }
     }
     //el
     //a little magic
     $this['App'] = $this;
     self::$app = $this['App'];
     //register the default configuration options
     $this->registerConfig($this->path . $this->configDir . 'config.php');
     //register the dev configuration options if necessary
     if ($this->config('DEV_MODE')) {
         $this->registerConfig($this->path . $this->configDir . 'dev.config.php');
     }
     //if
     //regiser the default services into the container
     $this->registerServices($this->path . $this->configDir . 'services.php');
     //regiser the default factories into the container
     $this->registerFactories($this->path . $this->configDir . 'factories.php');
     //force the registery of the Router factory.
     $this->makeFactory('Router', function () {
         return \Disco\classes\Router::factory();
     });
     if ($domain === null) {
         if ($this->configKeyExists('DOMAIN') && $this->config('DOMAIN')) {
             $domain = $this->config('DOMAIN');
         } else {
             $domain = $_SERVER['SERVER_NAME'];
         }
         //el
     }
     //if
     if (substr($domain, 0, 4) != 'http') {
         $domain = 'http://' . $domain;
     }
     //if
     if (!empty($_SERVER['HTTPS']) && substr($domain, 0, 5) != 'https') {
         $domain = str_replace('http://', 'https://', $domain);
     }
     //if
     $this->domain = $domain;
 }
コード例 #2
0
ファイル: Router.class.php プロジェクト: discophp/framework
 /**
  * Private method for setting and getting whether we have a route match yet. Big difference is that this method 
  * does not call `static::procesAvailableRoutes()` unlike its public counter part `routeMatch()`. The reason 
  * the public method calls `static::processAvailableRoutes()` is so that say a Router was created, and 
  * immeditatly after the a call is made to `Router::routeMatch()` to check if the last route satisifed the 
  * request, well if the `process()` method wasn't called on it directly, it wont be processed until another 
  * Router is created or the end of the application method `tearDown()` is called. So to make sure we respond 
  * with the correct anwser we need to make sure any un-processed routes are processed first.
  *
  * @param  boolean $m
  *
  * @return boolean
  */
 private static function __routeMatch($m = null)
 {
     if ($m !== null) {
         if (static::$routeMatch === false && $m === true) {
             \App::make('Router', '\\Disco\\classes\\MockBox');
         } else {
             if (static::$routeMatch === true && $m === false) {
                 \App::makeFactory('Router', function () {
                     return \Disco\classes\Router::factory();
                 });
             }
         }
         //el
         static::$routeMatch = $m;
     }
     //if
     return static::$routeMatch;
 }