Skip to content

Commit 60802c9

Browse files
committed
add full path deep link
1 parent 5126d38 commit 60802c9

File tree

5 files changed

+44
-78
lines changed

5 files changed

+44
-78
lines changed

CHANGELOG.md

Lines changed: 0 additions & 64 deletions
This file was deleted.

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Nano Framework
1313
===
1414
Nano is a simple stupid framework, really easy to handle, and really performant.
1515

16-
It implements the MVC design pattern
16+
It only implements the C part (Controller) of the MVC design pattern which allows developers to use any other existing library for others parts
1717

1818
Installation
1919
---
@@ -28,7 +28,8 @@ all your request can be redirected to your bootstrap (assuming index.php)
2828
```php
2929
<?php
3030
require_once ('vendor/autoload.php');
31-
(new \Nano\Framework())->dispatch();
31+
$nano = new \Nano\Framework();
32+
$nano->dispatch();
3233
```
3334

3435
That's all!
@@ -48,8 +49,9 @@ Either \<controller> or \<action> are optional and considered as 'index' if not
4849

4950
Therefore
5051

51-
url | class::method
52-
----------------------------- | ---------------------------------------
53-
http://mysite.tld/ | \Project\Controller\Index::indexAction
54-
http://mysite.tld/test | \Project\Controller\Test::indexAction
55-
http://mysite.tld/test/action | \Project\Controller\Test::actionAction
52+
url | class::method
53+
------------------------------------------ | ---------------------------------------
54+
http://mysite.tld/ | \Project\Controller\Index::indexAction
55+
http://mysite.tld/test | \Project\Controller\Test::indexAction
56+
http://mysite.tld/test/action | \Project\Controller\Test::actionAction
57+
http://mysite.tld/also/work/with/full/path | \Project\Controller\Also\Work\With\Full::pathAction

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "femtopixel/nano-framework",
33
"description": "Nano Framework - easier than easiest framework",
4-
"keywords":["nano", "framework", "easy", "performant", "lightweight", "simple", "MVC", "PHP 7", "PHP 5.3"],
4+
"keywords":["nano", "framework", "easy", "performant", "lightweight", "simple", "MVC", "quickstart", "PHP 7", "PHP 5.3"],
55
"license": "MIT",
66
"homepage": "http://femtopixel.github.io/nano-framework",
77
"authors": [

src/Framework.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ final class Framework
1717
*/
1818
public function dispatch()
1919
{
20-
$globb = explode('/', preg_replace('~^' . Basepath::get() . '~', '', $_SERVER['REQUEST_URI']));
21-
$controllerName = isset($globb[0]) && $globb[0] ? $globb[0] : 'index';
22-
$action = isset($globb[1]) && $globb[1] ? $globb[1] : 'index';
20+
$parts = explode('/', preg_replace('~^' . Basepath::get() . '~', '', $_SERVER['REQUEST_URI']));
21+
$action = count($parts) >= 2 ? array_pop($parts) : 'index';
22+
if (!$action) {
23+
$action = 'index';
24+
}
25+
$controllerName = isset($parts[0]) && $parts[0] ? implode($parts, '\\') : 'index';
2326
$controller = $this->projectNamespace . $this->controllerPackage . '\\' . ucfirst($controllerName);
2427
if (!class_exists($controller)) {
2528
throw new \Exception('controller ' . $controllerName . ' not found');

tests/FrameworkTest.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public function testAction()
1818
}
1919
}
2020
}
21-
namespace OtherNamespace\OtherSub {
22-
21+
namespace OtherNamespace\OtherSub
22+
{
2323
class Routing
2424
{
2525
public function testAction()
@@ -28,7 +28,8 @@ public function testAction()
2828
}
2929
}
3030
}
31-
namespace OtherNamespace {
31+
namespace OtherNamespace
32+
{
3233
class Route
3334
{
3435
public function actionThatHasOtherSuffix()
@@ -37,6 +38,18 @@ public function actionThatHasOtherSuffix()
3738
}
3839
}
3940
}
41+
42+
namespace OtherNamespace\Recursive
43+
{
44+
class Recursive
45+
{
46+
public function actionWithNoSuffix()
47+
{
48+
echo "Working5";
49+
}
50+
}
51+
}
52+
4053
namespace Nano\Tests {
4154

4255
class FrameworkTest extends \PHPUnit_Framework_TestCase
@@ -115,5 +128,17 @@ public function testDispatchSuccessWhenOtherSubPackageAndOtherNamespaceWithOther
115128
->setControllerActionSuffix('OtherSuffix')
116129
->dispatch();
117130
}
131+
132+
public function testDispatchSuccessWhenOtherSubPackageAndNoSuffixAndRecursivePath()
133+
{
134+
$_SERVER['REQUEST_URI'] = '/recursive/recursive/actionwithnosuffix';
135+
$_SERVER['SCRIPT_FILENAME'] = '/var/www/index.php';
136+
$this->expectOutputString("Working5");
137+
$nano = new \Nano\Framework();
138+
$nano->setNamespace('\OtherNamespace')
139+
->setControllerPackage('')
140+
->setControllerActionSuffix('')
141+
->dispatch();
142+
}
118143
}
119144
}

0 commit comments

Comments
 (0)