| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,83 @@ |
| 1 |
+<?php |
|
| 2 |
+ |
|
| 3 |
+namespace elanpl\L3; |
|
| 4 |
+ |
|
| 5 |
+class RouteInfo{
|
|
| 6 |
+ // URL pattern path |
|
| 7 |
+ public $Path; |
|
| 8 |
+ // Http method (ex. GET, POST, ANY) |
|
| 9 |
+ public $Method; |
|
| 10 |
+ // The assigned structure (string, array, function...) |
|
| 11 |
+ public $Result; |
|
| 12 |
+ // The route name |
|
| 13 |
+ public $Name; |
|
| 14 |
+ // BeforeAction event handlers; |
|
| 15 |
+ public $BeforeAction; |
|
| 16 |
+ // AfterAction event handlers; |
|
| 17 |
+ public $AfterAction; |
|
| 18 |
+ // AfterResult event handlers; |
|
| 19 |
+ public $AfterResult; |
|
| 20 |
+ |
|
| 21 |
+ public function __construct($Method, $Path, $Result, $Name = '') |
|
| 22 |
+ {
|
|
| 23 |
+ $this->Path = $Path; |
|
| 24 |
+ $this->Method = $Method; |
|
| 25 |
+ $this->Result = $Result; |
|
| 26 |
+ $this->Name = $Name; |
|
| 27 |
+ $this->BeforeAction = array(); |
|
| 28 |
+ $this->AfterAction = array(); |
|
| 29 |
+ $this->AfterResult = array(); |
|
| 30 |
+ } |
|
| 31 |
+ |
|
| 32 |
+ public function AddBeforeAction($event_handler){
|
|
| 33 |
+ if($this->EventHandlerFormatCheck($event_handler, $match)){
|
|
| 34 |
+ $this->BeforeAction[] = $event_handler; |
|
| 35 |
+ return $this; |
|
| 36 |
+ } |
|
| 37 |
+ else{
|
|
| 38 |
+ throw new \Exception("Wrong event handler format: $event_handler");
|
|
| 39 |
+ } |
|
| 40 |
+ } |
|
| 41 |
+ |
|
| 42 |
+ public function AddAfterAction($event_handler){
|
|
| 43 |
+ if($this->EventHandlerFormatCheck($event_handler, $match)){
|
|
| 44 |
+ $this->AfterAction[] = $event_handler; |
|
| 45 |
+ return $this; |
|
| 46 |
+ } |
|
| 47 |
+ else{
|
|
| 48 |
+ throw new \Exception("Wrong event handler format: $event_handler");
|
|
| 49 |
+ } |
|
| 50 |
+ } |
|
| 51 |
+ |
|
| 52 |
+ public function AddAfterResult($event_handler){
|
|
| 53 |
+ if($this->EventHandlerFormatCheck($event_handler, $match)){
|
|
| 54 |
+ $this->AfterResult[] = $event_handler; |
|
| 55 |
+ return $this; |
|
| 56 |
+ } |
|
| 57 |
+ else{
|
|
| 58 |
+ throw new \Exception("Wrong event handler format: $event_handler");
|
|
| 59 |
+ } |
|
| 60 |
+ } |
|
| 61 |
+ |
|
| 62 |
+ public static function EventHandlerFormatCheck($event_handler, &$match){
|
|
| 63 |
+ $pattern = '#^((?<class>[a-z0-9\\\\]+)::)?(?<function>[a-z0-9]+)(\\((?<arguments>[a-z0-9;, ]+)?\\))?$#i'; |
|
| 64 |
+ if(preg_match($pattern, $event_handler, $match)){
|
|
| 65 |
+ if(isset($match['arguments'])){
|
|
| 66 |
+ $result = self::EventHandlerArgumentsFormatCheck($match['arguments'],$arguments_match); |
|
| 67 |
+ return $result; |
|
| 68 |
+ } |
|
| 69 |
+ else{
|
|
| 70 |
+ return 1; |
|
| 71 |
+ } |
|
| 72 |
+ } |
|
| 73 |
+ else{
|
|
| 74 |
+ return 0; |
|
| 75 |
+ } |
|
| 76 |
+ } |
|
| 77 |
+ |
|
| 78 |
+ public static function EventHandlerArgumentsFormatCheck($arguments, &$match){
|
|
| 79 |
+ $match = explode(',', $arguments);
|
|
| 80 |
+ return $match; |
|
| 81 |
+ } |
|
| 82 |
+ |
|
| 83 |
+ } |
|
| 0 | 84 |
\ No newline at end of file |