Ejemplo n.º 1
0
 public function getTemplate($method = null)
 {
     $templates = $this->templates();
     $method = strtolower($method);
     if (isset($templates[$method])) {
         return $templates[$method];
     }
     return Config::get('environment.default_template');
 }
Ejemplo n.º 2
0
 protected function _view($view, array $data = array(), $toString = false)
 {
     // getting last context
     $prev_context = $this->_last_context;
     $context = debug_backtrace(false)[1];
     if (isset($context['class'])) {
         $this->_last_context = $context;
     }
     // building path location for absolute paths
     if ($view[0] === '/') {
         // do nothing
         $view = ltrim($view, '/');
     } else {
         // setting up include paths
         $paths = Config::get('environment.include_path');
         // building namespace preg_replace
         $patterns = array();
         $replace = array();
         foreach ($paths as $namespace => $path) {
             $patterns[] = '/^' . str_replace('\\', '\\\\', $namespace) . '/';
             $replace[] = $path . '/View/';
         }
         $view = str_replace('\\', '/', preg_replace($patterns, $replace, $this->_last_context['class'])) . '/' . $view;
     }
     // building file location from view name
     $path = $view . '.php';
     if (file_exists($path)) {
         // including php file of view
         ob_start();
         extract($data);
         include $path;
         $content = ob_get_clean();
         // including css and javascript do this after the view so dependencies work
         Package::getInstance()->get($view);
     } else {
         $dir = getcwd();
         throw new Exception("View not found ({$path}) in ({$dir})");
     }
     // returning last context to prior state
     $this->_last_context = $prev_context;
     // return method
     if ($toString) {
         return $content;
     }
     echo $content;
 }
Ejemplo n.º 3
0
 /**
  * this function is used to check the permissions of a given controller method combo
  *
  * @param UserInterface $user       Instance of user
  * @param string        $controller Controller Name
  * @param string        $method     Controller function name
  *
  * @return int
  */
 public static function checkPermissions(UserInterface $user, $controller, $method = null)
 {
     if ($method === null) {
         $method = Config::get('environment.default_method');
     }
     // validating controller & method
     if (!class_exists($controller, true) || !in_array('Ali\\Base\\ControllerInterface', class_implements($controller)) || !method_exists($controller, 'action' . $method)) {
         return self::PERM_404;
     }
     // getting controller permissions
     $controller_permissions = $controller::getPermissions($method);
     // checking permissions
     if (!$user->checkPermissions($controller_permissions)) {
         return self::PERM_DENIED;
     }
     // valid permissions
     return self::PERM_GRANTED;
 }
Ejemplo n.º 4
0
 public function getStyle($package)
 {
     // checking if we have already included this package
     if (!in_array($package, $this->_css_packages)) {
         // check for package requirements
         $packages = Config::get('package');
         if (isset($packages[$package]['requires'])) {
             foreach ($packages[$package]['requires'] as $required_package) {
                 $this->getStyle($required_package);
             }
         }
         // check for package configuration
         if (isset($packages[$package]['css'])) {
             foreach ($packages[$package]['css'] as $script) {
                 if (substr($script, 0, 4) !== 'http') {
                     $script = $this->_path . $script;
                 }
                 $this->linkStyle($script);
             }
         }
         // building file location from package name
         $path = $package . '.css';
         if (file_exists($path)) {
             // linking script
             $this->linkStyle($this->_path . $path);
         }
         // mark package as loaded
         $this->_css_packages[] = $package;
     }
 }