Browse code

REGEX routes

Rafał Szklarczyk authored on 26/11/2019 16:16:53
Showing 1 changed files
... ...
@@ -11,19 +11,26 @@ class RouteInfo{
11 11
     public $result;
12 12
     // The route name
13 13
     public $name;
14
+    // The type the route - should be one of defined in the class constants
15
+    public $type;
14 16
     // BeforeAction event handlers;
15 17
     public $beforeAction;
16 18
     // AfterAction event handlers;
17 19
     public $afterAction;
18 20
     // AfterResult event handlers;
19 21
     public $afterResult;
22
+
23
+    //RouteInfo types:
24
+    public const L3 = "L3";
25
+    public const REGEX = "REGEX";
20 26
        
21
-    public function __construct($method, $path, $result, $name = '')
27
+    public function __construct($method, $path, $result, $name = '', $type = self::L3)
22 28
     {
23 29
         $this->path = $path;
24 30
         $this->method = $method;
25 31
         $this->result = $result;
26 32
         $this->name = $name;
33
+        $this->type = $type;
27 34
         $this->beforeAction = array();
28 35
         $this->afterAction = array();
29 36
         $this->afterResult = array();
Browse code

{} characters in eventHandler arguments

Rafał Szklarczyk authored on 22/07/2019 18:15:11
Showing 1 changed files
... ...
@@ -60,7 +60,7 @@ class RouteInfo{
60 60
     }
61 61
 
62 62
     public static function eventHandlerFormatCheck($event_handler, &$match){
63
-        $pattern = '#^((?<class>[a-z0-9\\\\]+)::)?(?<function>[a-zA-Z0-9]+)(\\((?<arguments>[a-zA-Z0-9;, \-/]+)?\\))?$#i';
63
+        $pattern = '#^((?<class>[a-z0-9\\\\]+)::)?(?<function>[a-zA-Z0-9]+)(\\((?<arguments>[a-zA-Z0-9;, \{\}\-/]+)?\\))?$#i';
64 64
         if(preg_match($pattern, $event_handler, $match)){
65 65
             if(isset($match['arguments'])){
66 66
                 $result = self::eventHandlerArgumentsFormatCheck($match['arguments'],$arguments_match);
Browse code

More characters for eventHandler...

Rafał Szklarczyk authored on 18/07/2019 22:58:29
Showing 1 changed files
... ...
@@ -60,7 +60,7 @@ class RouteInfo{
60 60
     }
61 61
 
62 62
     public static function eventHandlerFormatCheck($event_handler, &$match){
63
-        $pattern = '#^((?<class>[a-z0-9\\\\]+)::)?(?<function>[a-z0-9]+)(\\((?<arguments>[a-z0-9;, \-/]+)?\\))?$#i';
63
+        $pattern = '#^((?<class>[a-z0-9\\\\]+)::)?(?<function>[a-zA-Z0-9]+)(\\((?<arguments>[a-zA-Z0-9;, \-/]+)?\\))?$#i';
64 64
         if(preg_match($pattern, $event_handler, $match)){
65 65
             if(isset($match['arguments'])){
66 66
                 $result = self::eventHandlerArgumentsFormatCheck($match['arguments'],$arguments_match);
Browse code

slash in eventHandler parameters

Rafał Szklarczyk authored on 18/07/2019 22:49:13
Showing 1 changed files
... ...
@@ -60,7 +60,7 @@ class RouteInfo{
60 60
     }
61 61
 
62 62
     public static function eventHandlerFormatCheck($event_handler, &$match){
63
-        $pattern = '#^((?<class>[a-z0-9\\\\]+)::)?(?<function>[a-z0-9]+)(\\((?<arguments>[a-z0-9;, \-]+)?\\))?$#i';
63
+        $pattern = '#^((?<class>[a-z0-9\\\\]+)::)?(?<function>[a-z0-9]+)(\\((?<arguments>[a-z0-9;, \-/]+)?\\))?$#i';
64 64
         if(preg_match($pattern, $event_handler, $match)){
65 65
             if(isset($match['arguments'])){
66 66
                 $result = self::eventHandlerArgumentsFormatCheck($match['arguments'],$arguments_match);
Browse code

regexp fix

Rafał Szklarczyk authored on 12/07/2019 14:55:18
Showing 1 changed files
... ...
@@ -60,7 +60,7 @@ class RouteInfo{
60 60
     }
61 61
 
62 62
     public static function eventHandlerFormatCheck($event_handler, &$match){
63
-        $pattern = '#^((?<class>[a-z0-9\\\\]+)::)?(?<function>[a-z0-9]+)(\\((?<arguments>[a-z0-9;,- ]+)?\\))?$#i';
63
+        $pattern = '#^((?<class>[a-z0-9\\\\]+)::)?(?<function>[a-z0-9]+)(\\((?<arguments>[a-z0-9;, \-]+)?\\))?$#i';
64 64
         if(preg_match($pattern, $event_handler, $match)){
65 65
             if(isset($match['arguments'])){
66 66
                 $result = self::eventHandlerArgumentsFormatCheck($match['arguments'],$arguments_match);
Browse code

'-' in eventHandler arguments

Rafał Szklarczyk authored on 12/07/2019 14:51:43
Showing 1 changed files
... ...
@@ -60,7 +60,7 @@ class RouteInfo{
60 60
     }
61 61
 
62 62
     public static function eventHandlerFormatCheck($event_handler, &$match){
63
-        $pattern = '#^((?<class>[a-z0-9\\\\]+)::)?(?<function>[a-z0-9]+)(\\((?<arguments>[a-z0-9;, ]+)?\\))?$#i';
63
+        $pattern = '#^((?<class>[a-z0-9\\\\]+)::)?(?<function>[a-z0-9]+)(\\((?<arguments>[a-z0-9;,- ]+)?\\))?$#i';
64 64
         if(preg_match($pattern, $event_handler, $match)){
65 65
             if(isset($match['arguments'])){
66 66
                 $result = self::eventHandlerArgumentsFormatCheck($match['arguments'],$arguments_match);
Browse code

Naming convention + clean up

Rafał Szklarczyk authored on 23/05/2019 18:25:39
Showing 1 changed files
... ...
@@ -4,34 +4,34 @@ namespace elanpl\L3;
4 4
 
5 5
 class RouteInfo{
6 6
     // URL pattern path
7
-    public $Path;
7
+    public $path;
8 8
     // Http method (ex. GET, POST, ANY)
9
-    public $Method;
9
+    public $method;
10 10
     // The assigned structure (string, array, function...)
11
-    public $Result;
11
+    public $result;
12 12
     // The route name
13
-    public $Name;
13
+    public $name;
14 14
     // BeforeAction event handlers;
15
-    public $BeforeAction;
15
+    public $beforeAction;
16 16
     // AfterAction event handlers;
17
-    public $AfterAction;
17
+    public $afterAction;
18 18
     // AfterResult event handlers;
19
-    public $AfterResult;
19
+    public $afterResult;
20 20
        
21
-    public function __construct($Method, $Path, $Result, $Name = '')
21
+    public function __construct($method, $path, $result, $name = '')
22 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();
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 30
     }
31 31
 
32
-    public function AddBeforeAction($event_handler){
33
-        if($this->EventHandlerFormatCheck($event_handler, $match)){
34
-            $this->BeforeAction[] = $event_handler;
32
+    public function addBeforeAction($event_handler){
33
+        if($this->eventHandlerFormatCheck($event_handler, $match)){
34
+            $this->beforeAction[] = $event_handler;
35 35
             return $this;
36 36
         }
37 37
         else{
... ...
@@ -39,9 +39,9 @@ class RouteInfo{
39 39
         }
40 40
     }
41 41
 
42
-    public function AddAfterAction($event_handler){
43
-        if($this->EventHandlerFormatCheck($event_handler, $match)){
44
-            $this->AfterAction[] = $event_handler;
42
+    public function addAfterAction($event_handler){
43
+        if($this->eventHandlerFormatCheck($event_handler, $match)){
44
+            $this->afterAction[] = $event_handler;
45 45
             return $this;
46 46
         }
47 47
         else{
... ...
@@ -49,9 +49,9 @@ class RouteInfo{
49 49
         }
50 50
     }
51 51
 
52
-    public function AddAfterResult($event_handler){
53
-        if($this->EventHandlerFormatCheck($event_handler, $match)){
54
-            $this->AfterResult[] = $event_handler;
52
+    public function addAfterResult($event_handler){
53
+        if($this->eventHandlerFormatCheck($event_handler, $match)){
54
+            $this->afterResult[] = $event_handler;
55 55
             return $this;
56 56
         }
57 57
         else{
... ...
@@ -59,11 +59,11 @@ class RouteInfo{
59 59
         }
60 60
     }
61 61
 
62
-    public static function EventHandlerFormatCheck($event_handler, &$match){
62
+    public static function eventHandlerFormatCheck($event_handler, &$match){
63 63
         $pattern = '#^((?<class>[a-z0-9\\\\]+)::)?(?<function>[a-z0-9]+)(\\((?<arguments>[a-z0-9;, ]+)?\\))?$#i';
64 64
         if(preg_match($pattern, $event_handler, $match)){
65 65
             if(isset($match['arguments'])){
66
-                $result = self::EventHandlerArgumentsFormatCheck($match['arguments'],$arguments_match);
66
+                $result = self::eventHandlerArgumentsFormatCheck($match['arguments'],$arguments_match);
67 67
                 return $result;
68 68
             }
69 69
             else{
... ...
@@ -75,7 +75,7 @@ class RouteInfo{
75 75
         }
76 76
     }
77 77
 
78
-    public static function EventHandlerArgumentsFormatCheck($arguments, &$match){
78
+    public static function eventHandlerArgumentsFormatCheck($arguments, &$match){
79 79
         $match = explode(',', $arguments);
80 80
         return $match;
81 81
     }
Browse code

Class RouteInfo

Rafał Szklarczyk authored on 22/05/2019 20:16:21
Showing 1 changed files
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