ORM::__call PHP Method

__call() public method

In this case we are attempting to convert camel case formatted methods into underscore formatted methods. This allows us to call ORM methods using camel case and remain backwards compatible.
public __call ( string $name, array $arguments ) : ORM
$name string
$arguments array
return ORM
    public function __call($name, $arguments)
    {
        $method = strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $name));
        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));
        }
    }

Usage Example

Exemplo n.º 1
0
Arquivo: page.php Projeto: nergal/2mio
 public function __call($method, array $args)
 {
     if ($method != 'loaded' and $this->loaded()) {
         $exploded = explode('_', strtolower($method));
         if (count($exploded) == 3 and $exploded[2] == 'count') {
             $type = $action = NULL;
             if (in_array($exploded[0], array('increment', 'decrement'))) {
                 $action = $exploded[0];
             }
             if (in_array($exploded[1], array('views', 'comments'))) {
                 $type = $exploded[1];
             }
             if ($type !== NULL and $action !== NULL) {
                 $key = array('count', $type, $this->id, date('Ymd'));
                 $key = implode('_', $key);
                 $default = parent::__get($type . '_count');
                 $result = Cache::instance('memcache')->{$action}($key, 1, $default);
                 return $result;
             }
         }
     }
     return parent::__call($method, $args);
 }
ORM