Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AD7six committed Nov 10, 2013
1 parent 8569323 commit 02ab55d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
31 changes: 29 additions & 2 deletions Cake/ORM/Behavior.php
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions Cake/Test/TestCase/ORM/BehaviorTest.php
Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand Down Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand Down

0 comments on commit 02ab55d

Please sign in to comment.