Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 public function testPaginate()
 {
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $_SERVER['REQUEST_URI'] = '/products/software';
     $p = 0;
     Router::paginate('/products/software', function ($page) use(&$p) {
         $p = $page;
         return false;
     })->process();
     $this->assertEquals(1, $p);
     $_SERVER['REQUEST_URI'] = '/products/software/page/9';
     $p = 0;
     Router::paginate('/products/software', function ($page) use(&$p) {
         $p = $page;
         return false;
     })->process();
     $this->assertEquals(9, $p);
     $_SERVER['REQUEST_URI'] = '/products/software/page/3?search=disco&limit=10';
     $_SERVER['QUERY_STRING'] = 'search=disco&limit=10';
     //$_SERVER['REQUEST_URI'] = '/products/software/page/3';
     $p = 0;
     $cat = '';
     Router::paginate('/products/{category}', function ($category, $page) use(&$cat, &$p) {
         $cat = $category;
         $p = $page;
         return false;
     })->allowURLParameters(array('search', 'limit'))->where('category', 'alpha_nospace')->process();
     $this->assertEquals('software', $cat);
     $this->assertEquals(3, $p);
     \Disco\classes\Router::$paginateCurrentPage = 1;
 }