Skip to content

Commit

Permalink
No need for this binder, call the factory directly. Standardize on us…
Browse files Browse the repository at this point in the history
…ing create() as the factory method.
  • Loading branch information
mrubinsk committed Jan 13, 2011
1 parent 960b3a2 commit 439e8bf
Show file tree
Hide file tree
Showing 28 changed files with 60 additions and 100 deletions.
2 changes: 1 addition & 1 deletion add.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/* A source has been selected, connect and set up the fields. */
if ($source) {
try {
$driver = $injector->getInstance('Turba_Driver')->getDriver($source);
$driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($source);
} catch (Turba_Exception $e) {
$notification->push($e, 'horde.error');
$driver = null;
Expand Down
2 changes: 1 addition & 1 deletion contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

/* Set the contact from the key requested. */
try {
$driver = $injector->getInstance('Turba_Driver')->getDriver($source);
$driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($source);
} catch (Turba_Exception $e) {
$notification->push($e, 'horde.error');
Horde::url($prefs->getValue('initial_page'), true)->redirect();
Expand Down
6 changes: 3 additions & 3 deletions data.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ function _getBareEmail($address, $allow_multi = false)
foreach ($sources as $source => $objectkeys) {
/* Create a Turba storage instance. */
try {
$driver = $injector->getInstance('Turba_Driver')->getDriver($source);
$driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($source);
} catch (Turba_Exception $e) {
$notification->push($e, 'horde.error');
$error = true;
Expand Down Expand Up @@ -335,7 +335,7 @@ function _getBareEmail($address, $allow_multi = false)
case Horde_Data::IMPORT_FILE:
$dest = Horde_Util::getFormData('dest');
try {
$driver = $injector->getInstance('Turba_Driver')->getDriver($dest);
$driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($dest);
} catch (Turba_Exception $e) {
$notification->push($e, 'horde.error');
$error = true;
Expand Down Expand Up @@ -423,7 +423,7 @@ function _getBareEmail($address, $allow_multi = false)
/* Create a Turba storage instance. */
$dest = $session->get('horde', 'import_data/target');
try {
$driver = $injector->getInstance('Turba_Driver')->getDriver($dest);
$driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($dest);
} catch (Turba_Exception $e) {
$notification->push($e, 'horde.error');
$driver = null;
Expand Down
2 changes: 1 addition & 1 deletion delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

$source = Horde_Util::getFormData('source');
$key = Horde_Util::getFormData('key');
$driver = $injector->getInstance('Turba_Driver')->getDriver($source);
$driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($source);

if ($conf['documents']['type'] != 'none') {
try {
Expand Down
2 changes: 1 addition & 1 deletion deletefile.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
Horde::url($prefs->getValue('initial_page'), true)->redirect();
}

$driver = $injector->getInstance('Turba_Driver')->getDriver($source);
$driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($source);

try {
$contact = $driver->getObject(Horde_Util::getPost('key'));
Expand Down
2 changes: 1 addition & 1 deletion edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
$url->redirect();
}

$driver = $injector->getInstance('Turba_Driver')->getDriver($source);
$driver = $injector->getInstance('Turba_Injector_Factory_Driver')->create($source);

/* Set the contact from the requested key. */
try {
Expand Down
42 changes: 21 additions & 21 deletions lib/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function commentCallback($id)
@list($source, $key) = explode('.', $id, 2);
if (isset($GLOBALS['cfgSources'][$source]) && $key) {
try {
$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($source);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source);
$object = $driver->getObject($key)->getValue('name');
} catch (Turba_Exception $e) {}
}
Expand Down Expand Up @@ -322,7 +322,7 @@ public function browse($path = '', $properties = array())
}

// Load the Turba driver.
$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($parts[1]);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($parts[1]);

$contacts = $driver->search(array());

Expand Down Expand Up @@ -371,7 +371,7 @@ public function browse($path = '', $properties = array())
}

// Load the Turba driver.
$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($parts[1]);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($parts[1]);

$contact = $driver->getObject($parts[2]);

Expand Down Expand Up @@ -418,7 +418,7 @@ public function path_delete($path)
}

// Load the Turba driver.
$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($parts[1]);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($parts[1]);

return $driver->delete($parts[2]);
}
Expand Down Expand Up @@ -458,7 +458,7 @@ public function listUids($sources = null)
throw new Turba_Exception(sprintf(_("Invalid address book: %s"), $source));
}

$storage = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($source);
$storage = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source);

try {
$results = $storage->search(array());
Expand Down Expand Up @@ -518,7 +518,7 @@ public function listBy($action, $timestamp, $sources = null, $end = null)
throw new Turba_Exception(sprintf(_("Invalid address book: %s"), $source));
}

$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($source);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source);

$histories = $history->getByTimestamp(
'>', $timestamp, $filter,
Expand Down Expand Up @@ -589,7 +589,7 @@ public function getActionTimestamp($uid, $action, $sources = null)
throw new Turba_Exception(sprintf(_("Invalid address book: %s"), $source));
}

$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($source);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source);

$ts = $history->getActionTimestamp('turba:' . $driver->getName()
. ':' . $uid,
Expand Down Expand Up @@ -635,7 +635,7 @@ public function import($content, $contentType = 'array',
throw new Turba_Exception(sprintf(_("Invalid address book: %s"), $import_source));
}

$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($import_source);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($import_source);

if (!$driver->hasPermission(Horde_Perms::EDIT)) {
throw new Turba_Exception(_("Permission denied"));
Expand Down Expand Up @@ -763,7 +763,7 @@ public function export($uid, $contentType, $sources = null, $fields = null)
throw new Turba_Exception(_("Invalid ID"));
}

$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($source);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source);

if (!$driver->hasPermission(Horde_Perms::READ)) {
continue;
Expand Down Expand Up @@ -827,7 +827,7 @@ public function export($uid, $contentType, $sources = null, $fields = null)
public function ownVCard()
{
$contact = $this->getOwnContactObject();
$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($contact['source']);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($contact['source']);

$vcard = $driver->tovCard($contact['contact'], '3.0', null, true);
$vcard->setAttribute('VERSION', '3.0');
Expand Down Expand Up @@ -868,7 +868,7 @@ public function getOwnContactObject()
throw new Turba_Exception(_("The address book with your own contact doesn't exist anymore."));
}

$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($source);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source);

if (!$driver->hasPermission(Horde_Perms::READ)) {
throw new Turba_Exception(_("You don't have sufficient permissions to read the address book that contains your own contact."));
Expand Down Expand Up @@ -933,7 +933,7 @@ public function delete($uid, $sources = null)
throw new Turba_Exception(_("Invalid ID"));
}

$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($source);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source);

if (!$GLOBALS['registry']->isAdmin() &&
!$driver->hasPermission(Horde_Perms::DELETE)) {
Expand Down Expand Up @@ -996,7 +996,7 @@ public function replace($uid, $content, $contentType, $sources = null)
}

// Check permissions.
$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($source);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source);
if (!$driver->hasPermission(Horde_Perms::EDIT)) {
continue;
}
Expand Down Expand Up @@ -1121,7 +1121,7 @@ public function search($names = array(), $sources = array(),
continue;
}

$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($source);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source);

// Determine the name of the column to sort by.
$columns = isset($sort_columns[$source])
Expand Down Expand Up @@ -1274,7 +1274,7 @@ public function getContact($source = null, $objectId = '')
}

if (isset($cfgSources[$source])) {
$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($source);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source);

$object = $driver->getObject($objectId);

Expand Down Expand Up @@ -1310,7 +1310,7 @@ public function getContacts($source = '', $objectIds = array())
}

if (isset($cfgSources[$source])) {
$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($source);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source);

$objects = $driver->getObjects($objectIds);

Expand Down Expand Up @@ -1351,7 +1351,7 @@ public function getAllAttributeValues($field = '', $sources = array())
$results = array();
foreach ($sources as $source) {
if (isset($cfgSources[$source])) {
$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($source);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source);

$res = $driver->search(array());
if (!($res instanceof Turba_List)) {
Expand Down Expand Up @@ -1419,7 +1419,7 @@ public function listTimeObjects($time_categories, $start, $end)
$objects = array();
foreach ($time_categories as $category) {
list($category, $source) = explode('/', $category, 2);
$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($source);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source);
$objects = array_merge($objects, $driver->listTimeObjects($start, $end, $category));
}

Expand Down Expand Up @@ -1563,7 +1563,7 @@ public function addField($address = '', $name = '', $field = '',
throw new Turba_Exception(_("Invalid entry"));
}

$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($source);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source);

if (!$driver->hasPermission(Horde_Perms::EDIT)) {
throw new Turba_Exception(_("Permission denied"));
Expand Down Expand Up @@ -1654,7 +1654,7 @@ public function getField($address = '', $field = '', $sources = array(),
continue;
}

$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($source);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source);
$criterium = array('email' => $address);
if (!isset($driver->map['email'])) {
if (isset($driver->map['emails'])) {
Expand Down Expand Up @@ -1719,7 +1719,7 @@ public function deleteField($address = '', $field = '', $sources = array())

foreach ($sources as $source) {
if (isset($cfgSources[$source])) {
$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($source);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source);
if (!$driver->hasPermission(Horde_Perms::EDIT)) {
continue;
}
Expand Down
13 changes: 2 additions & 11 deletions lib/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,6 @@ class Turba_Application extends Horde_Registry_Application
*/
protected function _init()
{
/* Add Turba-specific binders. */
$binders = array(
'Turba_Driver' => new Turba_Injector_Binder_Driver()
);

foreach ($binders as $key => $val) {
$GLOBALS['injector']->addBinder($key, $val);
}

// Turba source and attribute configuration.
$attributes = Horde::loadConfiguration('attributes.php', 'attributes', 'turba');
include TURBA_BASE . '/config/backends.php';
Expand Down Expand Up @@ -399,7 +390,7 @@ public function removeUserData($user)
if (empty($source['use_shares'])) {
// Shares not enabled for this source
try {
$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($source);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source);
} catch (Turba_Exception $e) {
Horde::logMessage($e, 'ERR');
throw new Turba_Exception(sprintf(_("There was an error removing an address book for %s"), $user));
Expand Down Expand Up @@ -432,7 +423,7 @@ public function removeUserData($user)
if (!empty($params['default'])) {
$config = Turba::getSourceFromShare($share);
try {
$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($config);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($config);
} catch (Turba_Exception $e) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Driver/Vbook.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function _init()
$this->_share = $this->_params['share'];

/* Load the underlying driver. */
$this->_driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($this->_params['source']);
$this->_driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($this->_params['source']);

$this->searchCriteria = empty($this->_params['criteria'])
? array()
Expand Down
2 changes: 1 addition & 1 deletion lib/Form/CreateAddressBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function execute()
// Need a clean cfgSources array
include TURBA_BASE . '/config/backends.php';

$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($cfgSources[$GLOBALS['conf']['shares']['source']]);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($cfgSources[$GLOBALS['conf']['shares']['source']]);

$params = array(
'params' => array('source' => $GLOBALS['conf']['shares']['source']),
Expand Down
2 changes: 1 addition & 1 deletion lib/Form/DeleteAddressBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function execute()
throw new Turba_Exception(_("You do not have permissions to delete this address book."));
}

$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($this->_addressbook->getName());
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($this->_addressbook->getName());

// We have a Turba_Driver, try to delete the address book.
$driver->deleteAll();
Expand Down
31 changes: 0 additions & 31 deletions lib/Injector/Binder/Driver.php

This file was deleted.

2 changes: 1 addition & 1 deletion lib/Injector/Factory/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct(Horde_Injector $injector)
* @return Turba_Driver The singleton instance.
* @throws Turba_Exception
*/
public function getDriver($name)
public function create($name)
{
if (is_array($name)) {
$key = md5(serialize($name));
Expand Down
2 changes: 1 addition & 1 deletion lib/List.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct($ids = array())
foreach ($ids as $value) {
list($source, $key) = explode(':', $value);
try {
$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($source);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source);
$this->insert($driver->getObject($key));
} catch (Turba_Exception $e) {}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/LoginTasks/SystemTask/UpgradeLists.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function execute()
$sources = array_keys($GLOBALS['cfgSources']);
foreach ($sources as $sourcekey) {
try {
$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($sourcekey);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($sourcekey);
$lists = $driver->search($criteria);
} catch (Turba_Exception $e) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions lib/Object/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function addMember($contactId, $sourceId = null)
if ($sourceId == $this->getSource()) {
$contact = $this->driver->getObject($contactId);
} else {
$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($sourceId);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($sourceId);
$contact = $driver->getObject($contactId);
}

Expand Down Expand Up @@ -170,7 +170,7 @@ function &listMembers($sort = null)
}

try {
$driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($sourceId);
$driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($sourceId);
} catch (Turba_Exception $e) {
continue;
}
Expand Down
Loading

0 comments on commit 439e8bf

Please sign in to comment.