Index: kernel/classes/ezurlwildcard.php
===================================================================
--- kernel/classes/ezurlwildcard.php	(révision 23735)
+++ kernel/classes/ezurlwildcard.php	(copie de travail)
@@ -28,16 +28,12 @@
 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
 //
 
-/*! \file
-*/
+/**
+ * Handles URL alias wildcards in eZ Publish
+ * @class eZURLWildcard
+ * @private
+ **/
 
-/*!
-  \class eZURLWildcard ezurlwildcard.php
-  \brief Handles URL alias wildcards in eZ Publish
-
-  \private
-*/
-
 class eZURLWildcard extends eZPersistentObject
 {
     const REGEXP_ARRAY_CALLBACK = 'eZURLWilcardCachedReqexpArray';
@@ -49,16 +45,25 @@
     const TYPE_FORWARD = 1;
     const TYPE_DIRECT = 2;
 
+    /**
+     * ExpiryHandler key
+     * @var string
+     **/
     const CACHE_SIGNATURE = 'urlalias-wildcard';
 
-    /*!
-     Initializes a new URL alias.
-    */
+    /**
+     * Initializes a new URL alias.
+     * @param $row
+     **/
     function eZURLWildcard( $row )
     {
         $this->eZPersistentObject( $row );
     }
 
+    /**
+     * Persistent object definition
+     * @return array
+     **/
     static function definition()
     {
         return array( "fields" => array( "id" => array( 'name' => 'ID',
@@ -84,9 +89,10 @@
                       "name" => "ezurlwildcard" );
     }
 
-    /*!
-     \return the url alias object as an associative array with all the attribute values.
-    */
+    /**
+     * Returns an associative array that represents the url alias object
+     * @return array
+     **/
     function asArray()
     {
         return array( 'id' => $this->attribute( 'id' ),
@@ -95,19 +101,22 @@
                       'type' => $this->attribute( 'type' ) );
     }
 
-    /*!
-     \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
-     the calls within a db transaction; thus within db->begin and db->commit.
-    */
+    /**
+     * @note Transaction unsafe.
+     *       If you call several transaction unsafe methods you must enclose
+     *       the calls within a db transaction; thus within db->begin and
+     *       db->commit.
+     **/
     function store( $fieldFilters = null )
     {
         eZPersistentObject::store( $fieldFilters );
     }
 
-    /*!
-     \static
-      Removes all wildcards that matches the base URL \a $baseURL.
-    */
+    /**
+     * Removes all wildcards that matches $baseURL.
+     * @param string $baseURL
+     * @return void
+     **/
     static function cleanup( $baseURL )
     {
         $db = eZDB::instance();
@@ -117,19 +126,19 @@
         $db->query( $sql );
     }
 
-    /*!
-     \static
-      Removes all wildcards.
-     */
+    /**
+     * Removes all wildcards.
+     **/
     static function removeAll()
     {
         eZPersistentObject::removeObject( eZURLWildcard::definition() );
     }
 
-    /*!
-     \static
-      Removes wildcards by IDs specified in \a $idList
-     */
+    /**
+     * Removes wildcards by IDs specified in $idList
+     * @param array $idList
+     * @return void
+     **/
     static function removeByIDs( $idList )
     {
         if ( !is_array( $idList ) )
@@ -203,16 +212,17 @@
         return $rows[0]['count'];
     }
 
-    /*!
-     \static
-     \return array with information on the wildcard cache.
-
-     The array containst the following keys
-     - dir - The directory for the cache
-     - file - The base filename for the caches
-     - path - The entire path (including filename) for the cache
-     - keys - Array with key values which is used to uniquely identify the cache
-    */
+    /**
+     * Returns wildcard cache information array
+     *
+     * The array containst the following keys
+     * - dir - The directory for the cache
+     * - file - The base filename for the caches
+     * - path - The entire path (including filename) for the cache
+     * - keys - Array with key values which is used to uniquely identify the cache
+     *
+     * @return array with information on the wildcard cache.
+     **/
     static function cacheInfo()
     {
         $cacheDir = eZSys::cacheDirectory();
@@ -244,10 +254,13 @@
         $wildcardKeys = $info['keys'];
     }
 
-    /*!
-     \static
-     \return true if the wildcard cache is expired.
-    */
+    /**
+     * Tests if the wildcard cache is expired for a given timestamp
+     *
+     * @param int $timestamp Cache timestamp to test for expiry
+     *
+     * @return bool true if the wildcard cache is expired, false otherwise
+     **/
     static function isCacheExpired( $timestamp )
     {
         $expired = false;
@@ -264,11 +277,11 @@
         return $expired;
     }
 
-    /*!
-     \static
-     Expires the wildcard cache. This causes the wildcard cache to be
-     regenerated on the next page load.
-    */
+    /**
+     * Expires the wildcard cache
+     *
+     * This causes the wildcard cache to be regenerated on the next page load.
+     **/
     static function expireCache()
     {
         $handler = eZExpiryHandler::instance();
@@ -276,12 +289,14 @@
         $handler->store();
     }
 
-    /*!
-     \static
-     Transforms the URI if there exists an alias for it.
-     \return \c true is if successful, \c false otherwise
-     \return The string with new url is returned if the translation was found, but the resource has moved.
-    */
+    /**
+     * Transforms $uri if there exists an alias for it
+     *
+     * Modifies the parameter $uri, translating it if possible. True is returned
+     * if the translation actually happened
+     *
+     * @return bool true is if successful, false otherwise
+     **/
     static function translate( &$uri )
     {
         $result = false;
@@ -425,7 +440,7 @@
         {
             eZDebugSetting::writeDebug( 'kernel-urltranslator', "setting up callback for cache mode", 'eZURLWildcard::setupMatchCallbacks' );
 
-            eZURLWildcard::loadCacheIndex();
+            eZURLWildcard::loadCache();
 
             if ( function_exists( eZURLWildcard::REGEXP_ARRAY_CALLBACK ) )
             {
@@ -441,18 +456,18 @@
         return true;
     }
 
-    /*!
-     \static
-    */
+    /**
+     * Creates the wildcard caches if the cache-index is expired
+     *
+     * @return true
+     **/
     static function createCacheIfExpired()
     {
-        $cacheFile = eZURLWildcard::cacheIndexFile();
+        $isExpired = true;
 
-        $isExpired = true;
-        if ( $cacheFile->exists() )
+        if ( $cacheFile = eZURLWildcard::cacheFile() )
         {
-            $timestamp = $cacheFile->mtime();
-            $isExpired = eZURLWildcard::isCacheExpired( $timestamp );
+            $isExpired = eZURLWildcard::isCacheExpired( $cacheFile->mtime() );
         }
 
         if ( $isExpired )
@@ -463,16 +478,19 @@
         return true;
     }
 
-    /*!
-     \static
-     The wildcard caches are splitted between several files:
-        'wildcard_<md5>_index.php' - contains regexps for wildcards,
-        'wildcard_<md5>_0.php',
-        'wildcard_<md5>_1.php',
-        ...
-        'wildcard_<md5>_N.php'     - contains cached wildcards.
-                                     Each file has info about eZURLWildcard::WILDCARDS_PER_CACHE_FILE wildcards.
-     */
+    /**
+     * Creates the wildcard caches
+     *
+     * The wildcard caches are splitted between several files:
+     *    'wildcard_<md5>_index.php' - contains regexps for wildcards,
+     *    'wildcard_<md5>_0.php',
+     *    'wildcard_<md5>_1.php',
+     *    ...
+     *    'wildcard_<md5>_N.php'     - contains cached wildcards.
+     * Each file has info about eZURLWildcard::WILDCARDS_PER_CACHE_FILE wildcards.
+     *
+     * @return void
+     **/
     static function createCache()
     {
         eZURLWildcard::cacheInfoDirectories( $wildcardCacheDir, $wildcardCacheFile, $wildcardCachePath, $wildcardKeys );
@@ -555,11 +573,12 @@
         $phpCacheIndex->store( true );
     }
 
-    /*!
-     \static
-     \private
-     Creates a 'regexp' portion of php-code for cache-index.
-     */
+    /**
+     * Creates a 'regexp' portion of php-code for cache-index.
+     *
+     * @param string $wildcard
+     * @return string PHP Code
+     **/
     static private function matchRegexpCode( $wildcard )
     {
         $phpCode = "";
@@ -578,11 +597,12 @@
         return $phpCode;
     }
 
-    /*!
-     \static
-     \private
-     Creates a 'replace' and wildcard-info portions of php-code for cache.
-     */
+    /**
+     * Creates a 'replace' and wildcard-info portions of php-code for cache.
+     * @param $wildcard
+     * @param $indent
+     * @return string PHP Code
+     **/
     static private function matchReplaceCode( $wildcard, $indent = '' )
     {
         $phpCode = "";
@@ -641,46 +661,80 @@
         return $phpCode;
     }
 
-    /*!
-     \static
-     \return instance of 'eZClusterFileHandler' for cache-index file
+    /**
+     * Returns the clusterfilehandler instance for a cache file if it exists.
+     *
+     * If $cacheNumber is not specified, the cache-index file will be returned.
+     * If a specific cache number is provided, this cache instance will be
+     * returned.
+     *
+     * @param int $cacheNumber cache number. If not provided, index is returned.
+     * @return bool|eZClusterFileHandlerInterface
+     *         Either the cache file clusterfilehandler instance, or false if
+     *         the file doesn't exist
     */
-    static function cacheIndexFile()
+    static function cacheFile( $cacheNumber = 'index' )
     {
         $info = eZURLWildcard::cacheInfo();
 
-        $cacheFile = eZClusterFileHandler::instance( $info['path'] . "_index.php" );
+        $cacheFile = eZClusterFileHandler::instance( $info['path'] . "_$cacheNumber.php" );
 
-        return $cacheFile;
+        if ( !$cacheFile->exists() )
+        {
+            return false;
+        }
+        else
+        {
+            return $cacheFile;
+        }
     }
 
-    /*!
-     \static
-     Loads cache-index.
-     */
-    static function loadCacheIndex()
+    /**
+     * Loads cache-index.
+     *
+     * @return bool true if load was successful, false if the file doesn't exist
+     **/
+    static function loadCache( $cacheNumber = 'index' )
     {
-        $info = eZURLWildcard::cacheInfo();
+        static $expiryTimestamp = null;
 
-        $cacheFile = eZClusterFileHandler::instance( $info['path'] . "_index.php" );
-
-        if ( !$cacheFile->exists() )
+		if ( !$cacheFile = self::cacheFile( $cacheNumber ) )
+        {
             return false;
+        }
 
-        $fetchedFilePath = $cacheFile->fetchUnique();
-        include_once( $fetchedFilePath );
-        $cacheFile->fileDeleteLocal( $fetchedFilePath );
+		// load expiry timestamp if unknown
+    	if ( $expiryTimestamp === null )
+		{
+			$handler = eZExpiryHandler::instance();
+			if ( $handler->hasTimestamp( eZURLWildcard::CACHE_SIGNATURE ) )
+			{
+				$expiryTimestamp = $handler->timestamp( eZURLWildcard::CACHE_SIGNATURE );
+			}
+    		// no expiry timestamp => false means not expired, better than checking again
+			else
+			{
+				$expiryTimestamp = false;
+			}
+		}
 
+        // processFile will apply the callback parameter (#1) once the file has been fetched locally
+		$cacheFile->processFile( array( __CLASS__, 'parseCacheFile' ), $expiryTimestamp );
+
         return true;
     }
 
-    /*!
-     The callback loads appropriate cache file for wildcard \a $wildcardNum,
-     extracts wildcard info and 'replace' url from cache.
-     \note The wildcard number(not a wildcard id) is used here. Reason: to find correct cache-file.
-           If it's needed to fetch wildcard from db, use eZURLWildcard::fetchList with offset = $wildcardNum and
-           $limit = 1.
-     */
+    /**
+     * Translates an URI based on cached data
+     *
+     * The callback loads appropriate cache file for wildcard $wildcardNum,
+     * extracts wildcard info and 'replace' url based on cache.
+     * @note The wildcard number(not a wildcard id) is used here. Reason: to
+     *       find correct cache-file. If it's needed to fetch wildcard from db,
+     *       use eZURLWildcard::fetchList with offset = $wildcardNum and
+     *       $limit = 1.
+     * @return bool
+     **/
     static function translateWithCache( $wildcardNum, &$uri, &$wildcardInfo, $matches )
     {
         eZDebugSetting::writeDebug( 'kernel-urltranslator', "eZURLWildcardTranslateWithCache:: wildcardNum = $wildcardNum, uri = $uri", __METHOD__ );
@@ -689,21 +743,8 @@
 
         eZDebugSetting::writeDebug( 'kernel-urltranslator', "eZURLWildcardTranslateWithCache:: cacheFileNum = $cacheFileNum", __METHOD__ );
 
-        $info = eZURLWildcard::cacheInfo();
-        $cacheFileName = $info['path'] . "_$cacheFileNum" . ".php";
+        self::loadCache( $cacheFileNum );
 
-        $cacheFile = eZClusterFileHandler::instance( $cacheFileName );
-
-        if ( !$cacheFile->exists() )
-        {
-            eZDebugSetting::writeDebug( 'kernel-urltranslator', "eZURLWildcardTranslateWithCache:: no cache file '$cacheFileName'", __METHOD__ );
-            return false;
-        }
-
-        $fetchedFilePath = $cacheFile->fetchUnique();
-        include_once( $fetchedFilePath );
-        $cacheFile->fileDeleteLocal( $fetchedFilePath );
-
         if ( !function_exists( eZURLWildcard::CACHED_TRANSLATE ) )
         {
             eZDebugSetting::writeDebug( 'kernel-urltranslator', "eZURLWildcardTranslateWithCache:: no function in cache file", __METHOD__ );
@@ -717,6 +758,19 @@
 
         return true;
     }
+
+	/**
+	* Callback used by the clsuterhandler to parse a wildcard cache file
+	* @param string $file
+	* @param int $mtime
+	* @param array $extraData
+	* @return void
+	* @sincer 4.2
+	**/
+	static function parseCacheFile( $file, $mtime, $extraData = null )
+	{
+		include $file;
+	}
 }
 
 ?>
\ No newline at end of file
