b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (CVS HEAD) [ class tree: evocore ] [ index: evocore ] [ all elements ]

Source for file _filecache.class.php

Documentation is available at _filecache.class.php

  1. <?php
  2. /**
  3.  * This file implements the FileCache class.
  4.  *
  5.  * This file is part of the evoCore framework - {@link http://evocore.net/}
  6.  * See also {@link http://sourceforge.net/projects/evocms/}.
  7.  *
  8.  * @copyright (c)2003-2010 by Francois PLANQUE - {@link http://fplanque.net/}
  9.  *
  10.  *  {@internal License choice
  11.  *  - If you have received this file as part of a package, please find the license.txt file in
  12.  *    the same folder or the closest folder above for complete license terms.
  13.  *  - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  14.  *    then you must choose one of the following licenses before using the file:
  15.  *    - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  16.  *    - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  17.  *  }}}
  18.  *
  19.  *  {@internal Open Source relicensing agreement:
  20.  *  }}}
  21.  *
  22.  * @package evocore
  23.  *
  24.  *  {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  25.  * @author fplanque: Francois PLANQUE
  26.  *
  27.  * @version $Id: _filecache.class.php,v 1.5 2010/02/08 17:52:18 efy-yury Exp $
  28.  */
  29. if!defined('EVO_MAIN_INIT') ) die'Please, do not access this page directly.' );
  30.  
  31. load_class'_core/model/dataobjects/_dataobjectcache.class.php''DataObjectCache' );
  32.  
  33. /**
  34.  * FileCache Class
  35.  *
  36.  * @package evocore
  37.  */
  38. class FileCache extends DataObjectCache
  39. {
  40.     /**
  41.      * Cache for 'root_type:root_in_type_ID:relative_path' -> File object reference
  42.      * @access private
  43.      * @var array 
  44.      */
  45.     var $cache_root_and_path array();
  46.  
  47.     /**
  48.      * Constructor
  49.      */
  50.     function FileCache()
  51.     {
  52.         parent::DataObjectCache'File'false'T_files''file_''file_ID' );
  53.     }
  54.  
  55.  
  56.     /**
  57.      * Instantiate a DataObject from a table row and then cache it.
  58.      *
  59.      * @param Object Database row
  60.      * @return Object 
  61.      */
  62.     function instantiate$db_row )
  63.     {
  64.         // Get ID of the object we'ere preparing to instantiate...
  65.         $obj_ID $db_row->{$this->dbIDname};
  66.  
  67.          if!empty($obj_ID) )
  68.         {    // If the object ID is valid:
  69.              if!isset($this->cache[$obj_ID]) )
  70.             {    // If not already cached:
  71.                 // Instantiate a File object for this line:
  72.                 $current_File new File$db_row->file_root_type$db_row->file_root_ID$db_row->file_path )// COPY!
  73.                 // Flow meta data into File object:
  74.                 $current_File->load_metafalse$db_row );
  75.                 $this->add$current_File );
  76.             }
  77.             else
  78.             {    // Already cached:
  79.                 $current_File $this->cache[$obj_ID];
  80.                 // Flow meta data into File object:
  81.                 $current_File->load_metafalse$db_row );
  82.             }
  83.         }
  84.  
  85.         return $this->cache[$obj_ID];
  86.     }
  87.  
  88.  
  89.   /**
  90.      * Creates an object of the {@link File} class, while providing caching
  91.      * and making sure that only one reference to a file exists.
  92.      *
  93.      * @param string Root type: 'user', 'group' or 'collection'
  94.      * @param integer ID of the user, the group or the collection the file belongs to...
  95.      * @param string Subpath for this file/folder, relative the associated root, including trailing slash (if directory)
  96.      * @param boolean check for meta data?
  97.      * @return File {@link File} object
  98.      */
  99.     function get_by_root_and_path$root_type$root_in_type_ID$rel_path$load_meta false )
  100.     {
  101.         global $Debuglog$cache_File;
  102.  
  103.         ifis_windows() )
  104.         {
  105.             $rel_path strtolower(str_replace'\\''/'$rel_path ));
  106.         }
  107.  
  108.         // Generate cache key for this file:
  109.         $cacheindex $root_type.':'.$root_in_type_ID.':'.$rel_path;
  110.  
  111.         ifisset$this->cache_root_and_path[$cacheindex) )
  112.         {    // Already in cache
  113.             $Debuglog->add'File retrieved from cache: '.$cacheindex'files' );
  114.             $File $this->cache_root_and_path[$cacheindex];
  115.             if$load_meta )
  116.             {    // Make sure meta is loaded:
  117.                 $File->load_meta();
  118.             }
  119.         }
  120.         else
  121.         {    // Not in cache
  122.             $Debuglog->add'File not in cache: '.$cacheindex'files' );
  123.             $File new File$root_type$root_in_type_ID$rel_path$load_meta )// COPY !!
  124.             $this->cache_root_and_path[$cacheindex$File;
  125.         }
  126.         return $File;
  127.     }
  128.  
  129.  
  130. }
  131.  
  132. /*
  133.  * $Log: _filecache.class.php,v $
  134.  * Revision 1.5  2010/02/08 17:52:18  efy-yury
  135.  * copyright 2009 -> 2010
  136.  *
  137.  * Revision 1.4  2009/09/14 13:04:53  efy-arrin
  138.  * Included the ClassName in load_class() call with proper UpperCase
  139.  *
  140.  * Revision 1.3  2009/03/08 23:57:43  fplanque
  141.  * 2009
  142.  *
  143.  * Revision 1.2  2008/01/21 09:35:28  fplanque
  144.  * (c) 2008
  145.  *
  146.  * Revision 1.1  2007/06/25 10:59:54  fplanque
  147.  * MODULES (refactored MVC)
  148.  *
  149.  * Revision 1.7  2007/04/26 00:11:10  fplanque
  150.  * (c) 2007
  151.  *
  152.  * Revision 1.6  2007/01/25 05:09:53  fplanque
  153.  * bugfix
  154.  *
  155.  * Revision 1.5  2006/12/07 20:03:32  fplanque
  156.  * Woohoo! File editing... means all skin editing.
  157.  *
  158.  * Revision 1.4  2006/11/24 18:27:24  blueyed
  159.  * Fixed link to b2evo CVS browsing interface in file docblocks
  160.  */
  161. ?>

Documentation generated on Sat, 06 Mar 2010 04:08:50 +0100 by phpDocumentor 1.4.2. This site is hosted and maintained by Daniel HAHLER (Contact).