Guest User

Untitled

a guest
Apr 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.90 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($classPrefix, $classDefault, $settings)
  21.     {
  22.            
  23.             Loader::Start();
  24.  
  25.             try{
  26.                
  27.                 Db_Transaction::open($settings);                
  28.  
  29.                 $router = new Helpers_Router();
  30.                 $router->get('class');
  31.  
  32.                 $class   = $router->getParam('class')  ? $classPrefix.ucfirst($router->getParam('class'))  : $classPrefix.$classDefault;
  33.                 $method  = $router->getParam('method') ? $router->getParam('method') : 'index';
  34.                
  35.                
  36.                 //Rota para o Controle de produtos
  37.                 if( $class == 'PublicProdutos' ) $method = 'index';
  38.  
  39.                
  40.                 $class  = str_replace("-", "_", $class);
  41.                 $method = str_replace("-", "_", $method);
  42.  
  43.                 if(!class_exists($class))
  44.                       $class = 'PublicPagina';
  45.  
  46.                 $controller = new $class;
  47.                 $controller->onLoad();
  48.                
  49.                 if(!method_exists($controller, $method))
  50.                   throw new Exception('404M');
  51.                  
  52.                   call_user_func(array($controller, $method));
  53.                   Db_Transaction::close();      
  54.                
  55.             }catch(Exception $exe){
  56.                
  57.                 $error = $exe->getTraceAsString();
  58.                
  59.                 $controller = new PublicError($error);
  60.                 $controller->index();
  61.                 Db_Transaction::rollback();
  62.             }
  63.     }
  64. }
  65. ?>
Add Comment
Please, Sign In to add comment