From eea60cbd0564e26e4e6596ccb890aa406a40fb32 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 12 Apr 2012 14:44:38 -0400 Subject: [PATCH] Move settings class to Query --- sys/common/settings.php | 240 ---------------------------------- sys/db | 2 +- tests/db_files/FB_TEST_DB.FDB | Bin 933888 -> 933888 bytes 3 files changed, 1 insertion(+), 241 deletions(-) delete mode 100644 sys/common/settings.php diff --git a/sys/common/settings.php b/sys/common/settings.php deleted file mode 100644 index caecafe..0000000 --- a/sys/common/settings.php +++ /dev/null @@ -1,240 +0,0 @@ -current = new stdClass(); - } - else - { - $this->current = json_decode(file_get_contents($path)); - } - - // Add the DB object under the settings if it doesn't already exist - if( ! isset($this->current->dbs)) - { - $this->current->dbs = new stdClass(); - } - - } - - // -------------------------------------------------------------------------- - - /** - * Output the settings on destruct - */ - public function __destruct() - { - $file_string = (defined('JSON_PRETTY_PRINT')) - ? json_encode($this->current, JSON_PRETTY_PRINT) - : json_encode($this->current); - - file_put_contents(SETTINGS_DIR . '/settings.json', $file_string); - } - - // -------------------------------------------------------------------------- - - /** - * Magic method to simplify isset checking for config options - * - * @param string $key - * @return mixed - */ - public function __get($key) - { - return (isset($this->current->{$key}) && $key != "dbs") - ? $this->current->{$key} - : NULL; - } - - // -------------------------------------------------------------------------- - - /** - * Magic method to simplify setting config options - * - * @param string $key - * @param mixed - */ - public function __set($key, $val) - { - //Don't allow direct db config changes - if($key == "dbs") - { - return FALSE; - } - - return $this->current->{$key} = $val; - } - - // -------------------------------------------------------------------------- - - /** - * Add a database connection - * - * @param string $name - * @param array $params - */ - public function add_db($name, $params) - { - // Return on bad data - if (empty($name) || empty($params)) - { - return FALSE; - } - - if( ! isset($this->current->dbs->{$name})) - { - $params['name'] = $name; - - $this->current->dbs->{$name} = array(); - $this->current->dbs->{$name} = $params; - } - else - { - return FALSE; - } - - // Save the json - $this->__destruct(); - } - - // -------------------------------------------------------------------------- - - /** - * Edit a database connection - * - * @param array $params - */ - public function edit_db($name, $params) - { - // Return on bad data - if (empty($name) || empty($params)) - { - return FALSE; - } - - if (isset($this->current->dbs->{$name}) && ($name === $params['name'])) - { - $this->current->dbs->{$name} = $params; - } - elseif ($name !== $params['name']) - { - unset($this->current->dbs->{$name}); - - if ( ! isset($this->current->dbs->{$params['name']})) - { - $this->current->dbs->{$params['name']} = $params; - } - else - { - return FALSE; - } - } - else - { - return FALSE; - } - - // Save the json - $this->__destruct(); - - return TRUE; - } - - // -------------------------------------------------------------------------- - - /** - * Remove a database connection - * - * @param string $name - */ - public function remove_db($name) - { - if( ! isset($this->current->dbs->{$name})) - { - return FALSE; - } - - // Remove the db name from the object - unset($this->current->dbs->{$name}); - - // Save the json - $this->__destruct(); - } - - // -------------------------------------------------------------------------- - - /** - * Retreive all db connections - * - * @return array - */ - public function get_dbs() - { - return $this->current->dbs; - } - - // -------------------------------------------------------------------------- - - /** - * Retreive a specific database connection - * - * @param string $name - * @return object - */ - public function get_db($name) - { - return (isset($this->current->dbs->{$name})) - ? $this->current->dbs->{$name} - : FALSE; - } - -} -// End of settings.php \ No newline at end of file diff --git a/sys/db b/sys/db index 74e8f99..773e7b8 160000 --- a/sys/db +++ b/sys/db @@ -1 +1 @@ -Subproject commit 74e8f99fd89d394124eb2639dfca9889c71bc39b +Subproject commit 773e7b8b805783ccefcfae17583f077ce8672996 diff --git a/tests/db_files/FB_TEST_DB.FDB b/tests/db_files/FB_TEST_DB.FDB index 9dfcfc9712adfff65b93a8b753c98c72d1014fa1..4f729036353bdac20bbb8f0b9434dd5e62cabac5 100755 GIT binary patch delta 382 zcmZo@uxx0s^kZbOG&rlofB*vA4a`s;h;CD4VCV#51_ma^*|!)NLd?&rt4Tu?2rw`K zVFH-L2qfDSw<`uPZsKneXcJ&;6JTl+U~Us&X%k>=6JTo-U~d!PXcOSvCcwoaz}U5& zRe`I3V|$4PS2uf`0oOJIZk7#k8mth5VPqJiFvAfxRfZ5w4F(QQRR$3b1%?moN(@Ih z6&OM|cp1*HD>E!%*I=mORAz7i@(qBr36O38ibt@kf{j_gsl>2_jhEpK+xDaf+(B%D zARp}mOEEGq>XzrXO+WgK+n=#*y6AImXCO860k_KZ+UMNrK=#uI+}?~G(+wYTJ1fHU zF);x3<)j{k@qs)b1p0n@=nL+>(|5h+mY%NrlG||luXjLJC5ZLv5w}MBrI*}5%(MN{ IOJ2P&0F0+r0RR91 delta 386 zcmYL^F-rqM5QX0+x#aG~!xae#g5(kpLr{`Jkl2Z3zyygYRYVU9L5rXu7DvDh_y@Mo zLi`14;n`>!Q&`zsB_hUa6u~}jqQM#Fz5Ql(7S{9fo|j)@$mbrD_zzBA_>X#Cvw>q( zK!}|_1Le7=DQEom0!K*YdLNk5n(f;qc0F9Bd1(99DExVT4oBb%6qY?TR7AGjTS9OM_l!v`+l2&%^d8yviU|u=E``77L{Fn zk}VHAlu_re4=S*2*?yr3S!|PI50*nv%R5`m0V`4oxN_y4?&L*_#$+a-Sq8ZlP(jYO QDPC^`q-w}-1lB_32a^L;Pyhe`