A super easy PHP Framework for web development!
				https://github.com/exacti/phacil-framework
			
			
		
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					126 lines
				
				2.2 KiB
			
		
		
			
		
	
	
					126 lines
				
				2.2 KiB
			| 
								 
											7 years ago
										 
									 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								final class Action {
							 | 
						||
| 
								 | 
							
									protected $file;
							 | 
						||
| 
								 | 
							
									protected $class;
							 | 
						||
| 
								 | 
							
									protected $method;
							 | 
						||
| 
								 | 
							
									protected $args = array();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									public function __construct($route, $args = array()) {
							 | 
						||
| 
								 | 
							
										$path = '';
							 | 
						||
| 
								 | 
							
										
							 | 
						||
| 
								 | 
							
										$parts = explode('/', str_replace('../', '', (string)$route));
							 | 
						||
| 
								 | 
							
										
							 | 
						||
| 
								 | 
							
										foreach ($parts as $part) { 
							 | 
						||
| 
								 | 
							
											$path .= $part;
							 | 
						||
| 
								 | 
							
											
							 | 
						||
| 
								 | 
							
											if (is_dir(DIR_APPLICATION . 'controller/' . $path)) {
							 | 
						||
| 
								 | 
							
												$path .= '/';
							 | 
						||
| 
								 | 
							
												
							 | 
						||
| 
								 | 
							
												array_shift($parts);
							 | 
						||
| 
								 | 
							
												
							 | 
						||
| 
								 | 
							
												continue;
							 | 
						||
| 
								 | 
							
											}
							 | 
						||
| 
								 | 
							
											
							 | 
						||
| 
								 | 
							
											if (is_file(DIR_APPLICATION . 'controller/' . str_replace('../', '', $path) . '.php')) {
							 | 
						||
| 
								 | 
							
												$this->file = DIR_APPLICATION . 'controller/' . str_replace('../', '', $path) . '.php';
							 | 
						||
| 
								 | 
							
												
							 | 
						||
| 
								 | 
							
												$this->class = 'Controller' . preg_replace('/[^a-zA-Z0-9]/', '', $path);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
												array_shift($parts);
							 | 
						||
| 
								 | 
							
												
							 | 
						||
| 
								 | 
							
												break;
							 | 
						||
| 
								 | 
							
											}
							 | 
						||
| 
								 | 
							
										}
							 | 
						||
| 
								 | 
							
										
							 | 
						||
| 
								 | 
							
										if ($args) {
							 | 
						||
| 
								 | 
							
											$this->args = $args;
							 | 
						||
| 
								 | 
							
										}
							 | 
						||
| 
								 | 
							
											
							 | 
						||
| 
								 | 
							
										$method = array_shift($parts);
							 | 
						||
| 
								 | 
							
												
							 | 
						||
| 
								 | 
							
										if ($method) {
							 | 
						||
| 
								 | 
							
											$this->method = $method;
							 | 
						||
| 
								 | 
							
										} else {
							 | 
						||
| 
								 | 
							
											$this->method = 'index';
							 | 
						||
| 
								 | 
							
										}
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									
							 | 
						||
| 
								 | 
							
									public function getFile() {
							 | 
						||
| 
								 | 
							
										return $this->file;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									
							 | 
						||
| 
								 | 
							
									public function getClass() {
							 | 
						||
| 
								 | 
							
										return $this->class;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									
							 | 
						||
| 
								 | 
							
									public function getMethod() {
							 | 
						||
| 
								 | 
							
										return $this->method;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									
							 | 
						||
| 
								 | 
							
									public function getArgs() {
							 | 
						||
| 
								 | 
							
										return $this->args;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								final class ActionSystem {
							 | 
						||
| 
								 | 
							
									protected $file;
							 | 
						||
| 
								 | 
							
									protected $class;
							 | 
						||
| 
								 | 
							
									protected $method;
							 | 
						||
| 
								 | 
							
									protected $args = array();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									public function __construct($route, $args = array()) {
							 | 
						||
| 
								 | 
							
										$path = '';
							 | 
						||
| 
								 | 
							
										
							 | 
						||
| 
								 | 
							
										$parts = explode('/', str_replace('../', '', (string)$route));
							 | 
						||
| 
								 | 
							
										
							 | 
						||
| 
								 | 
							
										foreach ($parts as $part) { 
							 | 
						||
| 
								 | 
							
											$path .= $part;
							 | 
						||
| 
								 | 
							
											
							 | 
						||
| 
								 | 
							
											if (is_dir(DIR_SYSTEM . '' . $path)) {
							 | 
						||
| 
								 | 
							
												$path .= '/';
							 | 
						||
| 
								 | 
							
												
							 | 
						||
| 
								 | 
							
												array_shift($parts);
							 | 
						||
| 
								 | 
							
												
							 | 
						||
| 
								 | 
							
												continue;
							 | 
						||
| 
								 | 
							
											}
							 | 
						||
| 
								 | 
							
											
							 | 
						||
| 
								 | 
							
											if (is_file(DIR_SYSTEM . '' . str_replace('../', '', $path) . '.php')) {
							 | 
						||
| 
								 | 
							
												$this->file = DIR_SYSTEM . '' . str_replace('../', '', $path) . '.php';
							 | 
						||
| 
								 | 
							
												
							 | 
						||
| 
								 | 
							
												$this->class = 'System' . preg_replace('/[^a-zA-Z0-9]/', '', $path);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
												array_shift($parts);
							 | 
						||
| 
								 | 
							
												
							 | 
						||
| 
								 | 
							
												break;
							 | 
						||
| 
								 | 
							
											}
							 | 
						||
| 
								 | 
							
										}
							 | 
						||
| 
								 | 
							
										
							 | 
						||
| 
								 | 
							
										if ($args) {
							 | 
						||
| 
								 | 
							
											$this->args = $args;
							 | 
						||
| 
								 | 
							
										}
							 | 
						||
| 
								 | 
							
											
							 | 
						||
| 
								 | 
							
										$method = array_shift($parts);
							 | 
						||
| 
								 | 
							
												
							 | 
						||
| 
								 | 
							
										if ($method) {
							 | 
						||
| 
								 | 
							
											$this->method = $method;
							 | 
						||
| 
								 | 
							
										} else {
							 | 
						||
| 
								 | 
							
											$this->method = 'index';
							 | 
						||
| 
								 | 
							
										}
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									
							 | 
						||
| 
								 | 
							
									public function getFile() {
							 | 
						||
| 
								 | 
							
										return $this->file;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									
							 | 
						||
| 
								 | 
							
									public function getClass() {
							 | 
						||
| 
								 | 
							
										return $this->class;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									
							 | 
						||
| 
								 | 
							
									public function getMethod() {
							 | 
						||
| 
								 | 
							
										return $this->method;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									
							 | 
						||
| 
								 | 
							
									public function getArgs() {
							 | 
						||
| 
								 | 
							
										return $this->args;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								?>
							 |