Skip to content

Commit

Permalink
Rename magic => dynamic.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Dec 1, 2013
1 parent 168cca3 commit 58b51ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
10 changes: 6 additions & 4 deletions Cake/ORM/Table.php
Expand Up @@ -1226,13 +1226,15 @@ public function callFinder($type, Query $query, $options = []) {
}

/**
* Provides the magic findBy and findByAll methods.
* Provides the dynamic findBy and findByAll methods.
*
* @param string $method The method name that was fired.
* @param array $args List of arguments passed to the function.
* @return mixed.
* @throws Cake\Error\Exception when there are missing arguments, or when
* and & or are combined.
*/
public function _magicFinder($method, $args) {
public function _dynamicFinder($method, $args) {
$method = Inflector::underscore($method);
$findType = 'first';
preg_match('/^find_([\w]+)_by_/', $method, $matches);
Expand Down Expand Up @@ -1299,7 +1301,7 @@ public function _magicFinder($method, $args) {
}

/**
* Handles behavior delegation + magic finders.
* Handles behavior delegation + dynamic finders.
*
* If your Table uses any behaviors you can call them as if
* they were on the table object.
Expand All @@ -1314,7 +1316,7 @@ public function __call($method, $args) {
return $this->_behaviors->call($method, $args);
}
if (strpos($method, 'findBy') === 0 || strpos($method, 'findAllBy') === 0) {
return $this->_magicFinder($method, $args);
return $this->_dynamicFinder($method, $args);
}

throw new \BadMethodCallException(
Expand Down
22 changes: 11 additions & 11 deletions Cake/Test/TestCase/ORM/TableTest.php
Expand Up @@ -1947,7 +1947,7 @@ public function testAfterValidate() {
*
* @return void
*/
public function testMagicFindFirst() {
public function testDynamicFindFirst() {
$table = TableRegistry::get('Users');

$result = $table->findByUsername('garrett');
Expand All @@ -1964,7 +1964,7 @@ public function testMagicFindFirst() {
* @expectedExceptionMessage Not enough arguments to magic finder. Got 0 required 1
* @return void
*/
public function testMagicFindError() {
public function testDynamicFindError() {
$table = TableRegistry::get('Users');

$table->findByUsername();
Expand All @@ -1977,7 +1977,7 @@ public function testMagicFindError() {
* @expectedExceptionMessage Not enough arguments to magic finder. Got 1 required 2
* @return void
*/
public function testMagicFindErrorMissingField() {
public function testDynamicFindErrorMissingField() {
$table = TableRegistry::get('Users');

$table->findByUsernameAndId('garrett');
Expand All @@ -1990,7 +1990,7 @@ public function testMagicFindErrorMissingField() {
* @expectedExceptionMessage Cannot mix "and" & "or" in a magic finder. Use find() instead.
* @return void
*/
public function testMagicFindErrorMixOfOperators() {
public function testDynamicFindErrorMixOfOperators() {
$table = TableRegistry::get('Users');

$table->findByUsernameAndIdOrPassword('garrett', 1, 'sekret');
Expand All @@ -2001,7 +2001,7 @@ public function testMagicFindErrorMixOfOperators() {
*
* @return void
*/
public function testMagicFindFirstAnd() {
public function testDynamicFindFirstAnd() {
$table = TableRegistry::get('Users');

$result = $table->findByUsernameAndId('garrett', 4);
Expand All @@ -2020,7 +2020,7 @@ public function testMagicFindFirstAnd() {
*
* @return void
*/
public function testMagicFindFirstOr() {
public function testDynamicFindFirstOr() {
$table = TableRegistry::get('Users');

$result = $table->findByUsernameOrId('garrett', 4);
Expand All @@ -2042,7 +2042,7 @@ public function testMagicFindFirstOr() {
*
* @return void
*/
public function testMagicFindFirstOrderBy() {
public function testDynamicFindFirstOrderBy() {
$table = TableRegistry::get('Users');

$result = $table->findByAuthorIdOrPublished(1, 'Y', ['id' => 'DESC']);
Expand All @@ -2058,7 +2058,7 @@ public function testMagicFindFirstOrderBy() {
*
* @return void
*/
public function testMagicFindAll() {
public function testDynamicFindAll() {
$table = TableRegistry::get('Articles');

$result = $table->findAllByAuthorId(1);
Expand All @@ -2077,7 +2077,7 @@ public function testMagicFindAll() {
*
* @return void
*/
public function testMagicFindAllAnd() {
public function testDynamicFindAllAnd() {
$table = TableRegistry::get('Users');

$result = $table->findAllByAuthorIdAndPublished(1, 'Y');
Expand All @@ -2094,7 +2094,7 @@ public function testMagicFindAllAnd() {
*
* @return void
*/
public function testMagicFindAllOr() {
public function testDynamicFindAllOr() {
$table = TableRegistry::get('Users');

$result = $table->findAllByAuthorIdOrPublished(1, 'Y');
Expand All @@ -2113,7 +2113,7 @@ public function testMagicFindAllOr() {
*
* @return void
*/
public function testMagicFindAllOrderBy() {
public function testDynamicFindAllOrderBy() {
$table = TableRegistry::get('Users');

$result = $table->findAllByAuthorIdOrPublished(1, 'Y', ['id' => 'DESC']);
Expand Down

0 comments on commit 58b51ce

Please sign in to comment.