gabordemooij / redbean

ORM layer that creates models, config and database on the fly
https://www.redbeanphp.com
2.31k stars 280 forks source link

Allowing __call() in models #115

Closed ghost closed 12 years ago

ghost commented 12 years ago

One of my models looks like this, (it has been stripped down for testing):

<?php

class mymodel extends RedBean_SimpleModel{
   public function __call($func, $args){
        var_dump($func);
        var_dump($args);
   }
}

Due to method_exists being used on line 356 in RedBean_OODBBean.php, __call() in a model is never called. Would it be possible to remove this check so that all function calls are passed to the model regardless whether they exist or not?

gabordemooij commented 12 years ago

I understand the issue however this is by design. It is not possible to remove the check because then all calls to optional handlers will fail.

If you need to have this functionality find:

if (!method_exists($this->__info["model"],$method)) return null;

in OODBBean.php and

replace it with:

if (!method_exists($this->__info["model"],$method)) {
    if (!method_exists($this->__info["model"],'magicCall')) { ... call method ... } else return null;

}
ghost commented 12 years ago

Thanks for that snippet :) This is perfect for my needs. Would you be able to push that feature to master?

gabordemooij commented 12 years ago

No sorry, I wont be implementing this is in the master. I think this will cause RedBeanPHP to contain too much magic. There is already a great deal of magic inside, so I would like not to add some more.