Example #1
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;
 }
Example #2
0
 /**
  * The constructor takes a controller class name and method
  * and performs the prepares the App to be rendered via the html or json functions
  *
  * @param UserInterface $user  user instance
  * @param Input         $input input object
  *
  * @return void
  */
 public function __construct(UserInterface $user, Input $input)
 {
     // setting user
     $this->_user = $user;
     $this->_input = $input;
     $this->_controller = $input->getController();
     $this->_method = $input->getMethod();
     $this->_package = Package::getInstance();
     // checking permission & validity
     $permission = self::checkPermissions($user, $this->_controller, $this->_method);
     if ($permission === self::PERM_404) {
         $this->_controller = Config::get('environment.error.404.controller');
         $this->_method = Config::get('environment.error.404.method');
     } else {
         if ($permission === self::PERM_DENIED) {
             $this->_controller = Config::get('environment.error.403.controller');
             $this->_method = Config::get('environment.error.403.method');
         }
     }
 }
Example #3
0
<!DOCTYPE html>
<html><head><title><?php 
if (isset($title)) {
    echo $title;
}
?>
</title><?php 
$package = \Ali\Package::getInstance();
$package->generateMeta();
$package->generateStyle();
$package->generateCustomStyle();
$package->generateScript();
?>
</head><body><?php 
if (isset($content)) {
    echo $content;
}
$package->generateCustomScript();
?>
</body></html>