* @author Marko Djukic <marko@oblo.com>
*/
-require_once dirname(__FILE__) . '/lib/Application.php';
+require_once dirname(__FILE__) . '/../lib/Application.php';
$jonah = Horde_Registry::appInit('jonah');
require_once 'Horde/Form.php';
require_once 'Horde/Form/Renderer.php';
}
if (empty($criteria['channel_id']) && !empty($criteria['feed'])) {
- $criteria['channel_id'] = $jonah_driver->getChannelId($criteria['feed']);
+ $criteria['channel_id'] = $GLOBALS['injector']->getInstance('Jonah_Driver')->getChannelId($criteria['feed']);
}
if (empty($criteria['channel_id'])) {
$notification->push(_("No valid feed name or ID requested."), 'horde.error');
} else {
- $stories = $jonah_driver->getStories($criteria);
+ $stories = $GLOBALS['injector']->getInstance('Jonah_Driver')->getStories($criteria);
}
if (!empty($stories)) {
{
global $registry;
- $results = $GLOBALS['jonah_driver']->getStoryCount($channel_id);
+ $results = $GLOBALS['injector']->getInstance('Jonah_Driver')->getStoryCount($channel_id);
if (is_a($results, 'PEAR_Error')) {
return 0;
}
*/
protected function _init()
{
+ $GLOBALS['injector']->addBinder('Jonah_Driver', new Jonah_Injector_Binder_Driver());
+
$GLOBALS['jonah_driver'] = Jonah_Driver::factory();
}
--- /dev/null
+<?php
+/**
+ * Jonah_Driver binder.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file LICENSE for license information (BSD). If you did not
+ * did not receive this file, see http://cvs.horde.org/co.php/jonah/LICENSE.
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Jonah
+ */
+class Jonah_Injector_Binder_Driver Implements Horde_Injector_Binder
+{
+ public function create(Horde_Injector $injector)
+ {
+ $driver = $GLOBALS['conf']['news']['storage']['driver'];
+ $params = Horde::getDriverConfig(array('news', 'storage'), $driver);
+
+ $factory = new Jonah_Injector_Factory_Driver();
+ return $factory->getDriver($driver, $params);
+ }
+
+ /**
+ */
+ public function equals(Horde_Injector_Binder $binder)
+ {
+ return false;
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * Jonah_Driver factory.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file LICENSE for license information (BSD). If you did not
+ * did not receive this file, see http://cvs.horde.org/co.php/jonah/LICENSE.
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @author Ben Klang <ben@alkaloid.net>
+ * @package Jonah
+ */
+class Jonah_Injector_Factory_Driver
+{
+ /**
+ * Instances.
+ *
+ * @var array
+ */
+ private $_instances = array();
+
+ /**
+ * The injector.
+ *
+ * @var Horde_Injector
+ */
+ private $_injector;
+
+ /**
+ * Constructor.
+ *
+ * @param Horde_Injector $injector The injector to use.
+ */
+ public function __construct(Horde_Injector $injector)
+ {
+ $this->_injector = $injector;
+ }
+
+ /**
+ * Return the driver instance.
+ *
+ * @param string $driver The concrete driver to return
+ * @param array $params An array of additional driver parameters.
+ *
+ * @return Jonah_Driver
+ * @throws Jonah_Exception
+ */
+ public function getDriver($driver, $params = array())
+ {
+ $driver = basename($driver);
+ $sig = md5(driver . serialize($params));
+ if (isset($this->_instances[$sig])) {
+ return $this->_instances[$sig];
+ }
+
+ $class = 'Jonah_Driver_' . $driver;
+ if (class_exists($class)) {
+ $object = new $class($params);
+ $this->_instances[$sig] = $object;
+ } else {
+ throw new Jonah_Exception(sprintf(_("No such backend \"%s\" found"), $driver));
+ }
+
+ return $this->_instances[$sig];
+ }
+
+}
\ No newline at end of file
* @author Jan Schneider <jan@horde.org>
* @package Jonah
*/
-class Jonah_News {
-
+class Jonah_News
+{
/**
* Hash containing connection parameters.
*
* @var array
*/
- var $_params = array();
+ protected $_params = array();
/**
* Constructs a new News storage object.
*
* @param array $params A hash containing connection parameters.
*/
- function Jonah_News($params = array())
+ public function __construct($params = array())
{
$this->_params = $params;
}