shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

router.php (1457B)


      1 <?php
      2 /**
      3  * @package		OpenCart
      4  * @author		Daniel Kerr
      5  * @copyright	Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/)
      6  * @license		https://opensource.org/licenses/GPL-3.0
      7  * @link		https://www.opencart.com
      8 */
      9 
     10 /**
     11 * Router class
     12 */
     13 final class Router {
     14 	private $registry;
     15 	private $pre_action = array();
     16 	private $error;
     17 	
     18 	/**
     19 	 * Constructor
     20 	 *
     21 	 * @param	object	$route
     22  	*/
     23 	public function __construct($registry) {
     24 		$this->registry = $registry;
     25 	}
     26 	
     27 	/**
     28 	 * 
     29 	 *
     30 	 * @param	object	$pre_action
     31  	*/	
     32 	public function addPreAction(Action $pre_action) {
     33 		$this->pre_action[] = $pre_action;
     34 	}
     35 
     36 	/**
     37 	 * 
     38 	 *
     39 	 * @param	object	$action
     40 	 * @param	object	$error
     41  	*/		
     42 	public function dispatch(Action $action, Action $error) {
     43 		$this->error = $error;
     44 
     45 		foreach ($this->pre_action as $pre_action) {
     46 			$result = $this->execute($pre_action);
     47 
     48 			if ($result instanceof Action) {
     49 				$action = $result;
     50 
     51 				break;
     52 			}
     53 		}
     54 
     55 		while ($action instanceof Action) {
     56 			$action = $this->execute($action);
     57 		}
     58 	}
     59 	
     60 	/**
     61 	 * 
     62 	 *
     63 	 * @param	object	$action
     64 	 * @return	object
     65  	*/
     66 	private function execute(Action $action) {
     67 		$result = $action->execute($this->registry);
     68 
     69 		if ($result instanceof Action) {
     70 			return $result;
     71 		} 
     72 		
     73 		if ($result instanceof Exception) {
     74 			$action = $this->error;
     75 			
     76 			$this->error = null;
     77 			
     78 			return $action;
     79 		}
     80 	}
     81 }