*/
/**
- * The Horde_Kolab_Format:: class provides the means to read/write the
- * Kolab format.
+ * The Horde_Kolab_Format:: interface defines the basic properties of a Kolab
+ * format handler.
*
* Copyright 2007-2010 Klarälvdalens Datakonsult AB
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you did not
* receive this file, see
* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @link http://pear.horde.org/index.php?package=Kolab_Format
*/
-abstract class Horde_Kolab_Format
+interface Horde_Kolab_Format
{
/**
- * Attempts to return a concrete Horde_Kolab_Format instance based on
- * $format_type.
- *
- * @param string $format_type The format type that should be handled.
- * @param string $object_type The object type that should be handled.
- * @param array $params An array of additional parameters.
- *
- * Supported parameters:
- *
- * 'version' - The format version.
- *
- * @return mixed The newly created concrete Horde_Kolab_Format_XML instance
- *
- * @throws Horde_Kolab_Format_Exception If the specified driver could not be loaded.
- */
- static public function factory($format_type = '', $object_type = '',
- $params = null)
- {
- $class = 'Horde_Kolab_Format_' . ucfirst(strtolower($format_type));
- if (class_exists($class)) {
- $driver = call_user_func(
- array($class, 'factory'), $object_type, $params
- );
- } else {
- throw new Horde_Kolab_Format_Exception(
- sprintf('Failed to load Kolab Format driver %s',
- $format_type)
- );
- }
-
- return $driver;
- }
-
- /**
* Return the name of the resulting document.
*
* @return string The name that may be used as filename.
*/
- abstract public function getName();
+ public function getName();
/**
* Return the mime type of the resulting document.
*
* @return string The mime type of the result.
*/
- abstract public function getMimeType();
+ public function getMimeType();
/**
* Return the disposition of the resulting document.
*
* @return string The disportion of this document.
*/
- abstract public function getDisposition();
+ public function getDisposition();
/**
* Load an object based on the given XML string.
*
* @throws Horde_Kolab_Format_Exception
*/
- abstract public function load(&$xmltext);
+ public function load(&$xmltext);
/**
* Convert the data to a XML string.
*
* @throws Horde_Kolab_Format_Exception
*/
- abstract public function save($object);
+ public function save($object);
}
--- /dev/null
+<?php
+/**
+ * A factory for generating Kolab format handlers.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package Kolab_Format
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Format
+ */
+
+/**
+ * A factory for generating Kolab format handlers.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you did not
+ * receive this file, see
+ * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+ *
+ * @category Kolab
+ * @package Kolab_Format
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Format
+ */
+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.
+ * @param string $object The object type that should be handled.
+ * @param array $params Additional parameters.
+ * <pre>
+ * 'version' - The format version.
+ * </pre>
+ *
+ * @return Horde_Kolab_Format The handler.
+ *
+ * @throws Horde_Kolab_Format_Exception If the specified handler does not
+ * exist.
+ */
+ public function create($format_type = '', $object_type = '', $params = null)
+ {
+ $class = 'Horde_Kolab_Format_' . ucfirst(strtolower($format_type)) . '_'
+ . ucfirst(strtolower(str_replace('-', '', $object_type)));
+
+ if (!isset($this->_instances[$class])) {
+ if (class_exists($class)) {
+ $this->_instances[$class] = new $class($params);
+ } 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];
+ }
+}
* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @link http://pear.horde.org/index.php?package=Kolab_Server
*/
-class Horde_Kolab_Format_Xml
+class Horde_Kolab_Format_Xml implements Horde_Kolab_Format
{
/**
<email>jan@horde.org</email>
<active>yes</active>
</lead>
- <date>2010-10-22</date>
- <time>19:03:01</time>
+ <date>2010-12-09</date>
+ <time>08:47:27</time>
<version>
<release>1.1.0</release>
<api>1.1.0</api>
</dir> <!-- /lib/Horde/Kolab/Format/Xml -->
<file name="Date.php" role="php" />
<file name="Exception.php" role="php" />
+ <file name="Factory.php" role="php" />
<file name="Translation.php" role="php">
<tasks:replace from="@data_dir@" to="data_dir" type="pear-config" />
</file>
<file name="TaskTest.php" role="test" />
<file name="XmlTest.php" role="test" />
</dir> <!-- /test/Horde/Kolab/Format/Integration -->
+ <dir name="Unit">
+ <dir name="Decorator">
+ <file name="TimedTest.php" role="test" />
+ </dir> <!-- /test/Horde/Kolab/Format/Unit/Decorator -->
+ <file name="FactoryTest.php" role="test" />
+ </dir> <!-- /test/Horde/Kolab/Format/Unit -->
<file name="AllTests.php" role="test" />
<file name="Autoload.php" role="test" />
<file name="phpunit.xml" role="test" />
+ <file name="TestCase.php" role="test" />
</dir> <!-- /test/Horde/Kolab/Format -->
</dir> <!-- /test/Horde/Kolab -->
</dir> <!-- /test/Horde -->
<phprelease>
<filelist>
<install as="Horde/Kolab/Format/usage.txt" name="doc/Horde/Kolab/Format/usage.txt" />
+ <install as="Horde/Kolab/Format/event.php" name="examples/Horde/Kolab/Format/event.php" />
+ <install as="Horde/Kolab/Format/new_type.php" name="examples/Horde/Kolab/Format/new_type.php" />
<install as="Horde/Kolab/Format.php" name="lib/Horde/Kolab/Format.php" />
<install as="Horde/Kolab/Format/Date.php" name="lib/Horde/Kolab/Format/Date.php" />
<install as="Horde/Kolab/Format/Exception.php" name="lib/Horde/Kolab/Format/Exception.php" />
+ <install as="Horde/Kolab/Format/Factory.php" name="lib/Horde/Kolab/Format/Factory.php" />
<install as="Horde/Kolab/Format/Translation.php" name="lib/Horde/Kolab/Format/Translation.php" />
<install as="Horde/Kolab/Format/Xml.php" name="lib/Horde/Kolab/Format/Xml.php" />
<install as="Horde/Kolab/Format/Xml/Annotation.php" name="lib/Horde/Kolab/Format/Xml/Annotation.php" />
<install as="Horde/Kolab/Format/AllTests.php" name="test/Horde/Kolab/Format/AllTests.php" />
<install as="Horde/Kolab/Format/Autoload.php" name="test/Horde/Kolab/Format/Autoload.php" />
<install as="Horde/Kolab/Format/phpunit.xml" name="test/Horde/Kolab/Format/phpunit.xml" />
+ <install as="Horde/Kolab/Format/TestCase.php" name="test/Horde/Kolab/Format/TestCase.php" />
<install as="Horde/Kolab/Format/fixtures/task.xml" name="test/Horde/Kolab/Format/fixtures/task.xml" />
<install as="Horde/Kolab/Format/Integration/ContactTest.php" name="test/Horde/Kolab/Format/Integration/ContactTest.php" />
<install as="Horde/Kolab/Format/Integration/EventTest.php" name="test/Horde/Kolab/Format/Integration/EventTest.php" />
<install as="Horde/Kolab/Format/Integration/fixtures/preferences_write_old.xml" name="test/Horde/Kolab/Format/Integration/fixtures/preferences_write_old.xml" />
<install as="Horde/Kolab/Format/Integration/fixtures/recur.xml" name="test/Horde/Kolab/Format/Integration/fixtures/recur.xml" />
<install as="Horde/Kolab/Format/Integration/fixtures/recur_fail.xml" name="test/Horde/Kolab/Format/Integration/fixtures/recur_fail.xml" />
+ <install as="Horde/Kolab/Format/Unit/FactoryTest.php" name="test/Horde/Kolab/Format/Unit/FactoryTest.php" />
+ <install as="Horde/Kolab/Format/Unit/Decorator/TimedTest.php" name="test/Horde/Kolab/Format/Unit/Decorator/TimedTest.php" />
+ <install as="COPYING" name="COPYING" />
+ <install as="TODO" name="TODO" />
</filelist>
</phprelease>
<changelog>
<release>stable</release>
<api>stable</api>
</stability>
- <date>2010-10-22</date>
+ <date>2010-12-09</date>
<license uri="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html">LGPL</license>
<notes>
* Removed dependency on the Kolab package within the task handler.
error_reporting(E_ALL | E_STRICT);
/** Load the basic test definition */
-//require_once dirname(__FILE__) . '/TestCase.php';
+require_once dirname(__FILE__) . '/TestCase.php';
* @link http://pear.horde.org/index.php?package=Kolab_Format
*/
class Horde_Kolab_Format_Integration_EventTest
-extends PHPUnit_Framework_TestCase
+extends Horde_Kolab_Format_TestCase
{
/**
* Test for https://www.intevation.de/roundup/kolab/issue3525
*/
public function testIssue3525()
{
- $xml = Horde_Kolab_Format::factory('XML', 'event');
+ $xml = $this->factory('XML', 'event');
// Load XML
$event = file_get_contents(dirname(__FILE__)
* @link http://pear.horde.org/index.php?package=Kolab_Format
*/
class Horde_Kolab_Format_Integration_MimeAttrTest
-extends PHPUnit_Framework_TestCase
+extends Horde_Kolab_Format_TestCase
{
/**
* Test retrieving the document name.
*/
public function testGetName()
{
- $format = Horde_Kolab_Format::factory('XML', 'contact');
+ $format = $this->factory('XML', 'contact');
$this->assertEquals('kolab.xml', $format->getName());
}
*/
public function testMimeType()
{
- $format = Horde_Kolab_Format::factory('XML', 'contact');
+ $format = $this->factory('XML', 'contact');
$this->assertEquals('application/x-vnd.kolab.contact',
$format->getMimeType());
}
*/
public function testGetDisposition()
{
- $format = Horde_Kolab_Format::factory('XML', 'contact');
+ $format = $this->factory('XML', 'contact');
$this->assertEquals('attachment', $format->getDisposition());
}
}
* @link http://pear.horde.org/index.php?package=Kolab_Format
*/
class Horde_Kolab_Format_Integration_RecurrenceTest
-extends PHPUnit_Framework_TestCase
+extends Horde_Kolab_Format_TestCase
{
/**
*/
protected function setUp()
{
- @include_once 'Horde/Date/Recurrence.php';
-
if (!class_exists('Horde_Date_Recurrence')) {
$this->markTestSkipped('The Horde_Date_Recurrence class is missing.');
}
*/
public function testBug6388()
{
- $xml = Horde_Kolab_Format::factory('XML', 'event');
+ $xml = $this->factory('XML', 'event');
// Load XML
$recur = file_get_contents(dirname(__FILE__) . '/fixtures/recur.xml');
// Load XML
- $xml = &Horde_Kolab_Format::factory('XML', 'event');
+ $xml = $this->factory('XML', 'event');
$recur = file_get_contents(dirname(__FILE__) . '/fixtures/recur_fail.xml');
// Check that the xml fails because of a missing interval value
*/
public function testExceptions()
{
- $xml = Horde_Kolab_Format::factory('XML', 'event');
+ $xml = $this->factory('XML', 'event');
// Load XML
$recur = file_get_contents(dirname(__FILE__) . '/fixtures/recur.xml');
*/
public function testCompletions()
{
- $xml = Horde_Kolab_Format::factory('XML', 'event');
+ $xml = $this->factory('XML', 'event');
$r = new Horde_Date_Recurrence(0);
$r->setRecurType(Horde_Date_Recurrence::RECUR_DAILY);
* @link http://pear.horde.org/index.php?package=Kolab_Format
*/
class Horde_Kolab_Format_Integration_TaskTest
-extends PHPUnit_Framework_TestCase
+extends Horde_Kolab_Format_TestCase
{
/**
*/
public function testBasicTask()
{
- $xml = Horde_Kolab_Format::factory('XML', 'task');
+ $xml = $this->factory('XML', 'task');
// Load XML
$task = file_get_contents(dirname(__FILE__) . '/../fixtures/task.xml');
--- /dev/null
+<?php
+/**
+ * Basic test case.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package Kolab_Format
+ * @subpackage UnitTests
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Format
+ */
+
+/**
+ * Basic test case.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package Kolab_Format
+ * @subpackage UnitTests
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Format
+ */
+class Horde_Kolab_Format_TestCase
+extends PHPUnit_Framework_TestCase
+{
+ public function factory(
+ $format_type = '', $object_type = '', $params = null
+ ) {
+ $factory = new Horde_Kolab_Format_Factory();
+ return $factory->create($format_type, $object_type, $params);
+ }
+}
--- /dev/null
+<?php
+/**
+ * Test the factory.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package Kolab_Format
+ * @subpackage UnitTests
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Format
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../Autoload.php';
+
+/**
+ * Test the factory.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package Kolab_Format
+ * @subpackage UnitTests
+ * @author Gunnar Wrobel <wrobel@pardus.de>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Kolab_Format
+ */
+class Horde_Kolab_Format_Unit_FactoryTest
+extends PHPUnit_Framework_TestCase
+{
+ public function testFactory()
+ {
+ $factory = new Horde_Kolab_Format_Factory();
+ $this->assertInstanceOf(
+ 'Horde_Kolab_Format_Xml_Contact',
+ $factory->create('XML', 'contact')
+ );
+ }
+
+ /**
+ * @expectedException Horde_Kolab_Format_Exception
+ */
+ public function testFactoryException()
+ {
+ $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')
+ );
+ }
+}
+++ /dev/null
-<?php
-/**
- * Test the format entry point.
- *
- * PHP version 5
- *
- * @category Kolab
- * @package Kolab_Format
- * @subpackage UnitTests
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Kolab_Format
- */
-
-/**
- * Prepare the test setup.
- */
-require_once dirname(__FILE__) . '/../Autoload.php';
-
-/**
- * Test the format entry point.
- *
- * Copyright 2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Kolab
- * @package Kolab_Format
- * @subpackage UnitTests
- * @author Gunnar Wrobel <wrobel@pardus.de>
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Kolab_Format
- */
-class Horde_Kolab_Format_Unit_FormatTest
-extends PHPUnit_Framework_TestCase
-{
- public function testFactory()
- {
- $this->assertInstanceOf(
- 'Horde_Kolab_Format_Xml_Contact',
- Horde_Kolab_Format::factory('XML', 'contact')
- );
- }
-
- /**
- * @expectedException Horde_Kolab_Format_Exception
- */
- public function testFactoryException()
- {
- Horde_Kolab_Format::factory('UNKNOWN', 'contact');
- }
-
-
-}