Author: Russ
Date: 2010-03-04 20:18:35 +0100 (Thu, 04 Mar 2010)
New Revision: 28383

Modified:
   plugins/sfDoctrinePlugin/branches/1.3-2.0/lib/form/sfFormDoctrine.class.php
Log:
[1.4][sfDoctrine2Plugin] Move isNew check out of constructor for better 
performance


Modified: 
plugins/sfDoctrinePlugin/branches/1.3-2.0/lib/form/sfFormDoctrine.class.php
===================================================================
--- plugins/sfDoctrinePlugin/branches/1.3-2.0/lib/form/sfFormDoctrine.class.php 
2010-03-04 18:11:31 UTC (rev 28382)
+++ plugins/sfDoctrinePlugin/branches/1.3-2.0/lib/form/sfFormDoctrine.class.php 
2010-03-04 19:18:35 UTC (rev 28383)
@@ -33,7 +33,7 @@
 abstract class sfFormDoctrine extends sfFormObject
 {
   protected
-    $isNew  = true,
+    $isNew  = null,
     $object = null,
     $em;
 
@@ -56,14 +56,11 @@
       {
         throw new sfException(sprintf('The "%s" form only accepts a "%s" 
object.', get_class($this), $class));
       }
-
       $this->object = $object;
-
-      $id = 
$this->em->getMetadataFactory()->getMetadataFor(get_class($object))->getIdentifierValues($object);
-      $this->isNew = ($this->em->contains($object) && ! empty($id)) ? true : 
false;
     }
     else
     {
+      $this->isNew  = true;
       $this->object = new $class();
     }
 
@@ -94,6 +91,11 @@
    */
   public function isNew()
   {
+    if (is_null($this->isNew))
+    {
+      $id = 
$this->em->getMetadataFactory()->getMetadataFor(get_class($this->object))->getIdentifierValues($this->object);
+      $this->isNew = ($this->em->contains($this->object) && ! empty($id)) ? 
true : false;
+    }
     return $this->isNew;
   }
 

-- 
You received this message because you are subscribed to the Google Groups 
"symfony 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.com/group/symfony-svn?hl=en.

Reply via email to