Пример #1
0
 /**
  * Get base-URL of the Phile installation
  *
  * @return string `scheme://host/path/phile-root`
  */
 public function getBaseUrl()
 {
     if (Registry::isRegistered('Phile_Settings')) {
         $config = Registry::get('Phile_Settings');
         if (!empty($config['base_url'])) {
             return $config['base_url'];
         }
     }
     $url = '';
     if (isset($this->server['PHP_SELF'])) {
         $url = preg_replace('/index\\.php(.*)?$/', '', $this->server['PHP_SELF']);
     }
     if (isset($this->server['HTTP_HOST'])) {
         $host = $this->server['HTTP_HOST'];
         $protocol = $this->getProtocol();
         $url = $protocol . '://' . $host . $url;
     }
     $url = rtrim($url, '/');
     return $url;
 }
Пример #2
0
 /**
  * reads the routing.json file and looks for matching routes<br /> 
  * The Get-Param `a` will be passed through in both cases
  * 
  * @access public
  * @return boolean
  */
 public function __construct()
 {
     // call the Routing Json building class to get the proper routing
     // @see config
     Registry::isRegistered('MVC_ROUTING_JSON_BUILDER') ? $sRoutingBuilder = Registry::get('MVC_ROUTING_JSON_BUILDER') : false;
     if (!isset($sRoutingBuilder)) {
         Error::addERROR('config MVC_ROUTING_JSON_BUILDER is not set.');
         return false;
     }
     $this->_oRoutingBuilder = new $sRoutingBuilder();
     $this->_sRoutingJson = $this->_oRoutingBuilder->getRoutingJson();
     $this->_aRouting = json_decode($this->_sRoutingJson, true);
     $this->_sRequestUri = Request::getInstance()->getRequestUri();
     // add path
     isset($this->_aRouting[$this->_sRequestUri]) ? $this->_aRouting[$this->_sRequestUri]['path'] = $this->_sRequestUri : false;
     // add class, method
     if (array_key_exists($this->_sRequestUri, $this->_aRouting)) {
         if (array_key_exists('query', $this->_aRouting[$this->_sRequestUri])) {
             // add Target Class
             parse_str($this->_aRouting[$this->_sRequestUri]['query'], $sQuery);
             $this->_aRouting[$this->_sRequestUri]['class'] = ucfirst($sQuery[Registry::get('MVC_GET_PARAM_MODULE')]) . '\\Controller\\' . ucfirst($sQuery[Registry::get('MVC_GET_PARAM_C')]);
             $this->_aRouting[$this->_sRequestUri]['method'] = Request::getInstance()->getMethod();
         }
     }
     Log::WRITE('routing table built by: ' . $sRoutingBuilder);
     Log::WRITE('routing handling done by: ' . Registry::get('MVC_ROUTING_HANDLING'));
     Log::WRITE('routes (cutout): ' . substr(preg_replace('/\\s+/', '', $this->_sRoutingJson), 0, 25) . ' [..]');
     if (false === filter_var($this->_oRoutingBuilder instanceof \MVC\MVCInterface\RouterJsonBuilder, FILTER_VALIDATE_BOOLEAN)) {
         /**
          * @todo ERROR
          */
         $sMsg = 'ERROR: <br />Make sure `' . $sRoutingBuilder . '` <b>implements</b> \\MVC\\MVCInterface\\RouterJsonBuilder';
         Error::addERROR($sMsg);
         Helper::STOP($sMsg);
     }
     return true;
 }
Пример #3
0
 /**
  * check the setup
  */
 protected function checkSetup()
 {
     /**
      * @triggerEvent before_setup_check this event is triggered before the setup check
      */
     Event::triggerEvent('before_setup_check');
     if (!Registry::isRegistered('templateVars')) {
         Registry::set('templateVars', []);
     }
     Event::triggerEvent('setup_check');
     /**
      * @triggerEvent after_setup_check this event is triggered after the setup check
      */
     Event::triggerEvent('after_setup_check');
 }
Пример #4
0
 public function testRegistryArrayObject()
 {
     $registry = Registry::getInstance();
     $registry['emptyArray'] = array();
     $registry['null'] = null;
     $this->assertTrue(isset($registry['emptyArray']));
     $this->assertTrue(isset($registry['null']));
     $this->assertFalse(isset($registry['noIndex']));
     $this->assertTrue(Registry::isRegistered('emptyArray'));
     $this->assertTrue(Registry::isRegistered('null'));
     $this->assertFalse(Registry::isRegistered('noIndex'));
 }
Пример #5
0
 public function getCache($which)
 {
     // do we already have the cache object in the Registry ?
     if (Registry::isRegistered('cache_' . $which)) {
         return Registry::get('cache_' . $which);
     } else {
         // get the config for our cache object
         $config = Registry::get('config');
         if (isset($config->cache->{$which}->handler)) {
             $cache = Cache::factory($config->cache->{$which}->handler, isset($config->cache->{$which}->params) ? $config->cache->{$which}->params : array(), isset($config->cache->{$which}->lifetime) ? $config->cache->{$which}->lifetime : Cache::DEFAULT_LIFETIME);
             return $cache;
         } else {
             throw new Exception('The cache handler "' . $which . '" is not set in config file');
         }
     }
 }
Пример #6
0
 /**
  * adds a key/value pair to registry
  * 
  * @access public
  * @static
  * @param string $sKey
  * @param string $sValue
  * @return void
  */
 public static function addToRegistry($sKey, $sValue)
 {
     !Registry::isRegistered('MVC_EVENT') ? Registry::set('MVC_EVENT', array()) : FALSE;
     $aMvcEvent = Registry::get('MVC_EVENT');
     $aMvcEvent[$sKey][] = $sValue;
     Registry::set('MVC_EVENT', $aMvcEvent);
 }
Пример #7
0
 /**
  * check the setup
  */
 protected function checkSetup()
 {
     /**
      * @triggerEvent before_setup_check this event is triggered before the setup check
      */
     Event::triggerEvent('before_setup_check');
     if (!Registry::isRegistered('templateVars')) {
         Registry::set('templateVars', []);
     }
     if (!isset($this->settings['encryptionKey']) || strlen($this->settings['encryptionKey']) == 0) {
         if ($this->router->getCurrentUrl() !== 'setup') {
             $this->response->redirect($this->router->url('setup'));
             return;
         }
     } else {
         if (is_file(CONTENT_DIR . 'setup.md')) {
             unlink(CONTENT_DIR . 'setup.md');
         }
     }
     /**
      * @triggerEvent after_setup_check this event is triggered after the setup check
      */
     Event::triggerEvent('after_setup_check');
 }
Пример #8
0
 /**
  * check page is running in ssl mode
  * 
  * @access public
  * @static
  * @return boolean 
  */
 public static function DETECTSSL()
 {
     if (Registry::isRegistered('MVC_SECURE_REQUEST')) {
         return Registry::get('MVC_SECURE_REQUEST');
     }
     return array_key_exists('HTTPS', $_SERVER) && strtolower($_SERVER['HTTPS']) !== 'off' || Registry::isRegistered('MVC_SSL_PORT') && $_SERVER['SERVER_PORT'] == Registry::get('MVC_SSL_PORT');
     return FALSE;
 }