phpPoA2
[ class tree: phpPoA2 ] [ index: phpPoA2 ] [ all elements ]

Source for file GenericDB.php

Documentation is available at GenericDB.php

  1. <?php
  2. /**
  3.  * @copyright Copyright 2005-2010 RedIRIS, http://www.rediris.es/
  4.  *
  5.  *  This file is part of phpPoA2.
  6.  *
  7.  *  phpPoA2 is free software: you can redistribute it and/or modify
  8.  *  it under the terms of the GNU General Public License as published by
  9.  *  the Free Software Foundation, either version 3 of the License, or
  10.  *  (at your option) any later version.
  11.  *
  12.  *  phpPoA2 is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *  GNU General Public License for more details.
  16.  *
  17.  *  You should have received a copy of the GNU General Public License
  18.  *  along with phpPoA2. If not, see <http://www.gnu.org/licenses/>.
  19.  *
  20.  * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
  21.  * @version 2.0
  22.  * @author Candido Rodriguez <candido.rodriguez@rediris.es>
  23.  * @filesource
  24.  */
  25.  
  26. /**
  27.  * Provides the basic operations and defines the interface of any DB operating class.
  28.  * @package phpPoA2
  29.  * @subpackage GenericDatabaseHandlers
  30.  */
  31. abstract class GenericDB {
  32.  
  33.     protected $cfg;
  34.     protected $error = null;
  35.     protected $db;
  36.     protected $mandatory_options = array();
  37.  
  38.     /**
  39.      * Main constructor.
  40.      * @param cfg A *Configurator object with the current configuration.
  41.      */
  42.     public function __construct($cfg{
  43.         if (!$cfg instanceof GenericConfigurator{
  44.             throw new PoAException('invalid-config'E_USER_ERRORarray());
  45.         }
  46.         $this->cfg = $cfg;
  47.         $this->configure();
  48.     }
  49.  
  50.     /**
  51.      * Configure the database handler.
  52.      * @return boolean true if success, PoAException if error.
  53.      */
  54.     protected function configure({
  55.         // validate mandatory params
  56.         $this->cfg->validate($this->mandatory_options);
  57.     }
  58.  
  59.     /**
  60.      * Opens the database.
  61.      * @return boolean true if success, false if error.
  62.      */
  63.     abstract public function open();
  64.  
  65.     /**
  66.      * Closes the database.
  67.      * @return boolean true if success, false if error.
  68.      */
  69.     abstract public function close();
  70.  
  71.     /**
  72.      * Checks if the specified key exists in the database.
  73.      * @param key The key to look for.
  74.      * @return boolean true if the key exists, false otherwise.
  75.      */
  76.     abstract public function check($key);
  77.  
  78.     /**
  79.      * Replaces the specified key with a new value. If the key does not
  80.      * exist previously, it will be created.
  81.      * @param key The key to replace.
  82.      * @param value The new value for the specified key.
  83.      * @return boolean true if success, false if error.
  84.      */
  85.     abstract public function replace($key$value);
  86.  
  87.     /**
  88.      * Gets the value of the specified key.
  89.      * @param key The key to look for.
  90.      * @return mixed|booleanThe value for that key, false if it does not exist.
  91.      */
  92.     abstract public function fetch($key);
  93.  
  94.     /**
  95.      * Gets all the contents stored in the database.
  96.      * @return array An array with all the rows of the database.
  97.      */
  98.     abstract public function fetch_all();
  99.  
  100.     /**
  101.      * Removes the specified key from the database.
  102.      * @param key The key to remove.
  103.      * @return boolean true if success, false if error.
  104.      */
  105.     abstract public function delete($key);
  106. }
  107.  
  108. ?>

Documentation generated on Tue, 25 Jan 2011 11:24:29 +0100 by phpDocumentor 1.4.3