[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/config/ -> configabstractstorage.class.php (source)

   1  <?php
   2  
   3      
   4  
   5      define( "TYPE_INTEGER", 1 );
   6      define( "TYPE_BOOLEAN", 2 );
   7      define( "TYPE_STRING",  3 );
   8      define( "TYPE_OBJECT",  4 );
   9      define( "TYPE_ARRAY",   5 );
  10      define( "TYPE_FLOAT",   6 );
  11  
  12      /**
  13       * \ingroup Config
  14       *
  15       * Interface class that defines the methods that should be implemented
  16       * by child classes wishing to implement a configuratino settings storage backend.
  17       * 
  18       * This class cannot be instantiated directly, and an attempt to call any of its methods
  19       * will end our script.
  20       */
  21      class ConfigAbstractStorage  
  22      {
  23  
  24      	function ConfigAbstractStorage( $params = null )
  25          {
  26              
  27          }
  28  
  29          /**
  30           * Returns a constant determining the type of the value passed as parameter. The constants
  31           * are:
  32           * - TYPE_INTEGER = 1
  33           * - TYPE_BOOLEAN = 2
  34           * - TYPE_STRING = 3
  35           * - TYPE_OBJECT = 4
  36           * - TYPE_ARRAY = 5
  37           * - TYPE_FLOAT = 6
  38           * 
  39           *
  40           * @param value The value from which we'd like to know its type
  41           * @return Returns one of the above.
  42           */
  43          function _getType( $value )
  44          {
  45              if( is_integer( $value ))
  46                  $type = TYPE_INTEGER;
  47              elseif( is_float( $value ))
  48                  $type = TYPE_FLOAT;
  49              elseif( is_bool( $value ))
  50                  $type = TYPE_BOOLEAN;
  51              elseif( is_string( $value ))
  52                  $type = TYPE_STRING;
  53              elseif( is_object( $value ))
  54                  $type = TYPE_OBJECT;
  55              elseif( is_array( $value ))
  56                  $type = TYPE_ARRAY;
  57              else
  58                  $type = TYPE_STRING;
  59  
  60              //print("type = ".$type."<br/>" );
  61  
  62              return $type;
  63          }
  64  
  65          /**
  66           * Given a key, gets its value from the storage backend. 
  67           *
  68           * @param key The key that we're looking for
  69           * @param defaultValue Optional, if the key does not exist we can provide a second parameter that
  70           * will be returned as the default value
  71           * @return The value assigned to the key or $defaultValue if there was no such key found
  72           */
  73          function getValue( $key, $defaultValue = null )
  74          {
  75              throw( new Exception( "ConfigAbstractStorage::getValue: This method must be implemented by child classes." ));
  76              die();
  77          }
  78  
  79          /**
  80           * Sets a value in the storage area. It is up to the storage backend implementation to either 
  81           * save the data right away after calling this method or whether it is needed to call
  82           * ConfigAbstractStorage::save() in order to do so.
  83           *
  84           * @param key The key that we'd like to save
  85           * @param value The value that should be assigned to this key
  86           * @return True if successful or false otherwise
  87           */
  88          function setValue( $key, $value )
  89          {
  90              throw( new Exception( "ConfigAbstractStorage::setValue: This method must be implemented by child classes." ));
  91              die();
  92          }
  93  
  94          /**
  95           * Returns all the configuration parameters as an associative array
  96           *
  97           * @return An associative array
  98           */
  99          function getAsArray()
 100          {
 101              throw( new Exception( "ConfigAbstractStorage::getAsArray: This method must be implemented by child classes." ));
 102              die();
 103          }
 104  
 105          /**
 106           * triggers a reload of all the settings from the backend.
 107           *
 108           * @return True if successful or false otherwise
 109           */
 110          function reload()
 111          {
 112              throw( new Exception( "ConfigAbstractStorage::reload: This method must be implemented by child classes." ));
 113              die();
 114          }
 115  
 116          /**
 117           * returns the name of the configuration file where data is being saved. If the backend does not
 118           * use a configuration file, the result of this method is an empty string
 119           *
 120           * @return name of the config file, or empty if not used
 121           */
 122          function getConfigFileName()
 123          {
 124              throw( new Exception( "ConfigAbstractStorage::getConfigFileName: This method must be implemented by child classes." ));
 125              die();
 126          }
 127  
 128          /**
 129           * Returns an associative array with all the keys that are in the storage backend
 130           *
 131           * @return An associative array, or an empty array if there are no keys
 132           */
 133          function getKeys()
 134          {
 135              throw( new Exception( "ConfigAbstractStorage::getKeys: This method must be implemented by child classes." ));
 136              die();
 137          }
 138  
 139          /**
 140           * Returns an array including only the values that are availalbe in the storage backend
 141           *
 142           * @return An array with only the values, or an empty array if there are no values.
 143           */
 144          function getValues()
 145          {
 146              throw( new Exception( "ConfigAbstractStorage::getValues: This method must be implemented by child classes." ));
 147              die();
 148          }
 149  
 150          /**
 151           * saves only one value to the configuration backend. This should save the value right away
 152           * without the need to call ConfigAbstractStorage::save() afterwards
 153           *
 154           * @param key The name of the key that we'd like to save
 155           * @param value The value of the key that we'd like to save
 156           * @return true if successful or false otherwise
 157           */
 158          function saveValue( $key, $value )
 159          {
 160              throw( new Exception( "ConfigAbstractStorage::saveValue: This method must be implemented by child classes." ));
 161              die();
 162          }
 163  
 164          /**
 165           * saves all the keys and their values to disk
 166           *
 167           * @return true if successful or false otherwise
 168           */
 169          function save()
 170          {
 171              throw( new Exception( "ConfigAbstractStorage::saveValue: This method must be implemented by child classes." ));
 172              die();
 173          }
 174          
 175  
 176          /**
 177           * shortcut for one of the most sought after config keys: temp_folder
 178           *
 179           * not really needed, but it makes my life easier since I never remember
 180           * whether it is tmp_folder, temp_folder, temp_dir, or whatever :)
 181           *
 182           * @return The name of the folder used for temporary storage
 183           */
 184  		function getTempFolder()
 185          {
 186              return $this->getValue( "temp_folder" );
 187          }
 188      }
 189  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics