From: Gunnar Wrobel Date: Mon, 13 Dec 2010 09:29:50 +0000 (+0100) Subject: Caching the parser is not a good idea. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=1f69f04529775bbf0e543e1782bc8a6d1903a477;p=horde.git Caching the parser is not a good idea. --- diff --git a/framework/Kolab_Format/lib/Horde/Kolab/Format/Factory.php b/framework/Kolab_Format/lib/Horde/Kolab/Format/Factory.php index f453ba56b..f1a625fdd 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format/Factory.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format/Factory.php @@ -29,13 +29,6 @@ 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]; } /** diff --git a/framework/Kolab_Format/test/Horde/Kolab/Format/Integration/EventTest.php b/framework/Kolab_Format/test/Horde/Kolab/Format/Integration/EventTest.php index fbb33abb5..82f2bd464 100644 --- a/framework/Kolab_Format/test/Horde/Kolab/Format/Integration/EventTest.php +++ b/framework/Kolab_Format/test/Horde/Kolab/Format/Integration/EventTest.php @@ -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'); diff --git a/framework/Kolab_Format/test/Horde/Kolab/Format/Unit/FactoryTest.php b/framework/Kolab_Format/test/Horde/Kolab/Format/Unit/FactoryTest.php index 79346dd20..a60d4c9fc 100644 --- a/framework/Kolab_Format/test/Horde/Kolab/Format/Unit/FactoryTest.php +++ b/framework/Kolab_Format/test/Horde/Kolab/Format/Unit/FactoryTest.php @@ -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') - ); - } }