Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class InstallerController extends BaseController {
- public $now_step='step0';
- public $av_steps=array();
- public $data=array();
- public $install_urls=array();
- public $now_controller='';
- public $now_action='';
- public function __construct(){
- $this->_getRouterInfo();
- $this->av_steps = array("step0" => "/main", "step1" => "/step/1", "step2" => "/step/2", "step3" => "/step/3", "finish" => "/finish", "cancel" => "/cancel");;
- // Available post urls
- $base_url_install= 'http://project.dev/install';
- $this->install_urls['step0']=$base_url_install.''.$this->av_steps['step0'];
- $this->install_urls['step1']=$base_url_install.''.$this->av_steps['step1'];
- $this->install_urls['step2']=$base_url_install.''.$this->av_steps['step2'];
- $this->install_urls['step3']=$base_url_install.''.$this->av_steps['step3'];
- $this->install_urls['finish']=$base_url_install.''.$this->av_steps['finish'];
- $this->install_urls['cancel']=$base_url_install.''.$this->av_steps['cancel'];
- $use_protection=1;
- if(($this->now_action != "cancel") && ($use_protection == 1)){
- // Check current step to the real step it has taken
- if(Session::has('install_progress')){
- $this->now_step= Session::get('install_progress');
- if($this->now_step != $this->now_action){
- // If step not equal to now action, redirect to actual step action
- echo $this->now_action.' || '.$this->now_step;
- _pre_array(Session::all());
- exit("<br />=== Halt on construct ===");
- }
- else{
- // Correct step just let it pass
- }
- }
- else{
- Session::put('install_progress', 'step0');
- if($this->now_action != 'step0'){
- header("Location: ". $this->install_urls['step0']);
- exit();
- }
- }
- }
- }
- protected function _getRouterInfo(){
- $routeArray = Str::parseCallback(Route::currentRouteAction(), null);
- if(last($routeArray) != null){
- // Remove 'controller' from the controller name.
- $controller = str_replace('Controller', '', class_basename(head($routeArray)));
- // Take out the method from the action.
- $action = str_replace(array('get', 'post', 'patch', 'put', 'delete'), '', last($routeArray));
- $this->now_controller = $controller;
- $this->now_action = $action;
- }
- }
- public function step0(){
- /* Installer Method Step Number 0 (Main) */
- $this->data['site_doc_title']='Welcome';
- $this->data['post_url'] = $this->install_urls['step0'];
- // Check POST method (validation)
- if(Input::has('_basedom')){;
- $in_data = Input::all();
- $validator = Validator::make($in_data, array('_basedom' => "in:project.dev"));
- if($validator->passes()){
- Session::put('install_progress', 'step1');
- header("Location: ". $this->install_urls['step1']);
- exit();
- }
- else{
- // not valid, should write error message here
- }
- }
- // Return View
- return View::make('install.step0',$this->data);
- }
- public function step1(){
- /* Installer Method Step Number 1 */
- $this->data['site_doc_title']='Welcome';
- $this->data['post_url'] = $this->install_urls['step1'];
- $this->data['cancel_url'] = $this->install_urls['cancel'];
- // Return View
- return View::make('install.step1',$this->data);
- }
- public function step2(){
- // return "Installer Method Step Number 2";
- // _pre_array(Session::all());
- // echo '<br >'.Session::get('install_progress');
- }
- public function step3(){
- // return "Installer Method Step Number 3";
- // _pre_array(Session::all());
- // echo '<br >'.Session::get('install_progress');
- }
- public function finish(){
- // return "Installer Method Step Finish";
- // _pre_array(Session::all());
- }
- public function cancel(){
- $this->data['site_doc_title']='Cancelled';
- // Remove session of installation progress
- Session::forget('install_progress');
- // Return View
- return View::make('install.cancel',$this->data);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement