Skip to content

Commit d270106

Browse files
authored
Merge pull request #3 from cherry-framework/develope
Develope
2 parents 2829227 + 6478605 commit d270106

File tree

6 files changed

+55
-32
lines changed

6 files changed

+55
-32
lines changed

CHANGELOG.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
# Cherry-router
22

3-
## [v1.0.1](https://github.com/ABGEO07/cherry-router/releases/tag/v1.0.1 "v1.0.1") (2019-03-29)
3+
## [v1.1.0](https://github.com/cherry-framework/router/releases/tag/v1.1.0 "v1.1.0") (2019-04-05)
4+
5+
- Remove namespace part form route action. Now you can use this syntax:
6+
7+
```json
8+
{
9+
...
10+
"action": "DefaultController::index",
11+
...
12+
}
13+
```
14+
15+
- Lock Cherry Request dependency to 1.0.x version.
16+
17+
## [v1.0.1](https://github.com/cherry-framework/router/releases/tag/v1.0.1 "v1.0.1") (2019-03-29)
418

519
- Change Namespace
620

@@ -15,10 +29,10 @@
1529
- Use call_user_func_array function in method calling
1630

1731

18-
## [v1.0.0](https://github.com/ABGEO07/cherry-router/releases/tag/v1.0.0 "v1.0.0") (2019-03-07)
32+
## [v1.0.0](https://github.com/cherry-framework/router/releases/tag/v1.0.0 "v1.0.0") (2019-03-07)
1933
#### The first stable version
2034

21-
- Package available on: `composer require cherry-project/router`;
35+
- Package available on: `composer require cherry-framework/router`;
2236
- Router path has placeholder support;
2337
- Router has all HTTP Methods support;
24-
- Router has caching feature;
38+
- Router has caching feature;

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Each route must have **path**, **method** and **action** keys. Homepage route ex
6060
"homepage": {
6161
"path": "/",
6262
"method": "GET",
63-
"action": "Cherry\\Controller\\DefaultController::index"
63+
"action": "DefaultController::index"
6464
}
6565
}
6666
```
@@ -71,7 +71,7 @@ Each route must have **path**, **method** and **action** keys. Homepage route ex
7171
"[RouteName]": {
7272
"path": "[URL]",
7373
"method": "[HTTP_Method]",
74-
"action": "[Namespace]\\[Controller]::[Method]"
74+
"action": "[Controller]::[Method]"
7575
}
7676
}
7777
```
@@ -81,8 +81,8 @@ Definitions for router keys:
8181
- **path** - Route url. (Ex.: For address http://www.example.com/homepage [URL] is *homepage*);
8282
- **method** - Route HTTP Method. Allowed all [HTTP methods](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods "HTTP methods");
8383
- **action** - Route callback action. The firs part of action (before *::*) is your controller (stored in **CONTROLLERS_PATH**).
84-
Controller is a simple [PHP Class](http://php.net/manual/en/language.oop5.php "PHP Class") where [Namespace] is his Namespace and
85-
[Controller] Class name (Class name and class filename must have same names (Ex.: **[Controller].php**)).
84+
Controller is a simple [PHP Class](http://php.net/manual/en/language.oop5.php "PHP Class") where
85+
[Controller] is Class name (Class name and class filename must have same names (Ex.: **[Controller].php**)).
8686
The second part of action key (after ::) is controllers (class) public method;
8787

8888
Your route path can use **Placeholders**. Placeholder is a template of your route.
@@ -93,7 +93,7 @@ Route example with placeholder:
9393
"homepage": {
9494
"path": "/hello/{name}",
9595
"method": "GET",
96-
"action": "Cherry\\Controller\\DefaultController::sayHello"
96+
"action": "DefaultController::sayHello"
9797
}
9898
}
9999
```

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Cherry-project Router",
44
"type": "library",
55
"keywords": ["cherry","router"],
6-
"homepage": "https://github.com/ABGEO07/cherry-router",
6+
"homepage": "https://github.com/cherry-framework/router",
77
"license": "MIT",
88
"authors": [
99
{
@@ -16,7 +16,7 @@
1616
"minimum-stability": "dev",
1717
"require": {
1818
"php": ">=5.6.0",
19-
"cherry-project/request": "v1.0.1",
19+
"cherry-project/request": "1.0.1",
2020
"ext-json": "*"
2121
},
2222
"autoload": {

composer.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/config/routes.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"homepage": {
33
"path": "/",
44
"method": "GET",
5-
"action": "Cherry\\Controller\\DefaultController::index"
5+
"action": "DefaultController::index"
66
}
7-
}
7+
}

src/Routing/Router.php

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* @category Library
88
* @package Cherry
99
* @author Temuri Takalandze <[email protected]>
10-
* @license https://github.com/ABGEO07/cherry-router/blob/master/LICENSE MIT
11-
* @link https://github.com/ABGEO07/cherry-router
10+
* @license https://github.com/cherry-framework/router/blob/master/LICENSE MIT
11+
* @link https://github.com/cherry-framework/router
1212
*/
1313

1414
namespace Cherry\Routing;
@@ -21,27 +21,34 @@
2121
* @category Library
2222
* @package Cherry
2323
* @author Temuri Takalandze <[email protected]>
24-
* @license https://github.com/ABGEO07/cherry-router/blob/master/LICENSE MIT
25-
* @link https://github.com/ABGEO07/cherry-router
24+
* @license https://github.com/cherry-framework/router/blob/master/LICENSE MIT
25+
* @link https://github.com/cherry-framework/router
2626
*/
2727
class Router
2828
{
2929
/**
30-
* Path to routes file
30+
* Path to routes file.
3131
*
3232
* @var string
3333
*/
3434
private $_routesFile;
3535

3636
/**
37-
* Path to controllers folder
37+
* Path to controllers folder.
3838
*
3939
* @var string
4040
*/
4141
private $_controllersPath;
4242

4343
/**
44-
* Application routes
44+
* Cherry Controller default namespace.
45+
*
46+
* @var string
47+
*/
48+
private $_ControllerNamespace = "Cherry\\Controller";
49+
50+
/**
51+
* Application routes.
4552
*
4653
* @var array
4754
*/
@@ -60,7 +67,7 @@ public function __construct()
6067
}
6168

6269
/**
63-
* Get routes from routes file
70+
* Get routes from routes file.
6471
*
6572
* @return array Application routes
6673
*/
@@ -91,7 +98,7 @@ private function _getRoutes()
9198
}
9299

93100
/**
94-
* Check if current request url math with
101+
* Check if current request url math with any route.
95102
*
96103
* @return void
97104
*/
@@ -122,7 +129,9 @@ private function _checkRoute()
122129
$routeFound = true;
123130
unset($match[0]);
124131

125-
$action = explode('::', $route['action']);
132+
$routeAction = $this->_ControllerNamespace.'\\'.$route['action'];
133+
134+
$action = explode('::', $routeAction);
126135
$controller = explode('\\', $action[0]);
127136
$controllerFile = $controllersPath . '/' .
128137
$controller[count($controller) - 1] . '.php';
@@ -160,10 +169,10 @@ private function _checkRoute()
160169
}
161170

162171
/**
163-
* Cache the routes
172+
* Cache the routes.
164173
*
165174
* @param string $routesCacheFile Cache file location.
166-
* @param array $routes Application routes
175+
* @param array $routes Application routes.
167176
*
168177
* @return void
169178
*/
@@ -182,11 +191,11 @@ private function _cacheRoutes($routesCacheFile, $routes)
182191
}
183192

184193
/**
185-
* Convert route to regular expression
194+
* Convert route to regular expression.
186195
*
187-
* @param string $plainText Router template for converting
196+
* @param string $plainText Router template for converting.
188197
*
189-
* @return string converted to Regular Expression route
198+
* @return string converted to Regular Expression route.
190199
*/
191200
private function _convertToRE($plainText)
192201
{
@@ -206,4 +215,4 @@ private function _convertToRE($plainText)
206215

207216
return "@^{$plainText}$@D";
208217
}
209-
}
218+
}

0 commit comments

Comments
 (0)