Guest User

Untitled

a guest
Jul 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.11 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * this class provides the methods for begin application
  5.  *
  6.  * @author Leonardo Poletto
  7.  * @version 1.0
  8.  * @category Application
  9.  */
  10. class Application {
  11.  
  12.     /*
  13.      * The construct method is marked as private, not to be built
  14.      */
  15.     private function  __construct() {}
  16.  
  17.        /*
  18.      * This Method Uses all methods this class
  19.      */
  20.     public static  function Run($classDefault, $settings)
  21.     {
  22.            
  23.             Loader::Start();
  24.  
  25.             try{
  26.                
  27.                 Db_Transaction::open($settings);                
  28.  
  29.                 $actions = $_GET;
  30.  
  31.                 $controller   = isset ($actions['controller']) &&  $actions['controller'] != null ? ucfirst($actions['controller']) : $classDefault;
  32.                 $action         = isset ($actions['action']) &&  $actions['action'] != null ? $actions['action'] : 'index';        
  33.                
  34.                 $controllerClassString = $controller.'Controller';
  35.                
  36.                 if( !isset($_SESSION['cadastroRevenda']['user']) && $controllerClassString != 'LoginController'){
  37.                     header('location:index.php?controller=login');
  38.                 }
  39.                
  40.                 if(!class_exists($controllerClassString))
  41.                     throw new Exception('404');
  42.  
  43.                 $controllerClass = new $controllerClassString;
  44.  
  45.                 if(!method_exists($controllerClass, $action.'Action'))
  46.                     throw new Exception('404');
  47.                
  48.                 call_user_func(array($controllerClass, $action.'Action'));  
  49.                 $controllerClass->view->render( $controller, $action);
  50.                
  51.                 Db_Transaction::close();          
  52.                
  53.             }catch(Exception $exe){
  54.                
  55.                 $controllerError = new ErrorController($exe->getMessage());
  56.                 $controllerError->indexAction();
  57.                 $controllerError->view->render('error' , 'index');
  58.                
  59.                
  60.                 Db_Transaction::rollback();
  61.             }
  62.        
  63.  
  64.     }
  65.  
  66.  
  67.  
  68. }
  69. ?>
Add Comment
Please, Sign In to add comment