Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting - camelCase rather than underscore #108

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions idiorm.php
Original file line number Diff line number Diff line change
Expand Up @@ -1777,6 +1777,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