From 02ab55d3e30fdd17bf85864e72add8940b7b0a93 Mon Sep 17 00:00:00 2001 From: AD7six Date: Wed, 6 Nov 2013 16:37:16 +0000 Subject: [PATCH] don't force strtolower in implemented* behavior methods Since it's a public function don't leave open the possibility that though configuration it doesn't "work" due to case changes. In the behavior class, return without case manipulation - take care of that in the behavior registry class. Also add documentation for implemented* methods --- Cake/ORM/Behavior.php | 31 +++++++++++++++++++++++-- Cake/Test/TestCase/ORM/BehaviorTest.php | 12 +++++----- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/Cake/ORM/Behavior.php b/Cake/ORM/Behavior.php index 524383bfb58..4eb96bfb99b 100644 --- a/Cake/ORM/Behavior.php +++ b/Cake/ORM/Behavior.php @@ -169,6 +169,20 @@ public function implementedEvents() { /** * implementedFinders * + * provides and alias->methodname map of which finders a behavior implements. Example: + * + * [ + * 'this' => 'findThis', + * 'alias' => 'findMmethodName' + * ] + * + * With the above example, a call to `$Table->find('this')` will call `$Behavior->findThis()` + * and a call to `$Table->find('alias')` will call `$Behavior->findMethodName()` + * + * It is recommended, though not required, to override this method in child classes such that + * it is not necessary to use reflections to derive the available method list. See core + * behaviors for an example + * * @return array */ public function implementedFinders() { @@ -183,6 +197,20 @@ public function implementedFinders() { /** * implementedMethods * + * provides and alias->methodname map of which methods a behavior implements. Example: + * + * [ + * 'method' => 'method', + * 'aliasedmethod' => 'somethingElse' + * ] + * + * With the above example, a call to `$Table->method()` will call `$Behavior->method()` + * and a call to `$Table->aliasedmethod()` will call `$Behavior->somethingElse()` + * + * It is recommended, though not required, to override this method in child classes such that + * it is not necessary to use reflections to derive the available method list. See core + * behaviors for an example + * * @return array */ public function implementedMethods() { @@ -229,10 +257,9 @@ protected function _reflectionMethods() { if (strpos($methodName, '_') === 0 || isset($eventMethods[$methodName])) { continue; } - $methodName = strtolower($methodName); if (substr($methodName, 0, 4) === 'find') { - $return['finders'][substr($methodName, 4)] = $methodName; + $return['finders'][lcfirst(substr($methodName, 4))] = $methodName; } else { $return['methods'][$methodName] = $methodName; } diff --git a/Cake/Test/TestCase/ORM/BehaviorTest.php b/Cake/Test/TestCase/ORM/BehaviorTest.php index f961b33df7d..d3efe3eb849 100644 --- a/Cake/Test/TestCase/ORM/BehaviorTest.php +++ b/Cake/Test/TestCase/ORM/BehaviorTest.php @@ -114,7 +114,7 @@ public function testImplementedMethods() { $table = $this->getMock('Cake\ORM\Table'); $behavior = new Test2Behavior($table); $expected = [ - 'dosomething' => 'dosomething' + 'doSomething' => 'doSomething' ]; $this->assertEquals($expected, $behavior->implementedMethods()); } @@ -128,11 +128,11 @@ public function testImplementedMethodsAliased() { $table = $this->getMock('Cake\ORM\Table'); $behavior = new Test2Behavior($table, [ 'implementedMethods' => [ - 'aliased' => 'dosomething' + 'aliased' => 'doSomething' ] ]); $expected = [ - 'aliased' => 'dosomething' + 'aliased' => 'doSomething' ]; $this->assertEquals($expected, $behavior->implementedMethods()); } @@ -160,7 +160,7 @@ public function testImplementedFinders() { $table = $this->getMock('Cake\ORM\Table'); $behavior = new Test2Behavior($table); $expected = [ - 'foo' => 'findfoo' + 'foo' => 'findFoo' ]; $this->assertEquals($expected, $behavior->implementedFinders()); } @@ -174,11 +174,11 @@ public function testImplementedFindersAliased() { $table = $this->getMock('Cake\ORM\Table'); $behavior = new Test2Behavior($table, [ 'implementedFinders' => [ - 'aliased' => 'findfoo' + 'aliased' => 'findFoo' ] ]); $expected = [ - 'aliased' => 'findfoo' + 'aliased' => 'findFoo' ]; $this->assertEquals($expected, $behavior->implementedFinders()); }