*/
public function getList()
{
- return new Horde_Kolab_Storage_List_Base(
+ $list = new Horde_Kolab_Storage_List_Base(
$this->_master,
$this->_factory
);
+ $this->_factory->createListQuery('Base', $list);
+ return $list;
}
/**
private $_cache;
/**
+ * The factory for generating additional resources.
+ *
+ * @var Horde_Kolab_Storage_Factory
+ */
+ private $_factory;
+
+ /**
* Constructor.
*
* @param Horde_Kolab_Storage $storage The storage handler.
* @param Horde_Kolab_Storage_Cache $cache The cache.
+ * @param Horde_Kolab_Storage_Factory $factory The factory.
*/
public function __construct(
Horde_Kolab_Storage $storage,
- Horde_Kolab_Storage_Cache $cache
+ Horde_Kolab_Storage_Cache $cache,
+ Horde_Kolab_Storage_Factory $factory
) {
$this->_storage = $storage;
$this->_cache = $cache;
+ $this->_factory = $factory;
}
/**
*/
public function getList()
{
- return new Horde_Kolab_Storage_List_Decorator_Cache(
+ $list_cache = new Horde_Kolab_Storage_Cache_List(
+ $this->_cache
+ );
+ $list = new Horde_Kolab_Storage_List_Decorator_Cache(
$this->_storage->getList(),
- new Horde_Kolab_Storage_Cache_List(
- $this->_cache
- )
+ $list_cache
+ );
+ $this->_factory->createListQuery(
+ 'Cache', $list, array('cache' => $list_cache)
);
+ return $list;
}
/**
/**
* Create the specified list query type.
*
- * @param string $name The query name.
- * @param Horde_Kolab_Storage_List $list The list that should be queried.
+ * @param string $name The query name.
+ * @param Horde_Kolab_Storage_List $list The list that should be queried.
+ * @param array $params Additional parameters provided
+ * to the query constructor.
*
* @return Horde_Kolab_Storage_Query A query handler.
*
* @throws Horde_Kolab_Storage_Exception In case the requested query is not supported.
*/
- public function createListQuery($name, Horde_Kolab_Storage_List $list)
+ public function createListQuery($name, Horde_Kolab_Storage_List $list, $params = array())
{
if (class_exists($name)) {
- $query = new $name($list);
+ $constructor_params = array_merge(
+ array('factory' => $this), $params
+ );
+ $query = new $name($list, $constructor_params);
} else if (strpos($name, 'Horde_Kolab_Storage_List_Query_') === false) {
$query = $this->createListQuery(
- 'Horde_Kolab_Storage_List_Query_' . $name, $list
+ 'Horde_Kolab_Storage_List_Query_' . $name, $list, $params
);
} else {
throw new Horde_Kolab_Storage_Exception(sprintf('No such query "%s"!', $name));
}
- if (method_exists($query, 'setFactory')) {
- $query->setFactory($this);
- }
- $list->registerQuery($query);
+ $list->registerQuery($name, $query);
return $query;
}
*/
public function synchronize()
{
- foreach ($this->_queries as $query) {
+ foreach ($this->_queries as $name => $query) {
$query->synchronize();
}
}
/**
* Register a query to be updated if the underlying data changes.
*
+ * @param string $name The query name.
* @param Horde_Kolab_Storage_Query $query The query to register.
*
* @return NULL
*/
- public function registerQuery(Horde_Kolab_Storage_Query $query)
+ public function registerQuery($name, Horde_Kolab_Storage_Query $query)
{
- $this->_queries[] = $query;
+ $this->_queries[$name] = $query;
+ }
+
+ /**
+ * Return a registered query.
+ *
+ * @param string $name The query name.
+ *
+ * @return NULL
+ */
+ public function getQuery($name)
+ {
+ if (isset($this->_queries[$name])) {
+ return $this->_queries[$name];
+ } else {
+ throw new Horde_Kolab_Storage_Exception('No such query!');
+ }
}
}
\ No newline at end of file
/**
* Register a query to be updated if the underlying data changes.
*
+ * @param string $name The query name.
* @param Horde_Kolab_Storage_Query $query The query to register.
*
* @return NULL
*/
- public function registerQuery(Horde_Kolab_Storage_Query $query)
+ public function registerQuery($name, Horde_Kolab_Storage_Query $query)
{
- $this->_list->registerQuery($query);
+ $this->_list->registerQuery($name, $query);
+ }
+
+ /**
+ * Return a registered query.
+ *
+ * @param string $name The query name.
+ *
+ * @return NULL
+ */
+ public function getQuery($name)
+ {
+ $this->_list->getQuery($name);
}
}
\ No newline at end of file
/**
* Register a query to be updated if the underlying data changes.
*
+ * @param string $name The query name.
* @param Horde_Kolab_Storage_Query $query The query to register.
*
* @return NULL
*/
- public function registerQuery(Horde_Kolab_Storage_Query $query)
+ public function registerQuery($name, Horde_Kolab_Storage_Query $query)
{
- $this->_list->registerQuery($query);
+ $this->_list->registerQuery($name, $query);
+ }
+
+ /**
+ * Return a registered query.
+ *
+ * @param string $name The query name.
+ *
+ * @return NULL
+ */
+ public function getQuery($name)
+ {
+ $this->_list->getQuery($name);
}
}
\ No newline at end of file
/**
* Constructor.
*
- * @param Horde_Kolab_Storage_List $list The queriable list.
+ * @param Horde_Kolab_Storage_List $list The queriable list.
+ * @param array $params Additional parameters.
*/
- public function __construct(Horde_Kolab_Storage_List $list)
- {
+ public function __construct(
+ Horde_Kolab_Storage_List $list,
+ $params
+ ) {
$this->_list = $list;
- }
-
- /**
- * Inject the factory.
- *
- * @param Horde_Kolab_Storage_Factory $factory The factory.
- *
- * @return NULL
- */
- public function setFactory(Horde_Kolab_Storage_Factory $factory)
- {
- $this->_factory = $factory;
+ $this->_factory = $params['factory'];
}
/**
/**
* Constructor.
*
- * @param Horde_Kolab_Storage_List $list The queriable list.
- * @param Horde_Kolab_Storage_Factory $factory The factory.
- * @param Horde_Kolab_Storage_Cache_List $list_cache The list cache.
+ * @param Horde_Kolab_Storage_List $list The queriable list.
+ * @param array $params Additional parameters.
*/
public function __construct(
Horde_Kolab_Storage_List $list,
- Horde_Kolab_Storage_Factory $factory,
- Horde_Kolab_Storage_Cache_List $list_cache
+ $params
) {
$this->_list = $list;
- $this->_list_cache = $list_cache;
- $this->_factory = $factory;
+ $this->_list_cache = $params['cache'];
+ $this->_factory = $params['factory'];
}
/**
/**
* Register a query to be updated if the underlying data changes.
*
+ * @param string $name The query name.
* @param Horde_Kolab_Storage_Query $query The query to register.
*
* @return NULL
*/
- public function registerQuery(Horde_Kolab_Storage_Query $query);
+ public function registerQuery($name, Horde_Kolab_Storage_Query $query);
+
+ /**
+ * Return a registered query.
+ *
+ * @param string $name The query name.
+ *
+ * @return NULL
+ */
+ public function getQuery($name);
}
}
/**
- * Inject the factory.
- *
- * @param Horde_Kolab_Storage_Factory $factory The factory.
- *
- * @return NULL
- */
- public function setFactory(Horde_Kolab_Storage_Factory $factory)
- {
- $this->called = true;
- }
-
- /**
* Synchronize the query data with the information from the backend.
*
* @return NULL
);
$query = new Horde_Kolab_Storage_List_Query_Cache(
$list,
- $factory,
- $list_cache
+ array(
+ 'factory' => $factory,
+ 'cache' => $list_cache
+ )
);
- $list->registerQuery($query);
+ $list->registerQuery('test', $query);
$list->synchronize();
return $query;
}
{
public function testDecoratedList()
{
+ $factory = new Horde_Kolab_Storage_Factory();
$storage = new Horde_Kolab_Storage_Decorator_Cache(
new Horde_Kolab_Storage_Base(
- $this->getNullMock(),
- new Horde_Kolab_Storage_Factory()
+ $this->getNullMock($factory),
+ $factory
),
- new Horde_Kolab_Storage_Cache(null)
+ new Horde_Kolab_Storage_Cache(null),
+ $factory
);
$this->assertInstanceOf(
'Horde_Kolab_Storage_List_Decorator_Cache',
)
);
}
-
- public function testQueryFactoryInjection()
- {
- $list = new Horde_Kolab_Storage_List_Base(
- $this->getNullMock(),
- new Horde_Kolab_Storage_Factory()
- );
- $factory = new Horde_Kolab_Storage_Factory();
- $query = $factory->createListQuery(
- 'Horde_Kolab_Storage_Stub_FactoryQuery',
- $list
- );
- $this->assertTrue($query->called);
- }
-
}
'Horde_Kolab_Storage_Stub_FactoryQuery',
$list
);
- $list->registerQuery($query);
+ $list->registerQuery('stub', $query);
$list->synchronize();
$this->assertTrue($query->synchronized);
}
+
+ public function testGetQuery()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $list = new Horde_Kolab_Storage_List_Base(
+ $this->getNullMock(),
+ $factory
+ );
+ $query = $factory->createListQuery(
+ 'Horde_Kolab_Storage_Stub_FactoryQuery',
+ $list
+ );
+ $this->assertInstanceOf(
+ 'Horde_Kolab_Storage_Stub_FactoryQuery',
+ $list->getQuery('Horde_Kolab_Storage_Stub_FactoryQuery')
+ );
+ }
}