Advertisement
vafrcor

Installation Controller based on Laravel

Jan 12th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.93 KB | None | 0 0
  1. <?php
  2. class InstallerController extends BaseController {
  3.     public $now_step='step0';
  4.     public $av_steps=array();
  5.     public $data=array();
  6.     public $install_urls=array();
  7.     public $now_controller='';
  8.     public $now_action='';
  9.    
  10.     public function __construct(){
  11.         $this->_getRouterInfo();
  12.        
  13.         $this->av_steps = array("step0" => "/main", "step1" => "/step/1", "step2" => "/step/2", "step3" => "/step/3", "finish" => "/finish", "cancel" => "/cancel");;
  14.        
  15.         // Available post urls
  16.         $base_url_install= 'http://project.dev/install';
  17.         $this->install_urls['step0']=$base_url_install.''.$this->av_steps['step0'];
  18.         $this->install_urls['step1']=$base_url_install.''.$this->av_steps['step1'];
  19.         $this->install_urls['step2']=$base_url_install.''.$this->av_steps['step2'];
  20.         $this->install_urls['step3']=$base_url_install.''.$this->av_steps['step3'];
  21.         $this->install_urls['finish']=$base_url_install.''.$this->av_steps['finish'];
  22.         $this->install_urls['cancel']=$base_url_install.''.$this->av_steps['cancel'];
  23.        
  24.         $use_protection=1;
  25.         if(($this->now_action != "cancel") && ($use_protection == 1)){
  26.             // Check current step to the real step it has taken
  27.             if(Session::has('install_progress')){
  28.                 $this->now_step= Session::get('install_progress');
  29.                 if($this->now_step != $this->now_action){
  30.                     // If step not equal to now action, redirect to actual step action
  31.                     echo $this->now_action.' || '.$this->now_step;
  32.                     _pre_array(Session::all());
  33.                     exit("<br />=== Halt on construct ===");
  34.                 }
  35.                 else{
  36.                     // Correct step just let it pass
  37.                 }
  38.             }
  39.             else{
  40.                 Session::put('install_progress', 'step0');
  41.                 if($this->now_action != 'step0'){  
  42.                     header("Location: ". $this->install_urls['step0']);
  43.                     exit();
  44.                 }
  45.             }
  46.         }
  47.     }
  48.    
  49.     protected function _getRouterInfo(){   
  50.         $routeArray = Str::parseCallback(Route::currentRouteAction(), null);
  51.  
  52.         if(last($routeArray) != null){
  53.             // Remove 'controller' from the controller name.
  54.             $controller = str_replace('Controller', '', class_basename(head($routeArray)));
  55.  
  56.             // Take out the method from the action.
  57.             $action = str_replace(array('get', 'post', 'patch', 'put', 'delete'), '', last($routeArray));
  58.  
  59.             $this->now_controller = $controller;
  60.             $this->now_action = $action;
  61.         }
  62.     }
  63.    
  64.     public function step0(){
  65.         /* Installer Method Step Number 0 (Main) */
  66.         $this->data['site_doc_title']='Welcome';
  67.         $this->data['post_url'] = $this->install_urls['step0'];
  68.        
  69.         // Check POST method (validation)
  70.         if(Input::has('_basedom')){;
  71.             $in_data = Input::all();
  72.             $validator = Validator::make($in_data, array('_basedom' => "in:project.dev"));
  73.             if($validator->passes()){
  74.                 Session::put('install_progress', 'step1');
  75.                 header("Location: ". $this->install_urls['step1']);
  76.                 exit();
  77.             }
  78.             else{
  79.                 // not valid, should write error message here
  80.             }
  81.         }
  82.        
  83.         // Return View
  84.         return View::make('install.step0',$this->data);
  85.     }
  86.    
  87.     public function step1(){
  88.         /* Installer Method Step Number 1 */
  89.         $this->data['site_doc_title']='Welcome';
  90.         $this->data['post_url'] = $this->install_urls['step1'];
  91.         $this->data['cancel_url'] = $this->install_urls['cancel'];
  92.        
  93.         // Return View
  94.         return View::make('install.step1',$this->data);
  95.     }
  96.    
  97.     public function step2(){
  98.         // return "Installer Method Step Number 2";
  99.         // _pre_array(Session::all());
  100.         // echo '<br >'.Session::get('install_progress');
  101.     }
  102.    
  103.     public function step3(){
  104.         // return "Installer Method Step Number 3";
  105.         // _pre_array(Session::all());
  106.         // echo '<br >'.Session::get('install_progress');
  107.     }
  108.    
  109.     public function finish(){
  110.         // return "Installer Method Step Finish";
  111.         // _pre_array(Session::all()); 
  112.     }
  113.    
  114.     public function cancel(){
  115.         $this->data['site_doc_title']='Cancelled';
  116.        
  117.         // Remove session of installation progress
  118.         Session::forget('install_progress');
  119.  
  120.         // Return View
  121.         return View::make('install.cancel',$this->data);
  122.     }
  123. }
  124. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement