summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChris Cornutt <chris.cornutt@hp.com>2014-12-12 14:12:40 -0600
committerChris Cornutt <chris.cornutt@hp.com>2014-12-12 14:12:40 -0600
commitce258117520a9446a28500f6f23c70dfa5e159c3 (patch)
tree0f215b6c678d97bfc11a5db61f1c91fccd573c9b /src
parent6ba2615d9e7be21f32d70da3634bae4d26f8276d (diff)
downloadgatekeeper-ce258117520a9446a28500f6f23c70dfa5e159c3.zip
gatekeeper-ce258117520a9446a28500f6f23c70dfa5e159c3.tar.gz
gatekeeper-ce258117520a9446a28500f6f23c70dfa5e159c3.tar.bz2
overriding the __get from the main model
Diffstat (limited to 'src')
-rw-r--r--src/Psecio/Gatekeeper/Model/Mysql.php41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/Psecio/Gatekeeper/Model/Mysql.php b/src/Psecio/Gatekeeper/Model/Mysql.php
index fb6355b..5a817a8 100644
--- a/src/Psecio/Gatekeeper/Model/Mysql.php
+++ b/src/Psecio/Gatekeeper/Model/Mysql.php
@@ -70,6 +70,47 @@ class Mysql extends \Modler\Model
}
/**
+ * Get the value of a current property
+ *
+ * @param string $name Property name
+ * @return mixed The property value if found, null if not
+ */
+ public function __get($name)
+ {
+ $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;
+ }
+
+ /**
* Save the current model - switches between create/update
* as needed
*