Caching the parser is not a good idea.
authorGunnar Wrobel <p@rdus.de>
Mon, 13 Dec 2010 09:29:50 +0000 (10:29 +0100)
committerGunnar Wrobel <p@rdus.de>
Mon, 13 Dec 2010 10:17:29 +0000 (11:17 +0100)
framework/Kolab_Format/lib/Horde/Kolab/Format/Factory.php
framework/Kolab_Format/test/Horde/Kolab/Format/Integration/EventTest.php
framework/Kolab_Format/test/Horde/Kolab/Format/Unit/FactoryTest.php

index f453ba5..f1a625f 100644 (file)
 class Horde_Kolab_Format_Factory
 {
     /**
-     * Instances.
-     *
-     * @var array
-     */
-    private $_instances = array();
-
-    /**
      * Generates a handler for a specific Kolab object type.
      *
      * @param string $format The format that the handler should work with.
@@ -58,35 +51,32 @@ class Horde_Kolab_Format_Factory
             . ucfirst(strtolower(str_replace('-', '', $object)))
         );
 
-        if (!isset($this->_instances[$class])) {
-            if (class_exists($class)) {
-                switch ($parser) {
-                case 'Xml':
-                    $this->_instances[$class] = new $class(
-                        new Horde_Kolab_Format_Xml_Parser(
-                            new DOMDocument('1.0', 'UTF-8')
-                        ),
-                        $params
-                    );
-                    break;
-                default:
-                    throw new Horde_Kolab_Format_Exception(
-                        sprintf(
-                            'Failed to initialize the specified parser (Parser type %s does not exist)!',
-                            $parser
-                        )
-                    );
-                }
-            } else {
+        if (class_exists($class)) {
+            switch ($parser) {
+            case 'Xml':
+                return new $class(
+                    new Horde_Kolab_Format_Xml_Parser(
+                        new DOMDocument('1.0', 'UTF-8')
+                    ),
+                    $params
+                );
+                break;
+            default:
                 throw new Horde_Kolab_Format_Exception(
                     sprintf(
-                        'Failed to load the specified Kolab Format handler (Class %s does not exist)!',
-                        $class
+                        'Failed to initialize the specified parser (Parser type %s does not exist)!',
+                        $parser
                     )
                 );
             }
+        } else {
+            throw new Horde_Kolab_Format_Exception(
+                sprintf(
+                    'Failed to load the specified Kolab Format handler (Class %s does not exist)!',
+                    $class
+                )
+            );
         }
-        return $this->_instances[$class];
     }
 
     /**
index fbb33ab..82f2bd4 100644 (file)
@@ -52,6 +52,8 @@ extends Horde_Kolab_Format_TestCase
         // Check that the xml loads fine
         $this->assertEquals('...übbe...', $result['body']);
 
+        $xml = $this->getFactory()->create('XML', 'event');
+
         // Load XML
         $event  = file_get_contents(dirname(__FILE__)
                                     . '/fixtures/event_umlaut_broken.xml');
index 79346dd..a60d4c9 100644 (file)
@@ -52,13 +52,4 @@ extends PHPUnit_Framework_TestCase
         $factory = new Horde_Kolab_Format_Factory();
         $factory->create('UNKNOWN', 'contact');
     }
-
-    public function testCaching()
-    {
-        $factory = new Horde_Kolab_Format_Factory();
-        $this->assertSame(
-            $factory->create('XML', 'contact'),
-            $factory->create('XML', 'contact')
-        );
-    }
 }