Skip to content

Commit

Permalink
add full path deep link
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymoulin committed Oct 23, 2016
1 parent 5126d38 commit 60802c9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 78 deletions.
64 changes: 0 additions & 64 deletions CHANGELOG.md

This file was deleted.

16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Nano Framework
===
Nano is a simple stupid framework, really easy to handle, and really performant.

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

Installation
---
Expand All @@ -28,7 +28,8 @@ all your request can be redirected to your bootstrap (assuming index.php)
```php
<?php
require_once ('vendor/autoload.php');
(new \Nano\Framework())->dispatch();
$nano = new \Nano\Framework();
$nano->dispatch();
```

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

Therefore

url | class::method
----------------------------- | ---------------------------------------
http://mysite.tld/ | \Project\Controller\Index::indexAction
http://mysite.tld/test | \Project\Controller\Test::indexAction
http://mysite.tld/test/action | \Project\Controller\Test::actionAction
url | class::method
------------------------------------------ | ---------------------------------------
http://mysite.tld/ | \Project\Controller\Index::indexAction
http://mysite.tld/test | \Project\Controller\Test::indexAction
http://mysite.tld/test/action | \Project\Controller\Test::actionAction
http://mysite.tld/also/work/with/full/path | \Project\Controller\Also\Work\With\Full::pathAction
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "femtopixel/nano-framework",
"description": "Nano Framework - easier than easiest framework",
"keywords":["nano", "framework", "easy", "performant", "lightweight", "simple", "MVC", "PHP 7", "PHP 5.3"],
"keywords":["nano", "framework", "easy", "performant", "lightweight", "simple", "MVC", "quickstart", "PHP 7", "PHP 5.3"],
"license": "MIT",
"homepage": "http://femtopixel.github.io/nano-framework",
"authors": [
Expand Down
9 changes: 6 additions & 3 deletions src/Framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ final class Framework
*/
public function dispatch()
{
$globb = explode('/', preg_replace('~^' . Basepath::get() . '~', '', $_SERVER['REQUEST_URI']));
$controllerName = isset($globb[0]) && $globb[0] ? $globb[0] : 'index';
$action = isset($globb[1]) && $globb[1] ? $globb[1] : 'index';
$parts = explode('/', preg_replace('~^' . Basepath::get() . '~', '', $_SERVER['REQUEST_URI']));
$action = count($parts) >= 2 ? array_pop($parts) : 'index';
if (!$action) {
$action = 'index';
}
$controllerName = isset($parts[0]) && $parts[0] ? implode($parts, '\\') : 'index';
$controller = $this->projectNamespace . $this->controllerPackage . '\\' . ucfirst($controllerName);
if (!class_exists($controller)) {
throw new \Exception('controller ' . $controllerName . ' not found');
Expand Down
31 changes: 28 additions & 3 deletions tests/FrameworkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public function testAction()
}
}
}
namespace OtherNamespace\OtherSub {

namespace OtherNamespace\OtherSub
{
class Routing
{
public function testAction()
Expand All @@ -28,7 +28,8 @@ public function testAction()
}
}
}
namespace OtherNamespace {
namespace OtherNamespace
{
class Route
{
public function actionThatHasOtherSuffix()
Expand All @@ -37,6 +38,18 @@ public function actionThatHasOtherSuffix()
}
}
}

namespace OtherNamespace\Recursive
{
class Recursive
{
public function actionWithNoSuffix()
{
echo "Working5";
}
}
}

namespace Nano\Tests {

class FrameworkTest extends \PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -115,5 +128,17 @@ public function testDispatchSuccessWhenOtherSubPackageAndOtherNamespaceWithOther
->setControllerActionSuffix('OtherSuffix')
->dispatch();
}

public function testDispatchSuccessWhenOtherSubPackageAndNoSuffixAndRecursivePath()
{
$_SERVER['REQUEST_URI'] = '/recursive/recursive/actionwithnosuffix';
$_SERVER['SCRIPT_FILENAME'] = '/var/www/index.php';
$this->expectOutputString("Working5");
$nano = new \Nano\Framework();
$nano->setNamespace('\OtherNamespace')
->setControllerPackage('')
->setControllerActionSuffix('')
->dispatch();
}
}
}

0 comments on commit 60802c9

Please sign in to comment.