Author: kn
Date: Thu Sep 20 11:34:03 2007
New Revision: 6211

Log:
- Set property as errnous, instead of throwing an exception, because we need to
  handle this later in the backend

Modified:
    trunk/Webdav/src/interfaces/property.php
    trunk/Webdav/src/properties/creationdate.php
    trunk/Webdav/src/properties/dead.php
    trunk/Webdav/src/properties/displayname.php
    trunk/Webdav/src/properties/getcontentlanguage.php
    trunk/Webdav/src/properties/getcontentlength.php
    trunk/Webdav/src/properties/getcontenttype.php
    trunk/Webdav/src/properties/getetag.php
    trunk/Webdav/src/properties/getlastmodified.php
    trunk/Webdav/src/properties/lockdiscovery.php
    trunk/Webdav/src/properties/lockdiscovery_activelock.php
    trunk/Webdav/src/properties/resourcetype.php
    trunk/Webdav/src/properties/source.php
    trunk/Webdav/src/properties/source_link.php
    trunk/Webdav/src/properties/supportedlock.php
    trunk/Webdav/src/properties/supportedlock_lockentry.php
    trunk/Webdav/tests/backend_memory_test.php
    trunk/Webdav/tests/property_test.php
    trunk/Webdav/tests/webdav_property_test.php

Modified: trunk/Webdav/src/interfaces/property.php
==============================================================================
--- trunk/Webdav/src/interfaces/property.php [iso-8859-1] (original)
+++ trunk/Webdav/src/interfaces/property.php [iso-8859-1] Thu Sep 20 11:34:03 
2007
@@ -10,10 +10,14 @@
 /**
  * Base class for WebDAV property representation classes.
  * 
- * @property $namespace
+ * @property string $namespace
  *           Namespace of property
- * @property $name
+ * @property string $name
  *           Name of property
+ * @property-read bool $hasError
+ *           If the property has a property validation error.
+ * @property-read array $errors
+ *           Validation errors for property
  *
  * @package Webdav
  * @version //autogen//
@@ -40,6 +44,9 @@
      */
     public function __construct( $namespace, $name )
     {
+        $this->properties['hasError'] = false;
+        $this->properties['errors']   = array();
+
         $this->namespace = $namespace;
         $this->name      = $name;
     }
@@ -70,6 +77,23 @@
     }
     
     /**
+     * Add property validation error.
+     *
+     * Method called, when a property validation error occured. The error is
+     * stored and the property is set as errnous.
+     * 
+     * @param string $property 
+     * @param mixed $value 
+     * @param string $expected 
+     * @return void
+     */
+    protected function hasError( $property, $value, $expected )
+    {
+        $this->properties['hasError'] = true;
+        $this->properties['errors'][] = "The property '$property' only accepts 
values of type '$expected' - '" . gettype( $value ) . "' given.";
+    }
+
+    /**
      * Sets a property.
      * This method is called when an property is to be set.
      * 
@@ -95,6 +119,14 @@
                     throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'string' );
                 }
                 $this->properties[$propertyName] = $propertyValue;
+                break;
+
+            case 'errors':
+            case 'hasError':
+                throw new ezcBasePropertyPermissionException(
+                    $propertyName,
+                    ezcBasePropertyPermissionException::READ
+                );
                 break;
 
             default:
@@ -137,7 +169,7 @@
     {
         foreach ( $this->properties as $name => $value )
         {
-            if ( !in_array( $name, array( 'name', 'namespace' ), true ) )
+            if ( !in_array( $name, array( 'name', 'namespace', 'errors', 
'hasError' ), true ) )
             {
                 $this->properties[$name] = null;
             }

Modified: trunk/Webdav/src/properties/creationdate.php
==============================================================================
--- trunk/Webdav/src/properties/creationdate.php [iso-8859-1] (original)
+++ trunk/Webdav/src/properties/creationdate.php [iso-8859-1] Thu Sep 20 
11:34:03 2007
@@ -53,7 +53,7 @@
             case 'date':
                 if ( ( $propertyValue instanceof DateTime ) === false && 
$propertyValue !== null )
                 {
-                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'DateTime' );
+                    return $this->hasError( $propertyName, $propertyValue, 
'DateTime' );
                 }
 
                 $this->properties[$propertyName] = $propertyValue;

Modified: trunk/Webdav/src/properties/dead.php
==============================================================================
--- trunk/Webdav/src/properties/dead.php [iso-8859-1] (original)
+++ trunk/Webdav/src/properties/dead.php [iso-8859-1] Thu Sep 20 11:34:03 2007
@@ -57,7 +57,7 @@
             case 'content':
                 if ( ( $propertyValue !== null ) && !is_string( $propertyValue 
) )
                 {
-                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'string' );
+                    return $this->hasError( $propertyName, $propertyValue, 
'string' );
                 }
 
                 $this->properties[$propertyName] = $propertyValue;

Modified: trunk/Webdav/src/properties/displayname.php
==============================================================================
--- trunk/Webdav/src/properties/displayname.php [iso-8859-1] (original)
+++ trunk/Webdav/src/properties/displayname.php [iso-8859-1] Thu Sep 20 
11:34:03 2007
@@ -53,7 +53,7 @@
             case 'displayName':
                 if ( is_string( $propertyValue ) === false && $propertyValue 
!== null )
                 {
-                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'string' );
+                    return $this->hasError( $propertyName, $propertyValue, 
'string' );
                 }
 
                 $this->properties[$propertyName] = $propertyValue;

Modified: trunk/Webdav/src/properties/getcontentlanguage.php
==============================================================================
--- trunk/Webdav/src/properties/getcontentlanguage.php [iso-8859-1] (original)
+++ trunk/Webdav/src/properties/getcontentlanguage.php [iso-8859-1] Thu Sep 20 
11:34:03 2007
@@ -53,7 +53,7 @@
             case 'languages':
                 if ( is_array( $propertyValue ) === false )
                 {
-                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'string' );
+                    return $this->hasError( $propertyName, $propertyValue, 
'string' );
                 }
 
                 $this->properties[$propertyName] = $propertyValue;

Modified: trunk/Webdav/src/properties/getcontentlength.php
==============================================================================
--- trunk/Webdav/src/properties/getcontentlength.php [iso-8859-1] (original)
+++ trunk/Webdav/src/properties/getcontentlength.php [iso-8859-1] Thu Sep 20 
11:34:03 2007
@@ -60,7 +60,7 @@
             case 'length':
                 if ( ( is_string( $propertyValue ) === false || is_numeric( 
$propertyValue ) === false ) && $propertyValue !== null )
                 {
-                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'string of digits' );
+                    return $this->hasError( $propertyName, $propertyValue, 
'string of digits' );
                 }
 
                 $this->properties[$propertyName] = $propertyValue;

Modified: trunk/Webdav/src/properties/getcontenttype.php
==============================================================================
--- trunk/Webdav/src/properties/getcontenttype.php [iso-8859-1] (original)
+++ trunk/Webdav/src/properties/getcontenttype.php [iso-8859-1] Thu Sep 20 
11:34:03 2007
@@ -56,7 +56,7 @@
             case 'mime':
                 if ( is_string( $propertyValue ) === false && $propertyValue 
!== null )
                 {
-                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'string' );
+                    return $this->hasError( $propertyName, $propertyValue, 
'string' );
                 }
 
                 $this->properties[$propertyName] = $propertyValue;
@@ -64,7 +64,7 @@
             case 'charset':
                 if ( is_string( $propertyValue ) === false && $propertyValue 
!== null )
                 {
-                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'string' );
+                    return $this->hasError( $propertyName, $propertyValue, 
'string' );
                 }
 
                 $this->properties[$propertyName] = $propertyValue;

Modified: trunk/Webdav/src/properties/getetag.php
==============================================================================
--- trunk/Webdav/src/properties/getetag.php [iso-8859-1] (original)
+++ trunk/Webdav/src/properties/getetag.php [iso-8859-1] Thu Sep 20 11:34:03 
2007
@@ -53,7 +53,7 @@
             case 'etag':
                 if ( is_string( $propertyValue ) === false && $propertyValue 
!== null )
                 {
-                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'string' );
+                    return $this->hasError( $propertyName, $propertyValue, 
'string' );
                 }
 
                 $this->properties[$propertyName] = $propertyValue;

Modified: trunk/Webdav/src/properties/getlastmodified.php
==============================================================================
--- trunk/Webdav/src/properties/getlastmodified.php [iso-8859-1] (original)
+++ trunk/Webdav/src/properties/getlastmodified.php [iso-8859-1] Thu Sep 20 
11:34:03 2007
@@ -53,7 +53,7 @@
             case 'date':
                 if ( ( $propertyValue instanceof DateTime ) === false && 
$propertyValue !== null )
                 {
-                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'DateTime' );
+                    return $this->hasError( $propertyName, $propertyValue, 
'DateTime' );
                 }
 
                 $this->properties[$propertyName] = $propertyValue;

Modified: trunk/Webdav/src/properties/lockdiscovery.php
==============================================================================
--- trunk/Webdav/src/properties/lockdiscovery.php [iso-8859-1] (original)
+++ trunk/Webdav/src/properties/lockdiscovery.php [iso-8859-1] Thu Sep 20 
11:34:03 2007
@@ -53,7 +53,7 @@
             case 'activeLock':
                 if ( is_array( $propertyValue ) === false && $propertyValue 
!== null )
                 {
-                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'array(ezcWebdavLockDiscoveryPropertyActiveLock)' );
+                    return $this->hasError( $propertyName, $propertyValue, 
'array(ezcWebdavLockDiscoveryPropertyActiveLock)' );
                 }
 
                 $this->properties[$propertyName] = $propertyValue;

Modified: trunk/Webdav/src/properties/lockdiscovery_activelock.php
==============================================================================
--- trunk/Webdav/src/properties/lockdiscovery_activelock.php [iso-8859-1] 
(original)
+++ trunk/Webdav/src/properties/lockdiscovery_activelock.php [iso-8859-1] Thu 
Sep 20 11:34:03 2007
@@ -76,35 +76,35 @@
             case 'depth':
                 if ( $propertyValue !== ezcWebdavRequest::DEPTH_INFINITY && 
$propertyValue !== ezcWebdavRequest::DEPTH_ONE && $propertyValue !== 
ezcWebdavRequest::DEPTH_ZERO )
                 {
-                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'ezcWebdavLockDiscoveryPropertyActiveLock::DEPTH_*' );
+                    return $this->hasError( $propertyName, $propertyValue, 
'ezcWebdavLockDiscoveryPropertyActiveLock::DEPTH_*' );
                 }
                 break;
             case 'owner':
                 if ( is_string( $propertyValue ) === false && $propertyValue 
!== null )
                 {
-                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'string' );
+                    return $this->hasError( $propertyName, $propertyValue, 
'string' );
                 }
                 break;
             case 'timeout':
                 if ( ( $propertyValue instanceof DateTime ) === false && 
$propertyValue !== null )
                 {
-                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'DateTime' );
+                    return $this->hasError( $propertyName, $propertyValue, 
'DateTime' );
                 }
                 break;
             case 'timeout':
                 if ( ( $propertyValue instanceof DateTime ) === false && 
$propertyValue !== null )
                 {
-                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'DateTime' );
+                    return $this->hasError( $propertyName, $propertyValue, 
'DateTime' );
                 }
                 break;
             case 'tokens':
                 if ( is_array( $propertyValue ) === false )
                 {
-                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'array(string)' );
+                    return $this->hasError( $propertyName, $propertyValue, 
'array(string)' );
                 }
                 break;
             default:
-                parent::__set( $propertyName, $propertyValue );
+                return parent::__set( $propertyName, $propertyValue );
         }
         $this->properties[$propertyName] = $propertyValue;
     }

Modified: trunk/Webdav/src/properties/resourcetype.php
==============================================================================
--- trunk/Webdav/src/properties/resourcetype.php [iso-8859-1] (original)
+++ trunk/Webdav/src/properties/resourcetype.php [iso-8859-1] Thu Sep 20 
11:34:03 2007
@@ -53,7 +53,7 @@
             case 'type':
                 if ( is_string( $propertyValue ) === false && $propertyValue 
!== null )
                 {
-                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'string' );
+                    return $this->hasError( $propertyName, $propertyValue, 
'string' );
                 }
 
                 $this->properties[$propertyName] = $propertyValue;

Modified: trunk/Webdav/src/properties/source.php
==============================================================================
--- trunk/Webdav/src/properties/source.php [iso-8859-1] (original)
+++ trunk/Webdav/src/properties/source.php [iso-8859-1] Thu Sep 20 11:34:03 2007
@@ -53,7 +53,7 @@
             case 'links':
                 if ( is_array( $propertyValue ) === false )
                 {
-                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'array(ezcWebdavSourcePropertyLink)' );
+                    return $this->hasError( $propertyName, $propertyValue, 
'array(ezcWebdavSourcePropertyLink)' );
                 }
 
                 $this->properties[$propertyName] = $propertyValue;

Modified: trunk/Webdav/src/properties/source_link.php
==============================================================================
--- trunk/Webdav/src/properties/source_link.php [iso-8859-1] (original)
+++ trunk/Webdav/src/properties/source_link.php [iso-8859-1] Thu Sep 20 
11:34:03 2007
@@ -57,7 +57,7 @@
             case 'src':
                 if ( is_string( $propertyValue ) === false && $propertyValue 
!== null )
                 {
-                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'string' );
+                    return $this->hasError( $propertyName, $propertyValue, 
'string' );
                 }
 
                 $this->properties[$propertyName] = $propertyValue;
@@ -66,7 +66,7 @@
             case 'dst':
                 if ( is_string( $propertyValue ) === false && $propertyValue 
!== null )
                 {
-                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'string' );
+                    return $this->hasError( $propertyName, $propertyValue, 
'string' );
                 }
 
                 $this->properties[$propertyName] = $propertyValue;

Modified: trunk/Webdav/src/properties/supportedlock.php
==============================================================================
--- trunk/Webdav/src/properties/supportedlock.php [iso-8859-1] (original)
+++ trunk/Webdav/src/properties/supportedlock.php [iso-8859-1] Thu Sep 20 
11:34:03 2007
@@ -53,7 +53,7 @@
             case 'lockEntry':
                 if ( is_array( $propertyValue ) === false && $propertyValue 
!== null )
                 {
-                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'array(ezcWebdavSupportedLockPropertyLockentry)' );
+                    return $this->hasError( $propertyName, $propertyValue, 
'array(ezcWebdavSupportedLockPropertyLockentry)' );
                 }
 
                 $this->properties[$propertyName] = $propertyValue;

Modified: trunk/Webdav/src/properties/supportedlock_lockentry.php
==============================================================================
--- trunk/Webdav/src/properties/supportedlock_lockentry.php [iso-8859-1] 
(original)
+++ trunk/Webdav/src/properties/supportedlock_lockentry.php [iso-8859-1] Thu 
Sep 20 11:34:03 2007
@@ -57,7 +57,7 @@
             case 'lockType':
                 if ( $propertyValue !== ezcWebdavLockRequest::TYPE_READ && 
$propertyValue !== ezcWebdavLockRequest::TYPE_WRITE )
                 {
-                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'ezcWebdavLockRequest::TYPE_*' );
+                    return $this->hasError( $propertyName, $propertyValue, 
'ezcWebdavLockRequest::TYPE_*' );
                 }
 
                 $this->properties[$propertyName] = $propertyValue;
@@ -66,7 +66,7 @@
             case 'lockScope':
                 if ( $propertyValue !== ezcWebdavLockRequest::SCOPE_SHARED && 
$propertyValue !== ezcWebdavLockRequest::SCOPE_EXCLUSIVE )
                 {
-                    throw new ezcBaseValueException( $propertyName, 
$propertyValue, 'ezcWebdavLockRequest::SCOPE_*' );
+                    return $this->hasError( $propertyName, $propertyValue, 
'ezcWebdavLockRequest::SCOPE_*' );
                 }
 
                 $this->properties[$propertyName] = $propertyValue;

Modified: trunk/Webdav/tests/backend_memory_test.php
==============================================================================
--- trunk/Webdav/tests/backend_memory_test.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/backend_memory_test.php [iso-8859-1] Thu Sep 20 11:34:03 
2007
@@ -1844,7 +1844,7 @@
             new ezcWebdavGetLastModifiedProperty()
         );
         $propertyStorage->attach(
-            new ezcWebdavGetContentLengthProperty()
+            $test = new ezcWebdavGetContentLengthProperty()
         );
 
         $expectedResponse = new ezcWebdavMultistatusResponse(

Modified: trunk/Webdav/tests/property_test.php
==============================================================================
--- trunk/Webdav/tests/property_test.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/property_test.php [iso-8859-1] Thu Sep 20 11:34:03 2007
@@ -158,6 +158,7 @@
                 try
                 {
                     $object->$propName = $value;
+                    $this->fail( 'Expected ezcBaseValueException.' );
                 }
                 catch ( ezcBaseValueException $e ) {}
 

Modified: trunk/Webdav/tests/webdav_property_test.php
==============================================================================
--- trunk/Webdav/tests/webdav_property_test.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/webdav_property_test.php [iso-8859-1] Thu Sep 20 
11:34:03 2007
@@ -97,6 +97,29 @@
         );
     }
 
+    public function testSetAccessFailure()
+    {
+        foreach ( $this->failingValues as $propName => $values )
+        {
+            foreach( $values as $value )
+            {
+                $object = $this->getObject();
+                $object->$propName = $value;
+
+                $this->assertEquals( 
+                    true,
+                    $object->hasError
+                );
+
+                $this->assertEquals( 
+                    $this->defaultValues[$propName], 
+                    $object->$propName,
+                    "Failed default value for $propName."
+                );
+            }
+        }
+    }
+
     public function testPropertyNoContentWithContentSet()
     {
         $object = $this->getObject();


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

Reply via email to