From 48bb7658b709fde9bfadf5850c2c7cf7a1dd9265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20M=20Mart=C3=ADnez?= Date: Fri, 17 Oct 2014 00:10:49 -0300 Subject: [PATCH 1/5] Mininal typo in README I just add the `new` to `Response` :) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 678f67c..18d2972 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ $app = new Application(); // Add a route $app->get('/hello/{name}', function (Application $app, Request $request, $name) { - return Response("Hello $name"); + return new Response("Hello $name"); }); $app->run(); From dad1a19af2cb88cb8ca4499299c499a1a6f808a5 Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Tue, 21 Oct 2014 10:25:02 +0200 Subject: [PATCH 2/5] Fix Invoker to map subclasses When invoking a method which has a parameter of class X, Invoker will properly map class parameters which are instances of a subclass of X. --- CHANGELOG.md | 9 +++++++++ src/Invoker.php | 16 ++++++++-------- tests/InvokerTest.php | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3116cd..10b7dfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ Cicada changelog ================ +0.4.10 (TBA) +------------ + +Features: + +* Fixed Invoker to map subclasses (it is now possible to use a subclass of + Application and it will be properly mapped in callbacks which reference + Application) + 0.4.9 (2014-10-15) ------------------ diff --git a/src/Invoker.php b/src/Invoker.php index b77c6c3..4235f0c 100644 --- a/src/Invoker.php +++ b/src/Invoker.php @@ -178,15 +178,15 @@ private function reindexClassParams(array $classParams) throw new \InvalidArgumentException("\$classParams entries must be objects."); } - $class = get_class($param); - - if (isset($reindexed[$class])) { - throw new \InvalidArgumentException( - "\$classParams contains multiple objects of the same class [$class]." - ); + // Iterate for param class and all parent classes. This way you can + // inject subclasses as well as the specified class + for ($class = get_class($param); $class !== false; $class = get_parent_class($class)) { + if (isset($reindexed[$class])) { + throw new \InvalidArgumentException("\$classParams contains multiple objects of the same class [$class]."); + } + + $reindexed[$class] = $param; } - - $reindexed[$class] = $param; } return $reindexed; diff --git a/tests/InvokerTest.php b/tests/InvokerTest.php index 4d038a5..89dca54 100644 --- a/tests/InvokerTest.php +++ b/tests/InvokerTest.php @@ -26,6 +26,11 @@ function invokerTestFunction(Application $app, Request $request, $foo, $bar) return func_get_args(); } +class ApplicationSubClass extends Application +{ + +} + class InvokerTest extends \PHPUnit_Framework_TestCase { private $namedParams = [ @@ -160,6 +165,33 @@ public function testInvokeObjectMethod() $this->assertEquals($expected5, $actual5); } + public function testInvokeSubClass() + { + // Check that a subclass of Application is properly injected + $app = new ApplicationSubClass(); + $request = new Request(); + $classParams = [$app, $request]; + + $invoker = new Invoker(); + $actual1 = $invoker->invoke("Cicada\Tests\InvokerTestAction::execute1", $this->namedParams, $classParams); + $actual2 = $invoker->invoke("Cicada\Tests\InvokerTestAction::execute2", $this->namedParams, $classParams); + $actual3 = $invoker->invoke("Cicada\Tests\InvokerTestAction::execute3", $this->namedParams, $classParams); + $actual4 = $invoker->invoke("Cicada\Tests\InvokerTestAction::execute4", $this->namedParams, $classParams); + $actual5 = $invoker->invoke("Cicada\Tests\InvokerTestAction::execute5", $this->namedParams, $classParams); + + $expected1 = ['foo_val', 'bar_val']; + $expected2 = ['foo_val', 'bar_val', $request]; + $expected3 = [$app, $request, 'foo_val', 'bar_val']; + $expected4 = [$app, $request, 'foo_val', 'bar_val']; + $expected5 = [$app, $request, 'foo_val', 'bar_val', null]; + + $this->assertEquals($expected1, $actual1); + $this->assertEquals($expected2, $actual2); + $this->assertEquals($expected3, $actual3); + $this->assertEquals($expected4, $actual4); + $this->assertEquals($expected5, $actual5); + } + public function testInvokeFunction() { $app = new Application(); From 190768d13f877f725579cb53a56656d87e5e93a7 Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Tue, 21 Oct 2014 10:44:34 +0200 Subject: [PATCH 3/5] Updated HTTP Foundation to 2.5.x --- CHANGELOG.md | 1 + composer.json | 2 +- composer.lock | 24 ++++++++++++------------ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10b7dfd..25d483c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Features: * Fixed Invoker to map subclasses (it is now possible to use a subclass of Application and it will be properly mapped in callbacks which reference Application) +* Updated HTTP Foundation dependency to 2.5.x 0.4.9 (2014-10-15) ------------------ diff --git a/composer.json b/composer.json index 40ffe3a..580be9c 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "php": ">=5.4.0", "apache/log4php": "2.3.0", "evenement/evenement": "2.0.*", - "symfony/http-foundation": "2.4.*", + "symfony/http-foundation": "2.5.*", "pimple/pimple": "~3.0" }, "require-dev": { diff --git a/composer.lock b/composer.lock index e312f4c..3686cd4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "aa72ffae6a4af3dc6380ddaf5c474bf2", + "hash": "b386fd7facc94787a5069ad0f9cf6217", "packages": [ { "name": "apache/log4php", @@ -130,17 +130,17 @@ }, { "name": "symfony/http-foundation", - "version": "v2.4.10", + "version": "v2.5.5", "target-dir": "Symfony/Component/HttpFoundation", "source": { "type": "git", "url": "https://github.com/symfony/HttpFoundation.git", - "reference": "8e42d9536b5df05f37a9aae5761d3ee69ab95ddf" + "reference": "650e115af152d7a5e857d01c2cdb9a22809de9b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/HttpFoundation/zipball/8e42d9536b5df05f37a9aae5761d3ee69ab95ddf", - "reference": "8e42d9536b5df05f37a9aae5761d3ee69ab95ddf", + "url": "https://api.github.com/repos/symfony/HttpFoundation/zipball/650e115af152d7a5e857d01c2cdb9a22809de9b4", + "reference": "650e115af152d7a5e857d01c2cdb9a22809de9b4", "shasum": "" }, "require": { @@ -152,7 +152,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.4-dev" + "dev-master": "2.5-dev" } }, "autoload": { @@ -179,7 +179,7 @@ ], "description": "Symfony HttpFoundation Component", "homepage": "http://symfony.com", - "time": "2014-09-25 08:51:47" + "time": "2014-09-25 09:52:29" } ], "packages-dev": [ @@ -578,16 +578,16 @@ }, { "name": "phpunit/phpunit", - "version": "4.3.1", + "version": "4.3.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "06005259429c156c02596add91f6a59c7dc3d4af" + "reference": "5a0bc4dcbb7340c0a9a9bc3507854a67c564edc4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/06005259429c156c02596add91f6a59c7dc3d4af", - "reference": "06005259429c156c02596add91f6a59c7dc3d4af", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/5a0bc4dcbb7340c0a9a9bc3507854a67c564edc4", + "reference": "5a0bc4dcbb7340c0a9a9bc3507854a67c564edc4", "shasum": "" }, "require": { @@ -648,7 +648,7 @@ "testing", "xunit" ], - "time": "2014-10-06 06:20:35" + "time": "2014-10-16 16:53:00" }, { "name": "phpunit/phpunit-mock-objects", From 2ab2343bd6e42b32f0e8ba9761366ae987721937 Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Tue, 21 Oct 2014 10:45:38 +0200 Subject: [PATCH 4/5] TravisCI: Added testing on PHP 5.6 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 025a57d..a04da00 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: php php: - 5.5 + - 5.6 - hhvm before_script: From 8837df273f68c3dd2990e3b466eefa8a22be281b Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Tue, 21 Oct 2014 10:53:33 +0200 Subject: [PATCH 5/5] Updated CHANGELOG for 0.4.10 release --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25d483c..35fcf86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ Cicada changelog ================ -0.4.10 (TBA) ------------- +0.4.10 (2014-10-21) +------------------- Features: