Exemplo n.º 1
0
 /**
  * Load set template.
  * 
  * @return string File resource
  * @throws \Exception 
  */
 private function loadTemplate()
 {
     $file = \Loader::search('template' . DIRECTORY_SEPARATOR . $this->template);
     if (!$file) {
         throw new \Exception('Invalid template name: ' . $this->template);
     }
     return $file;
 }
Exemplo n.º 2
0
 /**
  * Load the template provided in input data.
  * @param type $templateDirectory
  * @param type $template
  * @return type
  * @throws \Exception
  */
 private function loadTemplate($templateDirectory, $template)
 {
     // Get type-specific suffix prefix.
     $suffixPrefix = $this->getSuffixPrefix();
     $path = $templateDirectory . DIRECTORY_SEPARATOR . $template . $suffixPrefix . FILE_EXTENSION;
     $file = \Loader::search($path, FALSE);
     if ($file === FALSE) {
         throw new \Exception("Invalid template name: '{$template}'. Could not find file '{$path}'.");
     }
     return $file;
 }
Exemplo n.º 3
0
 /**
  * Generates template output.
  * Extracts $this->_data into local namespace so that it can be
  * interpolated into the output generated by template.
  */
 public function display_content()
 {
     // Search for the template
     $file = Loader::search('template', $this->template);
     // We need to fetch file manually to allow local variable namespace.
     if ($file !== FALSE) {
         // Get template variables into local namespace.
         extract($this->_data);
         require $file;
         return TRUE;
     }
     throw new Exception('Invalid template name');
 }
Exemplo n.º 4
0
 /**
  * Load configuration file.
  * 
  * @param type $file
  */
 private static function loadConfig($file)
 {
     $filename = Loader::search('config' . DIRECTORY_SEPARATOR . $file);
     if ($filename) {
         // Fetch valid configuration array.
         // Cache will prevent multiple includes.
         // In the event that it does not, honor the load.
         include $filename;
         // Cache configuration contents.
         if (isset($config) && is_array($config)) {
             self::set($file, $config);
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Determines the appropriate controller, method, and arguments 
  * from the current URI request.
  * Where necessary, defaults will be employed.
  * Values are stored in local static members for use by the core.
  */
 public static function current()
 {
     $current = self::getRequestPath();
     // Are we being run from command line?
     if (PHP_SAPI === 'cli') {
         // $argv and $argc are disabled by default in some configurations.
         $argc = isset($argc) ? $argc : $_SERVER['argc'];
         if ($argc > 0) {
             $args = isset($argv) ? $argv : $_SERVER['argv'];
             // Merge all cli arguments as if they were in a uri from web context.
             $current = implode('/', $args);
         } else {
             $current = self::getRequestPath();
         }
     }
     // Remove dot paths
     $current = preg_replace('#\\.[\\s./]*/#', '', $current);
     // Remove leading slash
     $current = ltrim($current, '/');
     // Reduce multiple slashes
     $current = preg_replace('#//+#', '/', $current);
     // Remove front controller from URI if present (depends on variable used)
     $frontController = \Config::get('core.front_controller') . FILE_EXTENSION;
     if (substr($current, 0, strlen($frontController)) == $frontController) {
         $current = substr($current, strlen($frontController));
     }
     // Remove any remaining leading/trailing slashes
     $current = trim($current, '/');
     // Check for rewrites matching configuration values.
     $matched = $current;
     $rewrites = \Config::get('rewrites');
     if (!empty($rewrites)) {
         foreach ($rewrites as $match => $replace) {
             $match = trim($match, '/');
             // Exact match?
             if ($match == $current) {
                 $matched = $replace;
             } elseif (preg_match('#^' . $match . '$#u', $current)) {
                 if (strpos($replace, '$')) {
                     // Replacement requires arguments that were parsed during match.
                     $matched = preg_replace('#^' . $match . '$#u', $replace, $current);
                 } else {
                     // Found match, no parsed arguments required.
                     $matched = $replace;
                 }
             }
         }
     }
     $current = $matched;
     $parts = array();
     if (strlen($current) > 0) {
         $parts = explode('/', $current);
     }
     if (empty($parts)) {
         self::$controller = \Config::get('core.default_controller');
     } else {
         $controller = '';
         while (count($parts)) {
             $controller .= array_shift($parts);
             if (Loader::search('controller' . DIRECTORY_SEPARATOR . $controller)) {
                 self::$controller = $controller;
                 if (count($parts)) {
                     self::$method = array_shift($parts);
                 }
                 if (count($parts)) {
                     self::$arguments = $parts;
                 }
             } else {
                 $controller .= DIRECTORY_SEPARATOR;
             }
         }
     }
     if (empty(self::$method)) {
         self::$method = \Config::get('core.default_controller_method');
     }
 }