Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions paris.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,16 @@ public static function __callStatic($method, $parameters) {
*
* @param string $name
* @param array $arguments
* @return ORMWrapper
* @return bool|ORMWrapper
*/
public function __call($name, $arguments) {
$method = strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $name));
return call_user_func_array(array($this, $method), $arguments);
if (method_exists($this, $method)) {
return call_user_func_array(array($this, $method), $arguments);
} else {
throw new ParisMethodMissingException("Method $name() does not exist in class " . get_class($this));
}
}
}

class ParisMethodMissingException extends Exception {}
17 changes: 16 additions & 1 deletion test/ParisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,19 @@ public function testFindResultSet() {
$this->assertSame(count($result_set), 5);
}

}
/**
* @expectedException ParisMethodMissingException
*/
public function testInvalidModelFunctionCallDoesNotRecurse() {
$model = new Model();
$model->noneExistentFunction();
}

/**
* @expectedException IdiormMethodMissingException
*/
public function testInvalidORMWrapperFunctionCallDoesNotRecurse() {
$ORMWrapper = Model::factory('Simple');
$ORMWrapper->noneExistentFunction();
}
}
14 changes: 12 additions & 2 deletions test/idiorm.php
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,11 @@ public function __call($name, $arguments)
{
$method = strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $name));

return call_user_func_array(array($this, $method), $arguments);
if (method_exists($this, $method)) {
return call_user_func_array(array($this, $method), $arguments);
} else {
throw new IdiormMethodMissingException("Method $name() does not exist in class " . get_class($this));
}
}

/**
Expand Down Expand Up @@ -2147,7 +2151,11 @@ public function unserialize($serialized) {
*/
public function __call($method, $params = array()) {
foreach($this->_results as $model) {
call_user_func_array(array($model, $method), $params);
if (method_exists($model, $method)) {
call_user_func_array(array($model, $method), $params);
} else {
throw new IdiormMethodMissingException("Method $method() does not exist in class " . get_class($this));
}
}
return $this;
}
Expand All @@ -2157,3 +2165,5 @@ public function __call($method, $params = array()) {
* A placeholder for exceptions eminating from the IdiormString class
*/
class IdiormStringException extends Exception {}

class IdiormMethodMissingException extends Exception {}