PHP Classes
elePHPant
Icontem

File: Xyndravandria/Dyverath/Cache.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Mauro Di Girolamo  >  Xyndravandria Dyverath  >  Xyndravandria/Dyverath/Cache.php  >  Download  
File: Xyndravandria/Dyverath/Cache.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Xyndravandria Dyverath
Compose and execute MySQL database queries
Author: By
Last change:
Date: 2 years ago
Size: 6,041 bytes
 

Contents

Class file image Download
<?php
/*
=============================================================================================================================================
| This file is part of a project released under the terms of the Xyndravandria PHP License (XyndravandriaPHPLicense.txt). |
| |
| You should be given a copy of the Xyndravandria PHP License (XyndravandriaPHPLicense.txt) within the same directory as the README.md; |
| if not, you can get a copy at http://Xyndravandria.ohost.de/XyndravandriaPHPLicense.txt . |
| |
| The copyright (c) of this project is owned by Mauro Di Girolamo <maurodigirolamo@.web.de>. |
============================================================================================================================================|



Xyndravandria Dyverath
----------------------
Alpha 0.0.0

Xyndravandria is the name of a collection of projects designed and developed by Mauro Di Girolamo (maurodigirolamo@web.de); he is therefore the copyright (c) owner of Xyndravandria itself and all of its projects.

Xyndravandria Dyverath is released under the terms of the Xyndravandria PHP License (XyndravandriaPHPLicense.txt). You should be given a copy of the Xyndravandria PHP License (XyndravandriaPHPLicense.txt) within the same directory as the README.md; if not, you can get a copy at http://Xyndravandria.ohost.de/XyndravandriaPHPLicense.txt . There might be a release under a freer license for a later, more stable version.

The documentation is either included in ./admin_media/Documentation/ or can be read at http://Xyndravandria.ohost.de/Dyverath/Documentation/.

All projects:

   Xyndravandria Averazain
   http://github.com/MauroDiGirolamo/Xyndravandria_Averazain
   PHP
   Averazain is an Ajax framework supporting also JavaScript disabled clients perfectly - including search engines like Google.
  
   Xyndravandria Dyverath
   http://github.com/MauroDiGirolamo/Xyndravandria_Dyverath
   PHP
   Dyverath is a database access wrapper.
  
   Xyndravandria Erozaver
   http://github.com/MauroDiGirolamo/Xyndravandria_Erozaver
   PHP
   Erozaver is a class extending the type hinting given by the PHP engine (additional support for basic type hinting and size constraints).
  
   Xyndravandria Mondraviel
   http://github.com/MauroDiGirolamo/Xyndravandria_Mondraviel
   PHP
   Mondraviel is a class used to separate HTML from PHP code by firstly register models - files containing place holders embedded in HTML code - and then later fill them dynamically with content by passing values for the place holders.
*/

namespace Xyndravandria\Dyverath;

/// A class to Cache a certain types of instances. @n
/// The class of theses objects has to implement the
/// Cacheable interface.
/// @abstract
class Cache {
  
  
/// The objects in the Cache.
   /// <dl class = "type"><dt><b>%Type:</b></dt>
   /// <dd>array of Cache::$Type</dd></dl>
   /// @private
  
private $Object;
  
  
/// The last object cached.
   /// <dl class = "return"><dt><b>%Type:</b></dt>
   /// <dd>Cache::$Type</dd></dl>
   /// @private
  
private $CurrentObject = null;
  
  
/// The class of the instances to be saved.
   /// <dl class = "type"><dt><b>%Type:</b></dt>
   /// <dd>string</dd></dl>
   /// @private
  
private $Class;
  
  
/// Creates a new Cache.
   /// @public
   /// @param string $Class: The class of the instances
   /// to Cache.
  
public function __construct( $Class ) {
     
//\settype( $Class, 'string' );
     
$this->Object = array( );
     
$this->Class = $Class;
      return;
   }
  
  
/// Adds an object to the Cache.
   /// @public
   /// @param object $Object: The object to be added to
   /// the Cache.
  
public function Add( $Object ) {
     
//\settype( $Object, 'object' );
     
if( \get_class( $Object ) != $this->Class )
         throw new
XyndravandriaDyverathException( 'Unable to add $Object to the Cache, since its class is not \'' . $this->Class . '\'.' );
      else if( ! (
$Object instanceof Cacheable ) )
         throw new
XyndravandriaDyverathException( 'Unable to add $Object to the Cache, since it dies not implement Cacheable.' );
      else if(
$this->Get( $Object->UniqueIdentifier( ) ) )
         throw new
XyndravandriaDyverathException( 'Unable to add $Object to the Cache, since it is already saved.' );
      else
         return
$this->Object[ ] = $this->CurrentObject = $Object;
      return;
   }
  
  
/// Gets an object in the Cache by its unique
   /// identifier.
   /// @public
   /// @param string $UniqueIdentifier: The unique
   /// identifier of the object to get.
   /// @returns Cache::$Type or false
  
public function Get( $UniqueIdentifier ) {
     
//\settype( $UniqueIdentifier, 'string' );
     
foreach( $this->Object as $Object )
         if(
$Object->UniqueIdentifier( ) == $UniqueIdentifier )
            return
$Object;
      return
false;
   }
    
  
/// Returns Cache::$CurrentObject.
   /// @public
   /// @returns Cache::$Type or null
  
public function CurrentObject( ) {
      return
$this->CurrentObject;
   }
  
}

/// The interface of CacheableObject.
interface Cacheable {
  
  
/// Should return the Cacheable object's Cache.
   /// @public
   /// @static
   /// @returns Cache
  
static function Cache( );
  
  
/// Gets an identifier which is unique for all
   /// instances of the class which implements this
   /// interface.
   /// @public
   /// @returns string
  
function UniqueIdentifier( );
  
  
/// Should be overriden in a subclass and then return
   /// its declared name without the namespace.
   /// @abstract
   /// @static
   /// @returns string
  
static function ClassName( );
  
}
?>