Author: Tobias Schlitt
Date: 2006-01-13 09:51:09 +0100 (Fri, 13 Jan 2006)
New Revision: 1807

Log:
- Migrate to use new Base exceptions (file and settings).

Modified:
   packages/Cache/trunk/src/manager.php
   packages/Cache/trunk/src/storage.php
   packages/Cache/trunk/src/storage/file.php
   packages/Cache/trunk/tests/manager_test.php
   packages/Cache/trunk/tests/storage_file_test.php
   packages/Cache/trunk/tests/storage_test.php

Modified: packages/Cache/trunk/src/manager.php
===================================================================
--- packages/Cache/trunk/src/manager.php        2006-01-13 08:47:33 UTC (rev 
1806)
+++ packages/Cache/trunk/src/manager.php        2006-01-13 08:51:09 UTC (rev 
1807)
@@ -112,23 +112,35 @@
      * @param string $storageClass   Subclass of [EMAIL PROTECTED] 
ezcCacheStorage}.
      * @param array(string) $options Options for the cache.
      *
-     * @throws ezcCacheInvalidStorageClassException
-     *         If the given location is invalid (does not exist, is not a 
-     *         directory, is not writeable).
+     * @throws ezcBaseFileNotFoundException
+     *         If the given location does not exist or is not a 
+     *         directory.
+     * @throws ezcBaseFilePermissionException
+     *         If the given location is not read/writeable.
      * @throws ezcCacheUsedLocationException
      *         If the given location is already in use by another cache.
      * @throws ezcCacheInvalidStorageClassException
      *         If the given storage class does not exist or is no subclas of 
      *         ezcCacheStorage.
      * @return void
+     *
+     * @todo Remove sanitity checks from here, since already performed during 
construction of CacheStorages!
      */
     public static function createCache( $id, $location, $storageClass, 
$options = array() ) 
     {
         // Sanity check existance.
-        if ( !file_exists( $location ) || !is_dir( $location ) || 
!is_writeable( $location ) ) 
+        if ( !file_exists( $location ) || !is_dir( $location ) ) 
         {
-            throw new ezcCacheInvalidLocationException( $location );
+            throw new ezcBaseFileNotFoundException( $location, 'cache 
location', 'Does not exists or is no directory.' );
         }
+        if ( !is_readable( $location ) )
+        {
+            throw new ezcBaseFilePermissionException( $location, 
ezcBaseFileException::READ, 'Cache location is not readable.' );
+        }
+        if ( !is_writeable( $location ) )
+        {
+            throw new ezcBaseFilePermissionException( $location, 
ezcBaseFileException::WRITE, 'Cache location is not writeable.' );
+        }
         $location = realpath( $location );
         // Sanity check double taken locations.
         foreach ( self::$configurations as $confId => $config )
@@ -159,16 +171,14 @@
      * @param string $id       The ID of the cache to return.
      * @return ezcCacheStorage The cache with the given ID.
      *
-     * @throws ezcCacheInvalidIdException
-     *         If the given cache ID does not exist.
-     * @throws ezcCacheInvalidLocationException
+     * @throws ezcBaseFileNotFoundException
      *         If the storage location does not exist.
-     * @throws ezcCacheInvalidLocationException
-     *         If the storage location is not a directory
-     * @throws ezcCacheInvalidLocationException
-     *         If the storage location is not writeable
-     * @throws ezcBaseConfigException
-     *         If an unknown option is set
+     * @throws ezcBaseFileNotFoundException
+     *         If the storage location is not a directory.
+     * @throws ezcBaseFilePermissionException
+     *         If the storage location is not writeable.
+     * @throws ezcBaseSettingNotFoundException
+     *         If an unknown option is set.
      */
     public static function getCache( $id ) 
     {

Modified: packages/Cache/trunk/src/storage/file.php
===================================================================
--- packages/Cache/trunk/src/storage/file.php   2006-01-13 08:47:33 UTC (rev 
1806)
+++ packages/Cache/trunk/src/storage/file.php   2006-01-13 08:51:09 UTC (rev 
1807)
@@ -39,9 +39,6 @@
      * 
      * @param mixed $data Simple type or array
      * @return string The serialized data
-     *
-     * @throws ezcCacheStorageIoException
-     *         If the submitted data type can not be stored.
      */
     abstract protected function prepareData( $data );
 
@@ -65,9 +62,10 @@
      * 
      * @return string            The ID string of the newly cached data.
      *
-     * @throws ezcCacheStorageIoException
-     *         If the location is not writeable or if the data could not be 
-     *         written to the location of another reason.
+     * @throws ezcBaseFilePermissionException
+     *         If an already existsing cache file could not be unlinked.
+     * @throws ezcBaseFilePermissionException
+     *         If the directory to store the cache file could not be created.
      */
     public function store( $id, $data, $attributes = array() ) 
     {
@@ -76,19 +74,19 @@
         {
             if ( unlink( $filename ) === false ) 
             {
-                throw new ezcCacheStorageIoException( $filename );
+                throw new ezcBaseFilePermissionException( $filename, 
ezcBaseFileException::WRITE, 'Could not delete existsing cache file.' );
             }
         }
         $dataStr = $this->prepareData( $data );
         $dirname = dirname( $filename );
-        if ( !is_dir( $dirname ) )
+        if ( !is_dir( $dirname ) && !mkdir( $dirname, 0777, true ) )
         {
-            mkdir( $dirname, 0777, true );
+            throw new ezcBaseFilePermissionException( $dirname, 
ezcBaseFileException::WRITE, 'Could not create directory to stor cache file.' );
         }
         
         if ( file_put_contents( $filename, $dataStr ) !== strlen( $dataStr ) ) 
         {
-            throw new ezcCacheStorageIoException( $filename );
+            throw new ezcBaseFileIoException( $filename, 
ezcBaseFileException::WRITE, 'Could not write data to cache file.' );
         }
         return $id;
     }
@@ -158,8 +156,8 @@
      * @param array $attributes Attributes describing the data to purge.
      * @return void
      *
-     * @throws ezcCacheStorageIoException
-     *         If the location is not writeable.
+     * @throws ezcBaseFilePermissionException
+     *         If a cache file could not be unlinked.
      */
     public function delete( $id = null, $attributes = array() )
     {
@@ -177,7 +175,7 @@
         {
             if ( unlink( $filename ) === false ) 
             {
-                throw new ezcCacheStorageIoException( $filename );
+                throw new ezcBaseFilePermissionException( $filename, 
ezcBaseFileException::WRITE, 'Could not unlink cache file.' );
             }
         }
     }
@@ -235,11 +233,11 @@
      * Checks if the location exists and tries to create it, if not. Also 
checks
      * if the location is read-/writeable and throws an exception, if not.
      * 
-     * @throws ezcCacheInvalidLocationException
+     * @throws ezcBaseFileNotFoundException
      *         If the storage location does not exist.
-     * @throws ezcCacheInvalidLocationException
+     * @throws ezcBaseFileNotFoundException
      *         If the storage location is not a directory.
-     * @throws ezcCacheInvalidLocationException
+     * @throws ezcBaseFilePermissionException
      *         If the storage location is not writeable.
      * @return void
      */
@@ -247,17 +245,17 @@
     {
         if ( file_exists( $this->location ) === false ) 
         {
-            throw new ezcCacheInvalidLocationException( $this->location );
+            throw new ezcBaseFileNotFoundException( $this->location, 'cache 
location' );
         }
             
         if ( is_dir( $this->location ) === false ) 
         {
-            throw new ezcCacheInvalidLocationException( $this->location );
+            throw new ezcBaseFileNotFoundException( $this->location, 'cache 
location', 'Cache location not a directory.' );
         }
 
         if ( is_writeable( $this->location ) === false ) 
         {
-            throw new ezcCacheInvalidLocationException( $this->location );
+            throw new ezcBaseFilePermissionException( $this->location, 
ezcBaseFileException::WRITE, 'Cache location is not a directory.' );
         }
     }
 

Modified: packages/Cache/trunk/src/storage.php
===================================================================
--- packages/Cache/trunk/src/storage.php        2006-01-13 08:47:33 UTC (rev 
1806)
+++ packages/Cache/trunk/src/storage.php        2006-01-13 08:51:09 UTC (rev 
1807)
@@ -60,14 +60,14 @@
      * @param string $location       Path to the cache location
      * @param array(string) $options Options
      *
-     * @throws ezcCacheInvalidLocationException
+     * @throws ezcBaseFileNotFoundException
      *         If the storage location does not exist.
-     * @throws ezcCacheInvalidLocationException
+     * @throws ezcBaseFileNotFoundException
      *         If the storage location is not a directory.
-     * @throws ezcCacheInvalidLocationException
+     * @throws ezcBaseFilePermissionException
      *         If the storage location is not writeable.
-     * @throws ezcBaseConfigException
-     *         If an unknown option is set
+     * @throws ezcBaseSettingNotFoundException
+     *         If an unknown option is set.
      */
     public function __construct( $location, $options = null ) 
     {
@@ -96,12 +96,10 @@
      * 
      * @return string           The ID of the newly cached data.
      *
-     * @throws ezcCacheInvalidLocationException
-     *         If the location is not writeable
-     * @throws ezcCacheStorageIoException
-     *         If the data could not be written to the location
-     * @throws ezcCacheInvalidData
-     *         If the submitted type data submitted is not storeable.
+     * @throws ezcBaseFilePermissionException
+     *         If an already existsing cache file could not be unlinked.
+     * @throws ezcBaseFilePermissionException
+     *         If the directory to store the cache file could not be created.
      */
     abstract public function store( $id, $data, $attributes = array() );
 
@@ -143,8 +141,8 @@
      * @param string $id        The ID of the data to purge.
      * @param array $attributes Attributes describing the data to purge.
      *
-     * @throws ezcCacheInvalidLocationException
-     *         If the location is not writeable.
+     * @throws ezcBaseFilePermissionException
+     *         If a cache file could not be unlinked.
      */
     abstract public function delete( $id = null, $attributes = array() );
 
@@ -200,8 +198,9 @@
      * 
      * @param array $options The options
      *
-     * @throws ezcBaseConfigException
-     *         If the desired option does not exist
+     * @throws ezcBaseSettingNotFoundException
+     *         If the desired option does not exist.
+     * @todo Sanity checks for options.
      */
     public function setOptions( $options = null ) 
     {
@@ -217,7 +216,7 @@
             } 
             else 
             {
-                throw new ezcBaseConfigException( $name, 
ezcBaseConfigException::UNKNOWN_CONFIG_SETTING );
+                throw new ezcBaseSettingNotFoundException( $name );
             }
         }
     }

Modified: packages/Cache/trunk/tests/manager_test.php
===================================================================
--- packages/Cache/trunk/tests/manager_test.php 2006-01-13 08:47:33 UTC (rev 
1806)
+++ packages/Cache/trunk/tests/manager_test.php 2006-01-13 08:51:09 UTC (rev 
1807)
@@ -93,7 +93,7 @@
         {
             $cache = ezcCacheManager::createCache( $id, '/fckgw', 
$this->data[$id] );
         }
-        catch ( ezcCacheInvalidLocationException $e )
+        catch ( ezcBaseFileNotFoundException $e )
         {
             $caughtException = true;
         }

Modified: packages/Cache/trunk/tests/storage_file_test.php
===================================================================
--- packages/Cache/trunk/tests/storage_file_test.php    2006-01-13 08:47:33 UTC 
(rev 1806)
+++ packages/Cache/trunk/tests/storage_file_test.php    2006-01-13 08:51:09 UTC 
(rev 1807)
@@ -45,9 +45,9 @@
             $obj = new ezcCacheStorageFileArray( '/tmp', array( 'eXtEnSiOn' => 
'.c' ) );
             $this->fail( 'Expected exception was not thrown' );
         }
-        catch ( ezcBaseConfigException $e )
+        catch ( ezcBaseSettingNotFoundException $e )
         {
-            $this->assertEquals( 
ezcBaseConfigException::UNKNOWN_CONFIG_SETTING, $e->getCode() );
+            $this->assertTrue( true );
         }
     }
 

Modified: packages/Cache/trunk/tests/storage_test.php
===================================================================
--- packages/Cache/trunk/tests/storage_test.php 2006-01-13 08:47:33 UTC (rev 
1806)
+++ packages/Cache/trunk/tests/storage_test.php 2006-01-13 08:51:09 UTC (rev 
1807)
@@ -140,7 +140,7 @@
             $cache = new ezcCacheStorageFileArray( $nonExistingPath );
             $this->fail( 'Exception "Location not available" not thrown.' );
         }
-        catch ( ezcCacheInvalidLocationException $e )
+        catch ( ezcBaseFileNotFoundException $e )
         {
             return;
         }
@@ -163,18 +163,23 @@
         {
             throw new Exception( 'Could not change permissions for location <' 
. $this->getTempDir() . '> to 0000.' );
         }
+        $exceptionThrown = false;
         try 
         {
             $cache = new $this->storageClass( $this->getTempDir() );
-            $this->fail( 'Exception "Location not writeable" not thrown.' );
-        } 
-        catch ( ezcCacheInvalidLocationException $e ) 
+        }
+        catch ( ezcBaseFilePermissionException $e ) 
         {
+            $exceptionThrown = true;
         }
         if ( chmod( $this->getTempDir(), $oldMode ) === false ) 
         {
             throw new Exception( 'Could not change permissions for location <' 
. $this->getTempDir() . '> to '.$oldMode.'.' );
         }
+        if ( $exceptionThrown === false)
+        {
+            $this->fail( 'Exception "Location not writeable" not thrown.' );
+        } 
     }
 
     /**

-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to