Skip to content

Commit

Permalink
Merge pull request #782 from jails/bug/entity-magic-call
Browse files Browse the repository at this point in the history
Fix infinite loop that occurs when an `data\Entity` class is used as `data\Entity::_model`.
  • Loading branch information
nateabele committed Jan 11, 2013
2 parents 0c9e1bd + 5f2fe23 commit 56074bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion data/Entity.php
Expand Up @@ -187,7 +187,7 @@ public function __isset($name) {
* @return mixed
*/
public function __call($method, $params) {
if ($model = $this->_model) {
if (($model = $this->_model) && method_exists($model, '_object')) {
array_unshift($params, $this);
$class = $model::invokeMethod('_object');
return call_user_func_array(array(&$class, $method), $params);
Expand Down
8 changes: 8 additions & 0 deletions tests/cases/data/EntityTest.php
Expand Up @@ -102,6 +102,14 @@ public function testMethodDispatchWithNoModel() {
$entity->foo();
}

public function testMethodDispatchWithEntityAsModel() {
$data = array('foo' => true);
$model = 'lithium\data\Entity';
$entity = new Entity(compact('model', 'data'));
$this->expectException("/^No model bound to call `foo`.$/");
$entity->foo();
}

public function testErrors() {
$entity = new Entity();
$errors = array('foo' => 'Something bad happened.');
Expand Down

0 comments on commit 56074bb

Please sign in to comment.