diff options
author | Chris Cornutt <chris.cornutt@hp.com> | 2014-12-12 14:25:44 -0600 |
---|---|---|
committer | Chris Cornutt <chris.cornutt@hp.com> | 2014-12-12 14:25:44 -0600 |
commit | aee3ab832f51a5bb2e98c49112c72c3978f2eafc (patch) | |
tree | 86e77f8a5cdff21f4963b93ddf3191651268851c | |
parent | 77845b45cc482d657ee84c921b74907730913357 (diff) | |
download | gatekeeper-aee3ab832f51a5bb2e98c49112c72c3978f2eafc.zip gatekeeper-aee3ab832f51a5bb2e98c49112c72c3978f2eafc.tar.gz gatekeeper-aee3ab832f51a5bb2e98c49112c72c3978f2eafc.tar.bz2 |
overwriting the makeModelInstance method instead of all of __get0.2
-rw-r--r-- | src/Psecio/Gatekeeper/Model/Mysql.php | 41 |
1 files changed, 6 insertions, 35 deletions
diff --git a/src/Psecio/Gatekeeper/Model/Mysql.php b/src/Psecio/Gatekeeper/Model/Mysql.php index 5a817a8..7e814bf 100644 --- a/src/Psecio/Gatekeeper/Model/Mysql.php +++ b/src/Psecio/Gatekeeper/Model/Mysql.php @@ -70,44 +70,15 @@ class Mysql extends \Modler\Model } /** - * Get the value of a current property + * Make a new model instance * - * @param string $name Property name - * @return mixed The property value if found, null if not + * @param string $model Model namespace "path" + * @return object Model instance */ - public function __get($name) + public function makeModelInstance($model) { - $property = $this->getProperty($name); - - if ($property == null) { - throw new \InvalidArgumentException('Property "'.$name.'" is invalid'); - } - - // See if it's a relation - if (isset($property['type']) && strtolower($property['type']) == 'relation') { - $model = $property['relation']['model']; - $method = $property['relation']['method']; - $local = $property['relation']['local']; - - if (!class_exists($model)) { - throw new \InvalidArgumentException('Model "'.$model.'" does not exist'); - } - - $instance = new $model($this->getDb()); - if (!method_exists($instance, $method)) { - throw new \InvalidArgumentException('Method "'.$method.'" does not exist on model '.get_class($instance)); - } - $params = array( - (isset($this->values[$local])) ? $this->values[$local] : null - ); - - call_user_func_array(array($instance, $method), $params); - return $instance; - } - - // If not, probably just a value - return that (or null) - return (array_key_exists($name, $this->values)) - ? $this->values[$name] : null; + $instance = new $model($this->getDb()); + return $instance; } /** |