ORM::__call PHP 메소드

__call() 공개 메소드

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
리턴 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

예제 #1
0
파일: page.php 프로젝트: 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