diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 4cc3455..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,64 +0,0 @@ -0.3.4 (2016-06-24) -================== - -Fixes ------ - - Travis CI will now build by excluding PHPMD from build - - add CONTRIBUTING.md + add CHANGELOG.md - - allow use of phpunit ^5.0 along with ^4.0 - -0.3.3 (2016-06-24) -================== - -Fixes ------ - - Renamed License - - add .gitattributes to have a clean disribution - - removed phing dependency (now uses composer scripts commands to do CI) - - changed Unit tests namespace (with autoload-dev) - -0.3.2 (2016-06-16) -================== - -Fixes ------ - - add codeclimate/php-test-reporter dependency to test code coverage - -0.3.1 (2016-06-14) -================== - -Fixes ------ - - fix phploc dependency - -0.3.0 (2016-06-13) -================== - -New ---- - - Add PHP ^5.3 support - -0.2.1 (2016-06-13) -================== - -Fixes ------ - - Removed dev dependencies to set them in require-dev - -0.2.0 (2016-06-13) -================== - -New ---- - - Add unit tests - -Fixes ------ - - fixes URL - - fixes DB connections - -0.1.0 (2016-06-10) -================== - -Initial release - Framework may be able to load simple controllers - diff --git a/README.md b/README.md index b2721a2..c876d7c 100644 --- a/README.md +++ b/README.md @@ -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 --- @@ -28,7 +28,8 @@ all your request can be redirected to your bootstrap (assuming index.php) ```php dispatch(); +$nano = new \Nano\Framework(); +$nano->dispatch(); ``` That's all! @@ -48,8 +49,9 @@ Either \ or \ 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 diff --git a/composer.json b/composer.json index 818824c..ffbe736 100644 --- a/composer.json +++ b/composer.json @@ -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": [ diff --git a/src/Framework.php b/src/Framework.php index c194f99..066cfba 100644 --- a/src/Framework.php +++ b/src/Framework.php @@ -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'); diff --git a/tests/FrameworkTest.php b/tests/FrameworkTest.php index f9838cb..d152319 100644 --- a/tests/FrameworkTest.php +++ b/tests/FrameworkTest.php @@ -18,8 +18,8 @@ public function testAction() } } } -namespace OtherNamespace\OtherSub { - +namespace OtherNamespace\OtherSub +{ class Routing { public function testAction() @@ -28,7 +28,8 @@ public function testAction() } } } -namespace OtherNamespace { +namespace OtherNamespace +{ class Route { public function actionThatHasOtherSuffix() @@ -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 @@ -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(); + } } }