From 3e7d5c4e225c4ffab8d7b6c85089e96f4aef1440 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 23 Oct 2005 20:46:27 +0000 Subject: [PATCH] - Run action methods using run_action_method() - You can now prevent action methods from running by setting $norunners --- api.php | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/api.php b/api.php index 5132bfd..b029b1a 100644 --- a/api.php +++ b/api.php @@ -122,6 +122,12 @@ class API */ var $insertid = 0; + /** + * Pre- and post-action method stoppers + * @var array + */ + var $norunners = array(); + /** * Constructor: cannot instantiate class directly */ @@ -248,7 +254,7 @@ class API trigger_error('Condition is empty: cannot fetch', E_USER_ERROR); } - $actmethod = (method_exists($this, 'pre_fetch') ? $this->pre_fetch() : ''); + $this->run_action_method('pre_fetch'); $result = $this->registry->modules['db_mysql']->query_first("SELECT * FROM {$this->prefix}{$this->table} WHERE {$this->condition}"); if (!$result) @@ -258,7 +264,7 @@ class API return; } - $actmethod = (method_exists($this, 'post_fetch') ? $this->post_fetch() : ''); + $this->run_action_method('post_fetch'); $this->objdata = $result; } @@ -270,7 +276,7 @@ class API { $this->verify(); - $actmethod = (method_exists($this, 'pre_insert') ? $this->pre_insert() : ''); + $this->run_action_method('pre_insert'); foreach ($this->setfields AS $field) { @@ -281,7 +287,7 @@ class API $this->registry->modules['db_mysql']->query("INSERT INTO {$this->prefix}{$this->table} (" . implode(',', $fields) . ") VALUES (" . implode(',', $values) . ")"); $this->insertid = $this->registry->modules['db_mysql']->insert_id(); - $actmethod = (method_exists($this, 'post_insert') ? $this->post_insert() : ''); + $this->run_action_method('post_insert'); } /** @@ -294,7 +300,7 @@ class API trigger_error('Condition is empty: cannot fetch', E_USER_ERROR); } - $actmethod = (method_exists($this, 'pre_update') ? $this->pre_update() : ''); + $this->run_action_method('pre_update'); foreach ($this->setfields AS $field) { @@ -304,7 +310,7 @@ class API $this->registry->modules['db_mysql']->query("UPDATE {$this->prefix}{$this->table} SET $updates WHERE {$this->condition}"); - $actmethod = (method_exists($this, 'post_update') ? $this->post_update() : ''); + $this->run_action_method('post_update'); } /** @@ -319,11 +325,11 @@ class API $this->set_existing(); - $actmethod = (method_exists($this, 'pre_delete') ? $this->pre_delete() : ''); + $this->run_action_method('pre_delete'); $this->registry->modules['db_mysql']->query("DELETE FROM {$this->prefix}{$this->table} WHERE {$this->condition}"); - $actmethod = (method_exists($this, 'post_delete') ? $this->post_delete() : ''); + $this->run_action_method('post_delete'); } /** @@ -348,6 +354,21 @@ class API } } + /** + * Runs a pre- or post-action method for database commands + * + * @param string Action to run + */ + function run_action_method($method) + { + if (in_array($method, $this->norunners)) + { + return; + } + + $actmethod = (method_exists($this, $method) ? $this->$method() : ''); + } + /** * Verify field: not a zero value */ -- 2.22.5