Author: ts
Date: Tue Nov 27 17:46:34 2007
New Revision: 6842

Log:
- Fixed issue #12082: Restoring a definition from var_export( $definition )
  PHP code.

Modified:
    trunk/PersistentObject/ChangeLog
    trunk/PersistentObject/src/interfaces/relation.php
    trunk/PersistentObject/src/object/persistent_object_columns.php
    trunk/PersistentObject/src/object/persistent_object_definition.php
    trunk/PersistentObject/src/object/persistent_object_id_property.php
    trunk/PersistentObject/src/object/persistent_object_properties.php
    trunk/PersistentObject/src/object/persistent_object_property.php
    trunk/PersistentObject/src/object/persistent_object_relations.php
    trunk/PersistentObject/src/relations/many_to_many.php
    trunk/PersistentObject/src/relations/many_to_one.php
    trunk/PersistentObject/src/relations/one_to_many.php
    trunk/PersistentObject/src/relations/one_to_one.php
    trunk/PersistentObject/tests/persistent_session_test.php

Modified: trunk/PersistentObject/ChangeLog
==============================================================================
--- trunk/PersistentObject/ChangeLog [iso-8859-1] (original)
+++ trunk/PersistentObject/ChangeLog [iso-8859-1] Tue Nov 27 17:46:34 2007
@@ -5,6 +5,8 @@
 - Fixed issue #11405: Ambiguous column names when using
   ezcPersistentManyToManyRelation. Column names are now correctly prefixed
   with their corresponding table names.
+- Fixed issue #12082: Restoring a definition from var_export( $definition )
+  PHP code.
 
 
 1.3.1 - Monday 13 August 2007

Modified: trunk/PersistentObject/src/interfaces/relation.php
==============================================================================
--- trunk/PersistentObject/src/interfaces/relation.php [iso-8859-1] (original)
+++ trunk/PersistentObject/src/interfaces/relation.php [iso-8859-1] Tue Nov 27 
17:46:34 2007
@@ -30,7 +30,7 @@
      *
      * @var array
      */
-    private $properties = array(
+    protected $properties = array(
         "sourceTable"       => null,
         "destinationTable"  => null,
         "columnMap"         => array(),

Modified: trunk/PersistentObject/src/object/persistent_object_columns.php
==============================================================================
--- trunk/PersistentObject/src/object/persistent_object_columns.php 
[iso-8859-1] (original)
+++ trunk/PersistentObject/src/object/persistent_object_columns.php 
[iso-8859-1] Tue Nov 27 17:46:34 2007
@@ -19,11 +19,11 @@
 class ezcPersistentObjectColumns extends ArrayObject
 {
     /**
-     * Stores the relation objects. 
+     * Stores the column objects. 
      * 
      * @var array(ezcPersistentObjectProperty)
      */
-    private $relations;
+    private $columns;
 
     /**
      * Create a new instance.
@@ -33,8 +33,8 @@
      */
     public function __construct()
     {
-        $this->relations = array();
-        parent::__construct( $this->relations );
+        $this->columns = array();
+        parent::__construct( $this->columns );
     }
 
     /**
@@ -105,6 +105,27 @@
     {
         throw new Exception( 'Operation append is not supported by this 
object.' );
     }
+
+    /**
+     * Sets the state on deserialization.
+     * 
+     * @param array $state
+     * @return ezcPersistentObjectColumns
+     */
+    public static function __set_state( array $state )
+    {
+        $columns = new ezcPersistentObjectColumns();
+        if ( isset( $state['columns'] ) && sizeof( $state ) === 1 )
+        {
+            $columns->exchangeArray( $state['columns'] );
+        }
+        else
+        {
+            // Old style exports
+            $columns->exchangeArray( $state );
+        }
+        return $columns;
+    }
 }
 
 ?>

Modified: trunk/PersistentObject/src/object/persistent_object_definition.php
==============================================================================
--- trunk/PersistentObject/src/object/persistent_object_definition.php 
[iso-8859-1] (original)
+++ trunk/PersistentObject/src/object/persistent_object_definition.php 
[iso-8859-1] Tue Nov 27 17:46:34 2007
@@ -43,7 +43,7 @@
      * 
      * @var array(string=>mixed)
      */
-    private $propertyArray = array(
+    protected $propertyArray = array(
         'table'      => null,
         'class'      => null,
         'idProperty' => null,
@@ -219,11 +219,29 @@
      */
     public static function __set_state( array $array )
     {
-        return new ezcPersistentObjectDefinition( $array['table'],
-                                                  $array['class'],
-                                                  $array['properties'],
-                                                  $array['relations'],
-                                                  $array['idProperty'] );
+        if ( isset( $array['propertyArray'] ) && count( $array ) === 1 )
+        {
+            $def =  new ezcPersistentObjectDefinition(
+                $array['propertyArray']['table'],
+                $array['propertyArray']['class']
+            );
+            $def->properties = $array['propertyArray']['properties'];
+            $def->columns    = $array['propertyArray']['columns'];
+            $def->relations  = $array['propertyArray']['relations'];
+            $def->idProperty = $array['propertyArray']['idProperty'];
+        }
+        else
+        {
+            $def = new ezcPersistentObjectDefinition(
+                $array['table'],
+                $array['class'],
+                $array['properties'],
+                $array['relations'],
+                $array['idProperty']
+            );
+            $def->columns = $array['columns'];
+        }
+        return $def;
     }
 }
 ?>

Modified: trunk/PersistentObject/src/object/persistent_object_id_property.php
==============================================================================
--- trunk/PersistentObject/src/object/persistent_object_id_property.php 
[iso-8859-1] (original)
+++ trunk/PersistentObject/src/object/persistent_object_id_property.php 
[iso-8859-1] Tue Nov 27 17:46:34 2007
@@ -169,10 +169,20 @@
      */
     public static function __set_state( array $array )
     {
-        return new ezcPersistentObjectIdProperty( $array['columnName'],
-                                                  $array['propertyName'],
-                                                  $array['visibility'],
-                                                  $array['generator'] );
+        if ( isset( $array['properties'] ) && count( $array ) === 1 )
+        {
+            return new ezcPersistentObjectIdProperty( 
$array['properties']['columnName'],
+                                                      
$array['properties']['propertyName'],
+                                                      
$array['properties']['visibility'],
+                                                      
$array['properties']['generator'] );
+        }
+        else
+        {
+            return new ezcPersistentObjectIdProperty( $array['columnName'],
+                                                      $array['propertyName'],
+                                                      $array['visibility'],
+                                                      $array['generator'] );
+        }
     }
 }
 

Modified: trunk/PersistentObject/src/object/persistent_object_properties.php
==============================================================================
--- trunk/PersistentObject/src/object/persistent_object_properties.php 
[iso-8859-1] (original)
+++ trunk/PersistentObject/src/object/persistent_object_properties.php 
[iso-8859-1] Tue Nov 27 17:46:34 2007
@@ -23,7 +23,7 @@
      * 
      * @var array(ezcPersistentObjectProperty)
      */
-    private $properties;
+    protected $properties;
 
     /**
      * Create a new instance.
@@ -105,6 +105,27 @@
     {
         throw new Exception( 'Operation append is not supported by this 
object.' );
     }
+    
+    /**
+     * Sets the state on deserialization.
+     * 
+     * @param array $state
+     * @return ezcPersistentObjectProperties
+     */
+    public static function __set_state( array $state )
+    {
+        $properties = new ezcPersistentObjectProperties();
+        if ( isset( $state['properties'] ) && count( $state ) === 1 )
+        {
+            $properties->exchangeArray( $state['properties'] );
+        }
+        else
+        {
+            // Old style exports
+            $properties->exchangeArray( $state );
+        }
+        return $properties;
+    }
 }
 
 ?>

Modified: trunk/PersistentObject/src/object/persistent_object_property.php
==============================================================================
--- trunk/PersistentObject/src/object/persistent_object_property.php 
[iso-8859-1] (original)
+++ trunk/PersistentObject/src/object/persistent_object_property.php 
[iso-8859-1] Tue Nov 27 17:46:34 2007
@@ -70,9 +70,19 @@
      */
     public static function __set_state( array $array )
     {
-        return new ezcPersistentObjectProperty( $array['columnName'],
-                                                $array['propertyName'],
-                                                $array['propertyType'] );
+        if ( isset( $array['properties'] ) )
+        {
+            return new ezcPersistentObjectProperty( 
$array['properties']['columnName'],
+                                                    
$array['properties']['propertyName'],
+                                                    
$array['properties']['propertyType'] );
+        }
+        else
+        {
+            // Old style exports
+            return new ezcPersistentObjectProperty( $array['columnName'],
+                                                    $array['propertyName'],
+                                                    $array['propertyType'] );
+        }
     }
 
     /**

Modified: trunk/PersistentObject/src/object/persistent_object_relations.php
==============================================================================
--- trunk/PersistentObject/src/object/persistent_object_relations.php 
[iso-8859-1] (original)
+++ trunk/PersistentObject/src/object/persistent_object_relations.php 
[iso-8859-1] Tue Nov 27 17:46:34 2007
@@ -105,6 +105,27 @@
     {
         throw new Exception( 'Operation append is not supported by this 
object.' );
     }
+    
+    /**
+     * Sets the state on deserialization.
+     * 
+     * @param array $state
+     * @return ezcPersistentObjectRelations
+     */
+    public static function __set_state( array $state )
+    {
+        $columns = new ezcPersistentObjectRelations();
+        if ( isset( $state['columns'] ) && count( $state ) === 1 )
+        {
+            $columns->exchangeArray( $state['columns'] );
+        }
+        else
+        {
+            // Old exported objects.
+            $columns->exchangeArray( $state );
+        }
+        return $columns;
+    }
 }
 
 ?>

Modified: trunk/PersistentObject/src/relations/many_to_many.php
==============================================================================
--- trunk/PersistentObject/src/relations/many_to_many.php [iso-8859-1] 
(original)
+++ trunk/PersistentObject/src/relations/many_to_many.php [iso-8859-1] Tue Nov 
27 17:46:34 2007
@@ -17,15 +17,6 @@
 class ezcPersistentManyToManyRelation extends ezcPersistentRelation
 {
     /**
-     * Holds the properties for this class.
-     *
-     * @var array
-     */
-    private $properties = array(
-        "relationTable" => null
-    );
-
-    /**
      * Constructs a new many to many relation from the table $sourceTable to
      * the table $destinationTable via $relationTable
      *
@@ -35,6 +26,8 @@
      */
     public function __construct( $sourceTable, $destinationTable, 
$relationTable )
     {
+        $this->properties['relationTable'] = null;
+
         $this->sourceTable      = $sourceTable;
         $this->destinationTable = $destinationTable;
         $this->relationTable    = $relationTable;
@@ -144,6 +137,23 @@
         }
         return parent::__isset( ( $propertyName ) );
     }
+
+    /**
+     * Sets the state after importing an exported object.
+     * 
+     * @param array $state 
+     * @return void
+     */
+    public static function __set_state( array $state )
+    {
+        $rel = new ezcPersistentManyToManyRelation( 
+            $state['properties']['sourceTable'],
+            $state['properties']['destinationTable'],
+            $state['properties']['relationTable']
+        );
+        $rel->properties = $state['properties'];
+        return $rel;
+    }
 }
 
 ?>

Modified: trunk/PersistentObject/src/relations/many_to_one.php
==============================================================================
--- trunk/PersistentObject/src/relations/many_to_one.php [iso-8859-1] (original)
+++ trunk/PersistentObject/src/relations/many_to_one.php [iso-8859-1] Tue Nov 
27 17:46:34 2007
@@ -21,14 +21,18 @@
 class ezcPersistentManyToOneRelation extends ezcPersistentRelation
 {
     /**
-     * Holds the properties for this class.
+     * Create a new relation.
      *
-     * @var array
+     * @param string $sourceTable      See property $sourceTable
+     * @param string $destinationTable See property $destinationTable
      */
-    private $properties = array(
-        "cascade" => false,
-        "reverse" => true,
-    );
+    public function __construct( $sourceTable, $destinationTable )
+    {
+        parent::__construct( $sourceTable, $destinationTable );
+        $this->properties['cascade'] = false;
+        $this->properties['reverse'] = true;
+    }
+
 
     /**
      * Validates an [EMAIL PROTECTED] ezcPersistentRelation::$columnMap} 
property.
@@ -137,6 +141,22 @@
         }
         return parent::__isset( ( $propertyName ) );
     }
+
+    /**
+     * Sets the state after importing an exported object.
+     * 
+     * @param array $state 
+     * @return void
+     */
+    public static function __set_state( array $state )
+    {
+        $rel = new ezcPersistentManyToOneRelation( 
+            $state['properties']['sourceTable'],
+            $state['properties']['destinationTable']
+        );
+        $rel->properties = $state['properties'];
+        return $rel;
+    }
 }
 
 ?>

Modified: trunk/PersistentObject/src/relations/one_to_many.php
==============================================================================
--- trunk/PersistentObject/src/relations/one_to_many.php [iso-8859-1] (original)
+++ trunk/PersistentObject/src/relations/one_to_many.php [iso-8859-1] Tue Nov 
27 17:46:34 2007
@@ -20,14 +20,18 @@
  */
 class ezcPersistentOneToManyRelation extends ezcPersistentRelation
 {
+
     /**
-     * Holds the properties for this class.
+     * Create a new relation.
      *
-     * @var array
+     * @param string $sourceTable      See property $sourceTable
+     * @param string $destinationTable See property $destinationTable
      */
-    private $properties = array(
-        "cascade" => false,
-    );
+    public function __construct( $sourceTable, $destinationTable )
+    {
+        parent::__construct( $sourceTable, $destinationTable );
+        $this->properties['cascade'] = false;
+    }
 
     /**
      * Validates an [EMAIL PROTECTED] ezcPersistentRelation::$columnMap} 
property.
@@ -133,6 +137,22 @@
         }
         return parent::__isset( ( $propertyName ) );
     }
+
+    /**
+     * Sets the state after importing an exported object.
+     * 
+     * @param array $state 
+     * @return void
+     */
+    public static function __set_state( array $state )
+    {
+        $rel = new ezcPersistentOneToManyRelation( 
+            $state['properties']['sourceTable'],
+            $state['properties']['destinationTable']
+        );
+        $rel->properties = $state['properties'];
+        return $rel;
+    }
 }
 
 ?>

Modified: trunk/PersistentObject/src/relations/one_to_one.php
==============================================================================
--- trunk/PersistentObject/src/relations/one_to_one.php [iso-8859-1] (original)
+++ trunk/PersistentObject/src/relations/one_to_one.php [iso-8859-1] Tue Nov 27 
17:46:34 2007
@@ -21,13 +21,16 @@
 class ezcPersistentOneToOneRelation extends ezcPersistentRelation
 {
     /**
-     * Holds the properties for this class.
+     * Create a new relation.
      *
-     * @var array
+     * @param string $sourceTable      See property $sourceTable
+     * @param string $destinationTable See property $destinationTable
      */
-    private $properties = array(
-        "cascade" => false,
-    );
+    public function __construct( $sourceTable, $destinationTable )
+    {
+        parent::__construct( $sourceTable, $destinationTable );
+        $this->properties['cascade'] = false;
+    }
 
     /**
      * Validates an [EMAIL PROTECTED] ezcPersistentRelation::$columnMap} 
property.
@@ -133,6 +136,22 @@
         }
         return parent::__isset( ( $propertyName ) );
     }
+
+    /**
+     * Sets the state after importing an exported object.
+     * 
+     * @param array $state 
+     * @return void
+     */
+    public static function __set_state( array $state )
+    {
+        $rel = new ezcPersistentOneToOneRelation( 
+            $state['properties']['sourceTable'],
+            $state['properties']['destinationTable']
+        );
+        $rel->properties = $state['properties'];
+        return $rel;
+    }
 }
 
 ?>

Modified: trunk/PersistentObject/tests/persistent_session_test.php
==============================================================================
--- trunk/PersistentObject/tests/persistent_session_test.php [iso-8859-1] 
(original)
+++ trunk/PersistentObject/tests/persistent_session_test.php [iso-8859-1] Tue 
Nov 27 17:46:34 2007
@@ -10,6 +10,11 @@
 
 require_once "data/persistent_test_object.php";
 require_once "data/persistent_test_object_no_id.php";
+
+require_once "data/relation_test_address.php";
+require_once "data/relation_test_person.php";
+require_once "data/relation_test_birthday.php";
+require_once "data/relation_test_employer.php";
 
 /**
  * Tests the code manager.
@@ -751,6 +756,38 @@
             )
         );
     }
+    
+    public function testExportImportDefinitions()
+    {
+        $classes = array(
+            'PersistentTestObject',
+            'RelationTestAddress',
+            'RelationTestEmployer',
+            'RelationTestBirthday',
+            'RelationTestPerson',
+        );
+        $dir = $this->createTempDir( 'export' );
+
+        foreach( $classes as $class )
+        {
+            $def = $this->session->definitionManager->fetchDefinition( $class 
);
+
+            $file = $dir . "/$class.php";
+            
+
+            file_put_contents( $file, "<?php\nreturn " . var_export( $def, 
true ) . ";\n?>" );
+            $deserialized = require $file;
+
+            $this->assertEquals(
+                $def,
+                $deserialized,
+                "Objects of class $class not exported/imported correctly."
+            );
+
+        }
+
+        $this->removeTempDir();
+    }
 }
 
 ?>


-- 
svn-components mailing list
svn-components@lists.ez.no
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to