summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChris Cornutt <chris.cornutt@hp.com>2014-12-16 11:31:32 -0600
committerChris Cornutt <chris.cornutt@hp.com>2014-12-16 11:31:32 -0600
commita3609d2014a5d4f79b621e40495ac02d859a47d8 (patch)
treefcec9ceef85c8fb6ff26872c0070d11b8d22635a /src
parent175fded9739b7558ecab008a8e8459db2993e565 (diff)
downloadgatekeeper-a3609d2014a5d4f79b621e40495ac02d859a47d8.zip
gatekeeper-a3609d2014a5d4f79b621e40495ac02d859a47d8.tar.gz
gatekeeper-a3609d2014a5d4f79b621e40495ac02d859a47d8.tar.bz2
updating the Gatekeeper class with delete handling
Diffstat (limited to 'src')
-rw-r--r--src/Psecio/Gatekeeper/Gatekeeper.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/Psecio/Gatekeeper/Gatekeeper.php b/src/Psecio/Gatekeeper/Gatekeeper.php
index 28a57e2..34eef92 100644
--- a/src/Psecio/Gatekeeper/Gatekeeper.php
+++ b/src/Psecio/Gatekeeper/Gatekeeper.php
@@ -136,6 +136,8 @@ class Gatekeeper
return self::handleFindBy($name, $args);
} elseif ($action == 'create') {
return self::handleCreate($name, $args);
+ } elseif ($action == 'delete') {
+ return self::handleDelete($name, $args);
}
return false;
}
@@ -194,4 +196,45 @@ class Gatekeeper
}
return false;
}
+
+ /**
+ * Handle the delete requests
+ *
+ * @param string $name Function name called
+ * @param array $args Arguments set
+ * @return boolean Success/fail of delete request
+ */
+ public static function handleDelete($name, array $args)
+ {
+ $model = self::buildModel('delete', $name, $args);
+ return $model->delete();
+ }
+
+ /**
+ * Build the model instance with data given
+ *
+ * @param string $action Action called (ex: "delete" or "create")
+ * @param string $name Function nname
+ * @param array $args Arguments set
+ * @throws \Exception\ModelNotFoundException If model type is not found
+ * @return object Model instance
+ */
+ protected static function buildModel($action = 'find', $name, array $args)
+ {
+ $name = str_replace($action, '', $name);
+ preg_match('/By(.+)/', $name, $matches);
+
+ $property = lcfirst($matches[1]);
+ $model = str_replace($matches[0], '', $name);
+ $data = array($property => $args[0]);
+
+ $modelNs = '\\Psecio\\Gatekeeper\\'.$model.'Model';
+ if (!class_exists($modelNs)) {
+ throw new Exception\ModelNotFoundException('Model type '.$model.' could not be found');
+ }
+
+ $instance = new $modelNs(self::$pdo);
+ $instance->find($data);
+ return $instance;
+ }
} \ No newline at end of file