Skip to content

Commit

Permalink
Added ability to use camel cased methods
Browse files Browse the repository at this point in the history
  • Loading branch information
chris@moderncognition.com authored and treffynnon committed Aug 28, 2013
1 parent ab5535d commit 7b1e19f
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions idiorm.php
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,44 @@ public function __unset($key) {
public function __isset($key) {
return $this->offsetExists($key);
}

/**
* Magic method to capture calls to undefined class methods.
* 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.
*
* @param string $name
* @param array $arguments
* @return ORM
*/
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);
}

/**
* Magic method to capture calls to undefined static class methods.
* 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.
*
* @param string $name
* @param array $arguments
* @return ORM
*/
public static function __callStatic($name, $arguments)
{
$method = strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $name));

return call_user_func_array(array('ORM', $method), $arguments);
}
}

/**
Expand Down

0 comments on commit 7b1e19f

Please sign in to comment.