Author: kn
Date: Tue Oct  2 11:50:54 2007
New Revision: 6327

Log:
- Support more live properties for reading in file backend

Modified:
    trunk/Webdav/src/backends/file.php
    trunk/Webdav/src/backends/memory.php
    trunk/Webdav/tests/backend_file_test.php
    trunk/Webdav/tests/data/responses/file/testPropFindAllPropsOnCollection.ser
    trunk/Webdav/tests/data/responses/file/testPropFindAllPropsOnResource.ser
    
trunk/Webdav/tests/data/responses/file/testPropFindNamesOnCollectionDepthInfinite.ser
    
trunk/Webdav/tests/data/responses/file/testPropFindNamesOnCollectionDepthOne.ser
    
trunk/Webdav/tests/data/responses/file/testPropFindNamesOnCollectionDepthZero.ser
    trunk/Webdav/tests/data/responses/file/testPropFindNamesOnResource.ser
    trunk/Webdav/tests/data/responses/file/testPropFindOnCollection.ser
    trunk/Webdav/tests/data/responses/file/testPropFindOnResource.ser
    
trunk/Webdav/tests/data/responses/file/testPropPatchFailOnRemoveProperty_2.ser

Modified: trunk/Webdav/src/backends/file.php
==============================================================================
--- trunk/Webdav/src/backends/file.php [iso-8859-1] (original)
+++ trunk/Webdav/src/backends/file.php [iso-8859-1] Tue Oct  2 11:50:54 2007
@@ -178,6 +178,45 @@
     }
 
     /**
+     * Get mime type for resource
+     *
+     * Return the mime type for a resource. If a mime type extension is
+     * available it will be used to read the real mime type, otherwise the
+     * original mime type passed by the client when uploading the file will be
+     * returned. If no mimetype has ever been associated with the file, the
+     * method will just return 'application/octet-stream'.
+     * 
+     * @param string $resource 
+     * @return string
+     */
+    protected function getMimeType( $resource )
+    {
+        // Check if extension pecl/fileinfo is usable.
+        if ( function_exists( 'finfo_file' ) )
+        {
+            $fInfo = new fInfo( FILEINFO_MIME );
+            $mimeType = $fInfo->file( $this->root . $resource );
+            $fInfo->close();
+
+            return $mimeType;
+        }
+
+        // Check if extension ext/mime-magic is usable.
+        if ( function_exists( 'mime_content_type' ) )
+        {
+            return mime_content_type( $this->root . $resource );
+        }
+
+        // Check if some browser submitted mime type is available.
+        if ( false )
+        {
+            // @TODO: Implement
+        }
+
+        return 'application/octet-stream';
+    }
+
+    /**
      * Create a new collection.
      *
      * Creates a new collection at the given path.
@@ -367,12 +406,13 @@
     {
         $storage = $this->getPropertyStoragePath( $resource, new 
ezcWebdavDeadProperty( $namespace, $propertyName ) );
 
-        // handle dead propreties
+        // Handle dead propreties
         if ( $namespace !== 'DAV:' )
         {
             return unserialize( file_get_contents( $storage ) );
         }
 
+        // Handle live properties
         switch ( $propertyName )
         {
             case 'getcontentlength':
@@ -387,8 +427,38 @@
                 $property->date = new ezcWebdavDateTime( '@' . filemtime( 
$this->root . $resource ) );
                 return $property;
 
+            case 'creationdate':
+                $property = new ezcWebdavCreationDateProperty();
+                $property->date = new ezcWebdavDateTime( '@' . filectime( 
$this->root . $resource ) );
+                return $property;
+
+            case 'displayname':
+                $property = new ezcWebdavDisplayNameProperty();
+                $property->displayName = basename( $resource );
+                return $property;
+
+            case 'getcontenttype':
+                $property = new ezcWebdavGetContentTypeProperty(
+                    $this->getMimeType( $resource )
+                );
+                return $property;
+
+            case 'getetag':
+                $property = new ezcWebdavGetEtagProperty();
+                // @TODO: Use proper etag hashing stuff
+                $property->etag = md5( $resource . filemtime( $this->root . 
$resource ) );
+                return $property;
+
+            case 'resourcetype':
+                $property = new ezcWebdavResourceTypeProperty();
+                $property->type = $this->isCollection( $resource ) ?
+                    ezcWebdavResourceTypeProperty::TYPE_COLLECTION : 
+                    ezcWebdavResourceTypeProperty::TYPE_RESSOURCE;
+                return $property;
+
             default:
-                throw new Exception( 'Start handling this one immediately!' );
+                // Handle unknown live properties like dead properties
+                return unserialize( file_get_contents( $storage ) );
         }
     }
 
@@ -419,7 +489,7 @@
         }
 
         // Also attach generated live properties
-        $liveProperties = array( 'getcontentlength', 'getlastmodified' );
+        $liveProperties = array( 'getcontentlength', 'getlastmodified', 
'creationdate', 'displayname', 'getcontenttype', 'getetag', 'resourcetype' );
         foreach( $liveProperties as $name )
         {
             $storage->attach( $this->getProperty( $resource, $name ) );

Modified: trunk/Webdav/src/backends/memory.php
==============================================================================
--- trunk/Webdav/src/backends/memory.php [iso-8859-1] (original)
+++ trunk/Webdav/src/backends/memory.php [iso-8859-1] Tue Oct  2 11:50:54 2007
@@ -195,7 +195,10 @@
 
             $propertyStorage->attach(
                 new ezcWebdavResourceTypeProperty(
-                    ( $isCollection === true ? 
ezcWebdavResourceTypeProperty::TYPE_COLLECTION : 
ezcWebdavResourceTypeProperty::TYPE_RESSOURCE )
+                    ( $isCollection === true ? 
+                        ezcWebdavResourceTypeProperty::TYPE_COLLECTION : 
+                        ezcWebdavResourceTypeProperty::TYPE_RESSOURCE
+                    )
                 )
             );
         }

Modified: trunk/Webdav/tests/backend_file_test.php
==============================================================================
--- trunk/Webdav/tests/backend_file_test.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/backend_file_test.php [iso-8859-1] Tue Oct  2 11:50:54 
2007
@@ -42,6 +42,7 @@
 
             if ( is_dir( $path = $source . '/' . $file ) )
             {
+                touch( $path, $time, $time );
                 $this->recursiveTouch( $path, $time );
             }
             else
@@ -81,7 +82,8 @@
         );
         $this->recursiveTouch(
             $this->tempDir . 'backend/',
-            12345678
+            // Change this once 64bit systems are common, or we reached year 
2038
+            2147483647
         );
     }
 

Modified: 
trunk/Webdav/tests/data/responses/file/testPropFindAllPropsOnCollection.ser
==============================================================================
Binary files - no diff available.

Modified: 
trunk/Webdav/tests/data/responses/file/testPropFindAllPropsOnResource.ser
==============================================================================
Binary files - no diff available.

Modified: 
trunk/Webdav/tests/data/responses/file/testPropFindNamesOnCollectionDepthInfinite.ser
==============================================================================
Binary files - no diff available.

Modified: 
trunk/Webdav/tests/data/responses/file/testPropFindNamesOnCollectionDepthOne.ser
==============================================================================
Binary files - no diff available.

Modified: 
trunk/Webdav/tests/data/responses/file/testPropFindNamesOnCollectionDepthZero.ser
==============================================================================
Binary files - no diff available.

Modified: trunk/Webdav/tests/data/responses/file/testPropFindNamesOnResource.ser
==============================================================================
Binary files - no diff available.

Modified: trunk/Webdav/tests/data/responses/file/testPropFindOnCollection.ser
==============================================================================
Binary files - no diff available.

Modified: trunk/Webdav/tests/data/responses/file/testPropFindOnResource.ser
==============================================================================
Binary files - no diff available.

Modified: 
trunk/Webdav/tests/data/responses/file/testPropPatchFailOnRemoveProperty_2.ser
==============================================================================
Binary files - no diff available.


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

Reply via email to