| 
									
										
										
										
											2010-02-26 14:49:12 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @copyright NetMonsters <team@netmonsters.ru> | 
					
						
							|  |  |  |  * @link http://netmonsters.ru | 
					
						
							|  |  |  |  * @package Majestic | 
					
						
							|  |  |  |  * @subpackage app | 
					
						
							|  |  |  |  * @since 2010-02-25 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | abstract class Action | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-10-13 14:55:06 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-14 12:12:17 +00:00
										 |  |  |     protected $template; | 
					
						
							| 
									
										
										
										
											2011-10-13 14:55:06 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-14 12:12:17 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @var PHPView | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected $view; | 
					
						
							| 
									
										
										
										
											2011-10-13 14:55:06 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-26 14:49:12 +00:00
										 |  |  |     public function __construct() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-03-14 12:12:17 +00:00
										 |  |  |         $this->view = FrontController::getInstance()->getView(); | 
					
						
							| 
									
										
										
										
											2010-02-26 14:49:12 +00:00
										 |  |  |         $this->extractParams(); | 
					
						
							|  |  |  |         $this->execute(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-10-13 14:55:06 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-26 14:49:12 +00:00
										 |  |  |     protected function extractParams() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-03-07 19:54:09 +00:00
										 |  |  |         foreach (Env::getParam() as $name => $value) { | 
					
						
							|  |  |  |             if (is_string($name)) { | 
					
						
							|  |  |  |                 $this->$name = $value; | 
					
						
							| 
									
										
										
										
											2010-02-26 14:49:12 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-10-13 14:55:06 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-26 14:49:12 +00:00
										 |  |  |     abstract protected function execute(); | 
					
						
							| 
									
										
										
										
											2011-10-13 14:55:06 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-26 14:49:12 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Redirect | 
					
						
							| 
									
										
										
										
											2011-10-13 14:55:06 +04:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2010-02-26 14:49:12 +00:00
										 |  |  |      * @param mixed $url | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2010-03-15 21:06:36 +00:00
										 |  |  |     protected function redirect($url = null) | 
					
						
							| 
									
										
										
										
											2010-02-26 14:49:12 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-03-15 21:06:36 +00:00
										 |  |  |         header('Location: ' . (($url) ? $url : Env::getRequestUri())); | 
					
						
							| 
									
										
										
										
											2010-02-26 14:49:12 +00:00
										 |  |  |         exit(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-10-13 14:55:06 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-14 12:12:17 +00:00
										 |  |  |     protected function getTemplate() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $class = get_class($this); | 
					
						
							| 
									
										
										
										
											2011-10-13 14:55:06 +04:00
										 |  |  |         $template = ($this->template) ? $this->template : substr($class, 0, -6 /*strlen('Action')*/); | 
					
						
							| 
									
										
										
										
											2010-03-14 12:12:17 +00:00
										 |  |  |         $dir = array_slice(explode('/', Load::getFilePath($class)), -2, 1); | 
					
						
							|  |  |  |         return '/actions/' . array_pop($dir) . '/' . $template; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-10-13 14:55:06 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-14 12:12:17 +00:00
										 |  |  |     public function fetch() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->view->assignObject($this); | 
					
						
							|  |  |  |         return $this->view->fetch($this->getTemplate()); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-02-26 14:49:12 +00:00
										 |  |  | } |