Author: jwage
Date: 2008-08-27 21:26:49 +0100 (Wed, 27 Aug 2008)
New Revision: 4852

Added:
   branches/1.0/tests/Ticket/1077TestCase.php
Modified:
   branches/1.0/lib/Doctrine.php
   branches/1.0/lib/Doctrine/Configurable.php
   branches/1.0/lib/Doctrine/Manager.php
   branches/1.0/lib/Doctrine/Record.php
   branches/1.0/tests/run.php
Log:
fixes #1077


Modified: branches/1.0/lib/Doctrine/Configurable.php
===================================================================
--- branches/1.0/lib/Doctrine/Configurable.php  2008-08-27 19:04:26 UTC (rev 
4851)
+++ branches/1.0/lib/Doctrine/Configurable.php  2008-08-27 20:26:49 UTC (rev 
4852)
@@ -181,6 +181,7 @@
             case Doctrine::ATTR_QUERY_CACHE_LIFESPAN:
             case Doctrine::ATTR_RECURSIVE_MERGE_FIXTURES;
             case Doctrine::ATTR_USE_DQL_CALLBACKS;
+            case Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE;
 
                 break;
             case Doctrine::ATTR_SEQCOL_NAME:

Modified: branches/1.0/lib/Doctrine/Manager.php
===================================================================
--- branches/1.0/lib/Doctrine/Manager.php       2008-08-27 19:04:26 UTC (rev 
4851)
+++ branches/1.0/lib/Doctrine/Manager.php       2008-08-27 20:26:49 UTC (rev 
4852)
@@ -102,6 +102,7 @@
                         Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE  => 'doctrine',
                         Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES   => false,
                         Doctrine::ATTR_USE_DQL_CALLBACKS        => false,
+                        Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE   => false,
                         ); 
             foreach ($attributes as $attribute => $value) {
                 $old = $this->getAttribute($attribute);

Modified: branches/1.0/lib/Doctrine/Record.php
===================================================================
--- branches/1.0/lib/Doctrine/Record.php        2008-08-27 19:04:26 UTC (rev 
4851)
+++ branches/1.0/lib/Doctrine/Record.php        2008-08-27 20:26:49 UTC (rev 
4852)
@@ -138,6 +138,20 @@
     protected $_pendingDeletes = array();
 
     /**
+     * Array of custom accessors for cache
+     *
+     * @var array
+     */
+    protected static $_customAccessors = array();
+
+    /**
+     * Array of custom mutators for cache
+     *
+     * @var array
+     */
+    protected static $_customMutators = array();
+
+    /**
      * @var integer $index                  this index is used for creating 
object identifiers
      */
     private static $_index = 1;
@@ -892,6 +906,19 @@
      */
     public function get($fieldName, $load = true)
     {
+        if 
($this->_table->getAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE)) {
+            $componentName = $this->_table->getComponentName();
+            $accessor = 
isset(self::$_customAccessors[$componentName][$fieldName]) ? 
self::$_customAccessors[$componentName][$fieldName]:'get' . 
Doctrine_Inflector::classify($fieldName);
+            if (isset(self::$_customAccessors[$componentName][$fieldName]) || 
method_exists($this, $accessor)) {
+                self::$_customAccessors[$componentName][$fieldName] = 
$accessor;
+                return $this->$accessor($load);
+            }
+        }
+        return $this->_get($fieldName, $load);
+    }
+
+    protected function _get($fieldName, $load = true)
+    {
         $value = self::$_null;
 
         if (isset($this->_data[$fieldName])) {
@@ -960,6 +987,19 @@
      */
     public function set($fieldName, $value, $load = true)
     {
+        if 
($this->_table->getAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE)) {
+            $componentName = $this->_table->getComponentName();
+            $mutator = 
isset(self::$_customMutators[$componentName][$fieldName]) ? 
self::$_customMutators[$componentName][$fieldName]:'set' . 
Doctrine_Inflector::classify($fieldName);
+            if (isset(self::$_customMutators[$componentName][$fieldName]) || 
method_exists($this, $mutator)) {
+                self::$_customMutators[$componentName][$fieldName] = $mutator;
+                return $this->$mutator($value, $load);
+            }
+        }
+        return $this->_set($fieldName, $value, $load);
+    }
+
+    protected function _set($fieldName, $value, $load = true)
+    {
         if (isset($this->_data[$fieldName])) {
             $type = $this->_table->getTypeOf($fieldName);
             if ($value instanceof Doctrine_Record) {

Modified: branches/1.0/lib/Doctrine.php
===================================================================
--- branches/1.0/lib/Doctrine.php       2008-08-27 19:04:26 UTC (rev 4851)
+++ branches/1.0/lib/Doctrine.php       2008-08-27 20:26:49 UTC (rev 4852)
@@ -195,6 +195,7 @@
     const ATTR_MODEL_LOADING            = 161;
     const ATTR_RECURSIVE_MERGE_FIXTURES = 162;
     const ATTR_USE_DQL_CALLBACKS        = 164;
+    const ATTR_AUTO_ACCESSOR_OVERRIDE   = 165;
 
     /**
      * LIMIT CONSTANTS

Added: branches/1.0/tests/Ticket/1077TestCase.php
===================================================================
--- branches/1.0/tests/Ticket/1077TestCase.php                          (rev 0)
+++ branches/1.0/tests/Ticket/1077TestCase.php  2008-08-27 20:26:49 UTC (rev 
4852)
@@ -0,0 +1,124 @@
+<?php
+/*
+ *  $Id$
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information, see
+ * <http://www.phpdoctrine.org>.
+ */
+
+/**
+ * Doctrine_Ticket_1077_TestCase
+ *
+ * @package     Doctrine
+ * @author      Konsta Vesterinen <[EMAIL PROTECTED]>
+ * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
+ * @category    Object Relational Mapping
+ * @link        www.phpdoctrine.org
+ * @since       1.0
+ * @version     $Revision$
+ */
+class Doctrine_Ticket_1077_TestCase extends Doctrine_UnitTestCase 
+{
+    public function prepareTables()
+    {
+        $this->tables[] = 'Ticket_1077_User';
+        $this->tables[] = 'Ticket_1077_Phonenumber';
+        parent::prepareTables();
+    }
+
+    public function testTest()
+    {
+        $orig = 
Doctrine_Manager::getInstance()->getAttribute('auto_accessor_override');
+        
Doctrine_Manager::getInstance()->setAttribute('auto_accessor_override', true);
+        $user = new Ticket_1077_User();
+        $user->username = 'jwage';
+        $user->password = 'changeme';
+        $user->save();
+        $this->assertEqual($user->getPassword(), 
'4cb9c8a8048fd02294477fcb1a41191a');
+        $this->assertEqual($user->getUsername(), 'Username: jwage');
+        $this->assertEqual($user->username, $user->getUsername());
+
+        try {
+            $phonenumbers = $user->Phonenumbers;
+            $this->fail();
+        } catch (Exception $e) {
+            $this->assertEqual($e->getMessage(), 'Testing that 
getPhonenumbers() is invoked');
+        }
+
+        $numbers = new Doctrine_Collection('Phonenumber');
+        $user->Phonenumbers = $numbers;
+        $this->assertEqual($user->phonenumbersTest, $numbers);
+        
Doctrine_Manager::getInstance()->setAttribute('auto_accessor_override', $orig);
+    }
+}
+
+class Ticket_1077_User extends Doctrine_Record
+{
+    public $phonenumbersTest = null;
+
+    public function setTableDefinition()
+    {
+        $this->hasColumn('username', 'string', 255);
+        $this->hasColumn('password', 'string', 255);
+    }
+
+    public function setUp()
+    {
+        $this->hasMany('Ticket_1077_Phonenumber as Phonenumbers', 
array('local'   => 'id',
+                                                                        
'foreign' => 'user_id'));
+    }
+
+    public function getPhonenumbers()
+    {
+        throw new Exception('Testing that getPhonenumbers() is invoked');
+    }
+
+    public function setPhonenumbers($phonenumbers)
+    {
+        $this->phonenumbersTest = $phonenumbers;
+        return $this->_set('Phonenumbers', $phonenumbers);
+    }
+
+    public function getUsername($load = true)
+    {
+        return 'Username: ' . $this->_get('username', $load);
+    }
+
+    public function setPassword($password)
+    {
+        return $this->_set('password', md5($password));
+    }
+
+    public function getPassword($load = true)
+    {
+        return $this->_get('password', $load);
+    }
+}
+
+class Ticket_1077_Phonenumber extends Doctrine_Record
+{
+    public function setTableDefinition()
+    {
+        $this->hasColumn('phonenumber', 'string', 55);
+        $this->hasColumn('user_id', 'integer');
+    }
+
+    public function setUp()
+    {
+        $this->hasOne('Ticket_1077_User as User', array('local'   => 'user_id',
+                                                        'foreign' => 'id'));
+    }
+}
\ No newline at end of file

Modified: branches/1.0/tests/run.php
===================================================================
--- branches/1.0/tests/run.php  2008-08-27 19:04:26 UTC (rev 4851)
+++ branches/1.0/tests/run.php  2008-08-27 20:26:49 UTC (rev 4852)
@@ -81,6 +81,7 @@
 $tickets->addTestCase(new Doctrine_Ticket_1044_TestCase());
 $tickets->addTestCase(new Doctrine_Ticket_1071_TestCase());
 $tickets->addTestCase(new Doctrine_Ticket_1072_TestCase());
+$tickets->addTestCase(new Doctrine_Ticket_1077_TestCase());
 $tickets->addTestCase(new Doctrine_Ticket_1099_TestCase());
 $tickets->addTestCase(new Doctrine_Ticket_1106_TestCase());
 $tickets->addTestCase(new Doctrine_Ticket_1113_TestCase());


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"doctrine-svn" group.
 To post to this group, send email to [email protected]
 To unsubscribe from this group, send email to [EMAIL PROTECTED]
 For more options, visit this group at 
http://groups.google.co.uk/group/doctrine-svn?hl=en-GB
-~----------~----~----~----~------~----~------~--~---

Reply via email to