1
- <?php
2
-
3
- /**
4
- * @package Routiny
5
- * @copyright © 2010
6
- * @author Nikita Titov <nikita@zencode .ru>
7
- */
8
- class Rt {
9
-
10
- private $ router ;
11
-
12
- public function __construct () {
13
- $ this ->router = new RtRouter ();
14
- }
15
-
16
- public function __call ($ name , $ arguments ) {
17
- if (RtHelper::checkHTTPMethod ($ name )) {
18
- if (isset ($ arguments [0 ])) {
19
- return $ this ->store ($ name , $ arguments [0 ]);
20
- }
21
- } elseif (RtHelper::checkDecorator ($ name )) {
22
- if (isset ($ arguments [0 ])) {
23
- return $ this ->decorate ($ name , $ arguments [0 ]);
24
- } else {
25
- return $ this ->decorate ($ name );
26
- }
27
- }
28
- }
29
-
30
- private function store ($ method , $ route ) {
31
- $ this ->router ->saveRoute ($ method , $ route );
32
- //defining a GET handler also automatically defines HEAD handler
33
- if ('GET ' == $ method ) {
34
- $ this ->router ->saveRoute ('HEAD ' , $ route );
35
- }
36
- return $ this ;
37
- }
38
-
39
- private function decorate ($ name , $ params =null ) {
40
- $ this ->router ->saveDecoratorParams ($ name , $ params );
41
- return $ this ;
42
- }
43
-
44
- public function format_by_request () {
45
- $ type = $ this ->router ->getType ();
46
- if (!is_null ($ type )) {
47
- $ this ->decorate ($ type );
48
- } else {
49
- $ this ->decorate ('view ' );
50
- }
51
- return $ this ;
52
- }
53
-
54
- public function dispatch ($ function ) {
55
- $ this ->router ->saveFunction ($ function );
56
- return $ this ;
57
- }
58
-
59
- public function run () {
60
- $ action = $ this ->router ->getAction ();
61
- $ decorators = $ this ->router ->getDecorators ();
62
- if (!empty ($ decorators )) {
63
- foreach ($ decorators as $ name => $ params ) {
64
- $ decorator = 'Rt ' . $ name ;
65
- $ action = new $ decorator ($ action , $ params );
66
- }
67
- }
68
- echo $ action ->perform ();
69
- }
70
-
71
- }
1
+ <?php
2
+
3
+ /**
4
+ * @package Routiny
5
+ * @copyright © 2010
6
+ * @author Nikita Titov <nmtitov@ya .ru>
7
+ */
8
+ class Rt {
9
+
10
+ private $ router ;
11
+
12
+ public function __construct () {
13
+ $ this ->router = new RtRouter ();
14
+ }
15
+
16
+ public function __call ($ name , $ arguments ) {
17
+ if (RtHelper::checkHTTPMethod ($ name )) {
18
+ if (isset ($ arguments [0 ])) {
19
+ return $ this ->store ($ name , $ arguments [0 ]);
20
+ }
21
+ } elseif (RtHelper::checkDecorator ($ name )) {
22
+ if (isset ($ arguments [0 ])) {
23
+ return $ this ->decorate ($ name , $ arguments [0 ]);
24
+ } else {
25
+ return $ this ->decorate ($ name );
26
+ }
27
+ }
28
+ }
29
+
30
+ private function store ($ method , $ route ) {
31
+ $ this ->router ->saveRoute ($ method , $ route );
32
+ //defining a GET handler also automatically defines HEAD handler
33
+ if ('GET ' == $ method ) {
34
+ $ this ->router ->saveRoute ('HEAD ' , $ route );
35
+ }
36
+ return $ this ;
37
+ }
38
+
39
+ private function decorate ($ name , $ params =null ) {
40
+ $ this ->router ->saveDecoratorParams ($ name , $ params );
41
+ return $ this ;
42
+ }
43
+
44
+ public function format_by_request () {
45
+ $ type = $ this ->router ->getType ();
46
+ if (!is_null ($ type )) {
47
+ $ this ->decorate ($ type );
48
+ } else {
49
+ $ this ->decorate ('view ' );
50
+ }
51
+ return $ this ;
52
+ }
53
+
54
+ public function dispatch ($ function ) {
55
+ $ this ->router ->saveFunction ($ function );
56
+ return $ this ;
57
+ }
58
+
59
+ public function run () {
60
+ $ action = $ this ->router ->getAction ();
61
+ $ decorators = $ this ->router ->getDecorators ();
62
+ if (!empty ($ decorators )) {
63
+ foreach ($ decorators as $ name => $ params ) {
64
+ $ decorator = 'Rt ' . $ name ;
65
+ $ action = new $ decorator ($ action , $ params );
66
+ }
67
+ }
68
+ echo $ action ->perform ();
69
+ }
70
+
71
+ }
72
72
73
73
74
74
/**
75
75
* @package Routiny
76
76
* @copyright © 2010
77
- * @author Nikita Titov <nikita@zencode .ru>
77
+ * @author Nikita Titov <nmtitov@ya .ru>
78
78
*/
79
79
class RtAction implements RtIAction {
80
80
@@ -123,7 +123,7 @@ public function perform() {
123
123
/**
124
124
* @package Routiny
125
125
* @copyright © 2010
126
- * @author Nikita Titov <nikita@zencode .ru>
126
+ * @author Nikita Titov <nmtitov@ya .ru>
127
127
*/
128
128
class RtException extends Exception {
129
129
@@ -133,7 +133,7 @@ class RtException extends Exception {
133
133
/**
134
134
* @package Routiny
135
135
* @copyright © 2010
136
- * @author Nikita Titov <nikita@zencode .ru>
136
+ * @author Nikita Titov <nmtitov@ya .ru>
137
137
*/
138
138
class RtHelper {
139
139
const D = "| " ;
@@ -198,7 +198,7 @@ public static function checkType($type) {
198
198
/**
199
199
* @package Routiny
200
200
* @copyright © 2010
201
- * @author Nikita Titov <nikita@zencode .ru>
201
+ * @author Nikita Titov <nmtitov@ya .ru>
202
202
*/
203
203
interface RtIAction {
204
204
public function perform ();
@@ -208,7 +208,7 @@ public function perform();
208
208
/**
209
209
* @package Routiny
210
210
* @copyright © 2010
211
- * @author Nikita Titov <nikita@zencode .ru>
211
+ * @author Nikita Titov <nmtitov@ya .ru>
212
212
*/
213
213
class RtJSON implements RtIAction {
214
214
@@ -365,7 +365,7 @@ private function getRequestQuery() {
365
365
/**
366
366
* @package Routiny
367
367
* @copyright © 2010
368
- * @author Nikita Titov <nikita@zencode .ru>
368
+ * @author Nikita Titov <nmtitov@ya .ru>
369
369
*/
370
370
class RtText implements RtIAction {
371
371
@@ -387,7 +387,7 @@ public function perform() {
387
387
/**
388
388
* @package Routiny
389
389
* @copyright © 2010
390
- * @author Nikita Titov <nikita@zencode .ru>
390
+ * @author Nikita Titov <nmtitov@ya .ru>
391
391
*/
392
392
class RtView implements RtIAction {
393
393
@@ -530,7 +530,7 @@ public static function isAssoc($array) {
530
530
/**
531
531
* @package Routiny
532
532
* @copyright © 2010
533
- * @author Nikita Titov <nikita@zencode .ru>
533
+ * @author Nikita Titov <nmtitov@ya .ru>
534
534
*/
535
535
class RtXSLT implements RtIAction {
536
536
0 commit comments