PerlStalker's SysAdmin Notes and Tools

- Skip Navigation- Home / squirrelmail / Persistor
- Persistor.php
- PersistorBackend.php

Printer Friendly

Join the Blue Ribbon Online Free Speech Campaign

 

New Persistor class for SquirrelMail

This is a work in progress.

Persistor.php


   1: <?php
   2: 
   3: /**
   4:  * A class for storing and retrieving persistant data.
   5:  *
   6:  * A class for storing and retrieving persistant data. It should be possible
   7:  * to store all basic data types (scalars, arrays, etc.) and selected classes.
   8:  *
   9:  * Perisistor doesn't actually store the data. It relies on a PersistorBackend
  10:  * class to do that.
  11:  *
  12:  * See {@link
    : http://nuts.netdork.net/index.php?objectid=-1891350754&classid=474086490 the brain
    : storming session}
  13:  * on {@link http://nuts.netdork.net/ nuts.netdork.net} for more discussion
  14:  * on how this is supposed to work.
  15:  *
  16:  * See also:
  17:  * - http://www.php.net/manual/en/language.oop.magic-functions.php
  18:  * -
    : http://cvs.sf.net/viewcvs.py/squirrelmail/sm2/lib/persistor/Persistor.inc.php?rev=1.2
  19:  * 
  20:  * @author Randy Smith <perlstalker@falconsroost.alamosa.co.us>
  21:  * @version $Id$
  22:  */
  23: Class Persistor
  24: {
  25:   /**
  26:    * The PersistorBackend that will actually write the data.
  27:    *
  28:    * The backend will each have a unique key to access it.
  29:    */
  30:   var $backends;
  31: 
  32:   /**
  33:    * Constructor
  34:    */
  35:   function Persistor() { }
  36: 
  37:   /**
  38:    * Retrieve the data for the specified key in the table.
  39:    *
  40:    * @param string $backend_id the backend to talk to.
  41:    * @param string $table Table name
  42:    * @param string $key The key to get
  43:    *
  44:    * @return
  45:    */
  46:   function get($backend_id, $table, $key) { }
  47: 
  48:   /**
  49:    * Set the value for the specified key and table.
  50:    *
  51:    * @param string $backend_id the backend to talk to.
  52:    * @param string $table Table name
  53:    * @param string $key The key to get
  54:    * @param mixed The value to set.
  55:    *
  56:    * @return
  57:    */
  58:   function set($backend_id, $table, $key, $value) { }
  59: 
  60:   function load_backend ($backend_id, $backend) { }
  61: 
  62:   /**
  63:    * Clean up at the end of a session.
  64:    */
  65:   function cleanup ()
  66:   {
  67:      # Call __sleep() for each backend.
  68:   }
  69: 
  70:   /**
  71:    * Parse a URI-like description of the backend.
  72:    *
  73:    * Parse a URI-like description of the backend. The URI will include
  74:    * the datastore, host, login creditials, etc.
  75:    */
  76:   function _parse_backend_uri ($uri) {}
  77: 
  78:   function __sleep()
  79:   {
  80:      $this->cleanup();
  81:   }
  82: }
  83: ?>

PersistorBackend.php


   1: <?php
   2: 
   3: /**
   4:  * A class for storing and retrieving persistant data.
   5:  *
   6:  * A class for storing and retrieving persistant data. It should be possible
   7:  * to store all basic data types (scalars, arrays, etc.) and selected classes.
   8:  *
   9:  * Perisistor doesn't actually store the data. It relies on a PersistorBackend
  10:  * class to do that.
  11:  *
  12:  * See {@link
    : http://nuts.netdork.net/index.php?objectid=-1891350754&classid=474086490 the brain
    : storming session}
  13:  * on {@link http://nuts.netdork.net/ nuts.netdork.net} for more discussion
  14:  * on how this is supposed to work.
  15:  *
  16:  * Subclass this for each backend supported. This can include PHP session
  17:  * data.
  18:  *
  19:  * @author Randy Smith <perlstalker@falconsroost.alamosa.co.us>
  20:  * @version $Id$
  21:  */
  22: Class PersistorBackend
  23: {
  24:   function new() { }
  25: 
  26:   /**
  27:    * See if the backend supports a certain feature.
  28:    *
  29:    * This is called by Persistor to determine if the Backend supports
  30:    * a given feature.
  31:    *
  32:    * <code>$rc = $backend->can("store binary");</code>
  33:    *
  34:    * @param string The name of the feature to support.
  35:    *
  36:    * @return True if PersistorBackend supports the feature; False otherwise.
  37:    */
  38:   function can ($feature) { }
  39: 
  40:   /**
  41:    * Write cached writes to the data store.
  42:    *
  43:    * Write cached writes to the data store. Not all Backends need to be
  44:    * flushed, in those cases this is a noop.
  45:    */
  46:   function flush () { }
  47: 
  48:   function __sleep ()
  49:   {
  50:      $this->flush();
  51:   }
  52: }
  53: ?>

Copyright © 2003-2008 Randall B. Smith
<perlstalker AT falconsroost.alamosa.co.us>