/** * Return the Agora_Driver:: instance. * * @param string $scope Instance scope * @param int $forum_id Forum to link to * * @return Agora_Driver The singleton instance. * @throws Agora_Exception */ public function create($scope = 'agora', $forum_id = 0) { if (!isset($this->_instances[$scope])) { $driver = $GLOBALS['conf']['threads']['split'] ? 'SplitSql' : 'Sql'; $params = Horde::getDriverConfig('sql'); $class = 'Agora_Driver_' . $driver; if (!class_exists($class)) { throw new Agora_Exception(sprintf('Unable to load the definition of %s.', $class)); } $params = array('db' => $this->_injector->getInstance('Horde_Db_Adapter'), 'charset' => $params['charset']); $driver = new $class($scope, $params); $this->_instances[$scope] = $driver; } if ($forum_id) { /* Check if there was a valid forum object to get. */ try { $forum = $this->_instances[$scope]->getForum($forum_id); } catch (Horde_Exception $e) { throw new Agora_Exception($e->getMessage()); } /* Set current forum id and forum data */ $this->_instances[$scope]->_forum = $forum; $this->_instances[$scope]->_forum_id = (int) $forum_id; } return $this->_instances[$scope]; }
/** * Return an Kolab_Driver instance. * * @return Kolab_Driver */ public function create(Horde_Injector $injector) { $driver = Horde_String::ucfirst($GLOBALS['conf']['storage']['driver']); $signature = serialize(array($driver, $GLOBALS['conf']['storage']['params']['driverconfig'])); if (empty($this->_instances[$signature])) { switch ($driver) { case 'Sql': try { if ($GLOBALS['conf']['storage']['params']['driverconfig'] == 'horde') { $db = $injector->getInstance('Horde_Db_Adapter'); } else { $db = $injector->getInstance('Horde_Core_Factory_Db')->create('kolab', 'storage'); } } catch (Horde_Exception $e) { throw new Kolab_Exception($e); } $params = array('db' => $db); break; case 'Ldap': try { $params = array('ldap' => $injector->getIntance('Horde_Core_Factory_Ldap')->create('kolab', 'storage')); } catch (Horde_Exception $e) { throw new Kolab_Exception($e); } break; } $class = 'Kolab_Driver_' . $driver; $this->_instances[$signature] = new $class($params); } return $this->_instances[$signature]; }
/** * Factory method * * @param string $driver The driver type, leave empty for client connection * @param array $params The driver parameters, leave empty to use default. * * @return mixed The Horde_Imsp object or Horde_Imsp_Client object. * @throws Horde_Exception */ protected function _factory($driver = null, array $params = array()) { $driver = basename($driver); // Use global config if none passed in. if (empty($params)) { $params = $GLOBALS['conf']['imsp']; } elseif (empty($params['auth_method'])) { $params['auth_method'] = $GLOBALS['conf']['imsp']['auth_method']; } $params['authObj'] = $this->_injector->getInstance('Horde_Core_Factory_ImspAuth')->create($params['auth_method'], $params); // @TODO: Separate class for the imtest client? unset($params['auth_method']); try { $socket = new Horde_Imsp_Client_Socket($params); } catch (Horde_Imsp_Exception $e) { throw new Horde_Exception($e); } // Return the client itself if no requested driver. if (empty($driver)) { return $socket; } if (!$socket->authenticate($params)) { throw new Horde_Exception_PermissionDenied(); } $class = $this->_getDriverName($driver, 'Horde_Imsp'); return new $class($socket, $params); }
/** * Return a Nag_Tasklists instance. * * @return Nag_Tasklists */ public function create() { if (!isset($GLOBALS['conf']['tasklists']['driver'])) { $driver = 'Default'; } else { $driver = Horde_String::ucfirst($GLOBALS['conf']['tasklists']['driver']); } if (empty($this->_instances[$driver])) { $class = 'Nag_Tasklists_' . $driver; if (class_exists($class)) { $params = array(); if (!empty($GLOBALS['conf']['share']['auto_create'])) { $params['auto_create'] = true; } switch ($driver) { case 'Default': $params['identity'] = $this->_injector->getInstance('Horde_Core_Factory_Identity')->create(); break; } $this->_instances[$driver] = new $class($GLOBALS['nag_shares'], $GLOBALS['registry']->getAuth(), $params); } else { throw new Nag_Exception(sprintf('Unable to load the definition of %s.', $class)); } } return $this->_instances[$driver]; }
public function create(Horde_Injector $injector) { $driver = Horde_String::ucfirst($GLOBALS['conf']['group']['driver']); $params = Horde::getDriverConfig('group', $driver); if (!empty($GLOBALS['conf']['group']['cache'])) { $params['cache'] = $injector->getInstance('Horde_Cache'); } switch ($driver) { case 'Contactlists': $class = 'Horde_Group_Contactlists'; $params['api'] = $GLOBALS['registry']->contacts; break; case 'Kolab': $class = 'Horde_Group_Kolab'; $params['ldap'] = $injector->getInstance('Horde_Core_Factory_Ldap')->create('horde', 'group'); break; case 'Ldap': $class = 'Horde_Core_Group_Ldap'; $params['ldap'] = $injector->getInstance('Horde_Core_Factory_Ldap')->create('horde', 'group'); break; case 'Sql': $class = 'Horde_Group_Sql'; $params['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'group'); break; default: $class = $this->_getDriverName($driver, 'Horde_Group'); break; } return new $class($params); }
/** * @throws Horde_Exception */ public function create(Horde_Injector $injector) { global $conf, $injector; if (empty($conf['weather']['provider'])) { throw new Horde_Exception(Horde_Core_Translation::t("Weather support not configured.")); } // Parameters for all driver types $params = array('cache' => $injector->getInstance('Horde_Cache'), 'cache_lifetime' => $conf['weather']['params']['lifetime'], 'http_client' => $injector->createInstance('Horde_Core_Factory_HttpClient')->create()); $driver = $conf['weather']['provider']; switch ($driver) { case 'WeatherUnderground': case 'Wwo': $params['apikey'] = $conf['weather']['params']['key']; break; case 'Google': $l = explode('_', $GLOBALS['language']); $params['language'] = $l[0]; break; } $class = $this->_getDriverName($driver, 'Horde_Service_Weather'); try { return new $class($params); } catch (InvalidArgumentException $e) { throw new Horde_Exception($e); } }
public function testMock() { $injector = new Horde_Injector(new Horde_Injector_TopLevel()); $injector->bindFactory('Horde_Group', 'Horde_Core_Factory_Group', 'create'); $GLOBALS['conf']['group']['driver'] = 'mock'; $this->assertInstanceOf('Horde_Group_Mock', $injector->getInstance('Horde_Group')); }
/** * @return Horde_Core_History * @throws Horde_Exception */ public function create(Horde_Injector $injector) { global $conf; // For BC, default to 'Sql' driver. $driver = empty($conf['history']['driver']) ? 'Sql' : $conf['history']['driver']; $history = null; $user = $injector->getInstance('Horde_Registry')->getAuth(); switch (Horde_String::lower($driver)) { case 'nosql': $nosql = $injector->getInstance('Horde_Core_Factory_Nosql')->create('horde', 'history'); if ($nosql instanceof Horde_History_Mongo) { $history = new Horde_History_Mongo($user, array('mongo_db' => $nosql)); } break; case 'sql': try { $history = new Horde_History_Sql($user, $injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'history')); } catch (Exception $e) { } break; } if (is_null($history)) { $history = new Horde_History_Null($user); } elseif ($cache = $injector->getInstance('Horde_Cache')) { $history->setCache($cache); $history = new Horde_Core_History($history); } return $history; }
/** * @throws Horde_Exception */ public function create(Horde_Injector $injector) { if (empty($GLOBALS['conf']['timezone']['location'])) { throw new Horde_Exception('Timezone database location is not configured'); } return new Horde_Timezone(array('cache' => $injector->getInstance('Horde_Cache'), 'location' => $GLOBALS['conf']['timezone']['location'], 'temp' => Horde::getTempDir())); }
/** * Return the Mnemo_Driver:: instance. * * @param mixed $name The notepad to open * * @return Mnemo_Driver * @throws Mnemo_Exception */ public function create($name = '') { if (!isset($this->_instances[$name])) { $driver = $GLOBALS['conf']['storage']['driver']; $params = Horde::getDriverConfig('storage', $driver); $class = 'Mnemo_Driver_' . ucfirst(basename($driver)); if (!class_exists($class)) { throw new Mnemo_Exception(sprintf('Unable to load the definition of %s.', $class)); } switch ($class) { case 'Mnemo_Driver_Sql': if ($params['driverconfig'] != 'horde') { $customParams = $params; unset($customParams['driverconfig'], $customParams['table']); $params['db'] = $this->_injector->getInstance('Horde_Core_Factory_Db')->create('mnemo', $customParams); } else { $params['db'] = $this->_injector->getInstance('Horde_Db_Adapter'); } break; case 'Mnemo_Driver_Kolab': $params = array('storage' => $this->_injector->getInstance('Horde_Kolab_Storage')); } $driver = new $class($name, $params); $this->_instances[$name] = $driver; } return $this->_instances[$name]; }
public function create(Horde_Injector $injector) { global $conf, $session; $driver = empty($conf['token']) ? 'null' : $conf['token']['driver']; $params = empty($conf['token']) ? array() : Horde::getDriverConfig('token', $conf['token']['driver']); $params['logger'] = $injector->getInstance('Horde_Log_Logger'); if (!$session->exists('horde', 'token_secret_key')) { $session->set('horde', 'token_secret_key', strval(new Horde_Support_Randomid())); } $params['secret'] = $session->get('horde', 'token_secret_key'); switch (Horde_String::lower($driver)) { case 'none': $driver = 'null'; break; case 'nosql': $nosql = $injector->getInstance('Horde_Core_Factory_Nosql')->create('horde', 'token'); if ($nosql instanceof Horde_Mongo_Client) { $params['mongo_db'] = $nosql; $driver = 'Horde_Token_Mongo'; } break; case 'sql': $params['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'token'); break; } if (isset($conf['urls']['token_lifetime'])) { $params['token_lifetime'] = $conf['urls']['token_lifetime'] * 60; } $class = $this->_getDriverName($driver, 'Horde_Token'); return new $class($params); }
public function create(Horde_Injector $injector) { $registry = $injector->getInstance('Horde_Registry'); $view = new Horde_View(array('templatePath' => $registry->get('templates', $registry->getApp()))); $view->addHelper('Tag'); $view->addHelper('Text'); return $view; }
/** * @param Horde_Injector $injector * @param ReflectionParameter $method * * @return mixed * @throws Horde_Injector_Exception */ public function getParameterDependency(Horde_Injector $injector, ReflectionParameter $parameter) { if ($parameter->getClass()) { return $injector->getInstance($parameter->getClass()->getName()); } elseif ($parameter->isOptional()) { return $parameter->getDefaultValue(); } throw new Horde_Injector_Exception("Untyped parameter \$" . $parameter->getName() . "can't be fulfilled"); }
/** * Return the driver instance. * * @return Kronolith_Storage * @throws Kronolith_Exception */ public function create(Horde_Injector $injector) { if (empty($GLOBALS['conf']['maps']['geodriver'])) { throw new Kronolith_Exception('Geospatial support not configured.'); } $class = 'Kronolith_Geo_' . $GLOBALS['conf']['maps']['geodriver']; $db = $injector->getInstance('Horde_Db_Adapter'); return new $class($db); }
/** * Return an Ansel_Storage instance scoped for the current Ansel scope. * Scope is determined by the current value of Ansel_Config::scope * * @return Ansel_Storage */ public function create(Horde_Injector $injector) { $scope = $injector->getInstance('Ansel_Config')->get('scope'); if (empty($this->_instances[$scope])) { $this->_instances[$scope] = new Ansel_Storage($injector->getInstance('Horde_Core_Factory_Share')->create($scope)); $this->_instances[$scope]->setStorage($injector->getInstance('Horde_Db_Adapter')); } return $this->_instances[$scope]; }
/** * Return the IMP_Crypt_Pgp instance. * * @return IMP_Crypt_Pgp The singleton instance. */ public function create(Horde_Injector $injector) { $params = array('program' => $GLOBALS['conf']['gnupg']['path']); if (isset($GLOBALS['conf']['http']['proxy']['proxy_host'])) { $params['proxy_host'] = $GLOBALS['conf']['http']['proxy']['proxy_host']; if (isset($GLOBALS['conf']['http']['proxy']['proxy_port'])) { $params['proxy_port'] = $GLOBALS['conf']['http']['proxy']['proxy_port']; } } return $injector->getInstance('Horde_Core_Factory_Crypt')->create('IMP_Crypt_Pgp', $params); }
/** * Returns a Horde_Db instance for the SQL backend. * * @param Horde_Injector $injector An injector object. * * @return Horde_Db_Adapter A correctly configured Horde_Db_Adapter * instance. * @throws Wicked_Exception */ public function getDb(Horde_Injector $injector) { try { if ($GLOBALS['conf']['storage']['params']['driverconfig'] == 'horde') { return $injector->getInstance('Horde_Db_Adapter'); } return $injector->getInstance('Horde_Core_Factory_Db')->create('wicked', 'storage'); } catch (Horde_Exception $e) { throw new Wicked_Exception($e); } }
private function _getFactory() { $GLOBALS['conf']['kolab']['server']['basedn'] = 'test'; $injector = new Horde_Injector(new Horde_Injector_TopLevel()); $server_factory = new Horde_Core_Factory_KolabServer($injector); $factory = new Horde_Core_Factory_KolabSession($injector); $this->session_auth = $this->getMock('Horde_Kolab_Session_Auth_Interface'); $this->session_storage = $this->getMock('Horde_Kolab_Session_Storage_Interface'); $injector->setInstance('Horde_Kolab_Session_Auth_Interface', $this->session_auth); $injector->setInstance('Horde_Kolab_Session_Storage_Interface', $this->session_storage); return $factory; }
public function create(Horde_Injector $injector) { // Set up a view with the shared template path. // Individual controlles will set the specific path for their view. // @TODO: GLOBALS should be moved to a site_config object obtained via // the injector and injected into each class that needs them. $view = $injector->getInstance('Horde_View'); $view->addHelper('Tag'); $view->addHelper('Url'); $view->addTemplatePath(array($GLOBALS['fs_base'] . '/app/views/shared', $GLOBALS['fs_base'] . '/app/views/partials', $GLOBALS['fs_base'] . '/app/views/layout')); return $view; }
/** * Return the IMP_Pgp instance. * * @return IMP_Pgp The singleton instance. */ public function create(Horde_Injector $injector) { global $conf; $params = array('program' => $conf['gnupg']['path']); if (isset($conf['http']['proxy']['proxy_host'])) { $params['proxy_host'] = $conf['http']['proxy']['proxy_host']; if (isset($conf['http']['proxy']['proxy_port'])) { $params['proxy_port'] = $conf['http']['proxy']['proxy_port']; } } return new IMP_Pgp($injector->getInstance('Horde_Core_Factory_Crypt')->create('Horde_Crypt_Pgp', $params)); }
public function create(Horde_Injector $injector) { global $conf, $registry; // Backend driver and dependencies $params = array('registry' => $registry); $adapter_params = array('factory' => new Horde_Core_ActiveSync_Imap_Factory()); // Force emailsync to off if we don't have a mail API. if (!$registry->hasInterface('mail')) { $conf['activesync']['emailsync'] = false; } $driver_params = array('connector' => new Horde_Core_ActiveSync_Connector($params), 'imap' => !empty($conf['activesync']['emailsync']) ? new Horde_ActiveSync_Imap_Adapter($adapter_params) : null, 'ping' => $conf['activesync']['ping'], 'state' => $injector->getInstance('Horde_ActiveSyncState'), 'auth' => $this->_getAuth(), 'cache' => $injector->getInstance('Horde_Cache')); return new Horde_Core_ActiveSync_Driver($driver_params); }
/** */ public function create(Horde_Injector $injector) { global $registry; if (isset($this->_notify)) { return $this->_notify; } $this->_notify = new Horde_Core_Notification_Handler(new Horde_Core_Notification_Storage_Session()); $this->_notify->addType('default', '*', 'Horde_Core_Notification_Event_Status'); $this->_notify->addType('status', 'horde.*', 'Horde_Core_Notification_Event_Status'); $this->_notify->addDecorator(new Horde_Notification_Handler_Decorator_Alarm($injector->getInstance('Horde_Core_Factory_Alarm'), $registry->getAuth())); $this->_notify->addDecorator(new Horde_Core_Notification_Handler_Decorator_Hordelog()); return $this->_notify; }
public function getRequestConfiguration(Horde_Injector $injector) { $request = $injector->getInstance('Horde_Controller_Request'); $registry = $injector->getInstance('Horde_Registry'); $settingsFinder = $injector->getInstance('Horde_Core_Controller_SettingsFinder'); $config = $injector->createInstance('Horde_Core_Controller_RequestConfiguration'); $uri = substr($request->getPath(), strlen($registry->get('webroot', 'horde'))); $uri = trim($uri, '/'); if (strpos($uri, '/') === false) { $app = $uri; } else { list($app, ) = explode('/', $uri, 2); } $config->setApplication($app); // Check for route definitions. $fileroot = $registry->get('fileroot', $app); $routeFile = $fileroot . '/config/routes.php'; if (!file_exists($routeFile)) { $config->setControllerName('Horde_Core_Controller_NotFound'); return $config; } // Push $app onto the registry $registry->pushApp($app); // Application routes are relative only to the application. Let the // mapper know where they start. $this->_mapper->prefix = $registry->get('webroot', $app); // Set the application controller directory $this->_mapper->directory = $registry->get('fileroot', $app) . '/app/controllers'; // Load application routes. $mapper = $this->_mapper; include $routeFile; if (file_exists($fileroot . '/config/routes.local.php')) { include $fileroot . '/config/routes.local.php'; } // Match // @TODO Cache routes $path = $request->getPath(); if (($pos = strpos($path, '?')) !== false) { $path = substr($path, 0, $pos); } $match = $this->_mapper->match($path); if (isset($match['controller'])) { $config->setControllerName(Horde_String::ucfirst($app) . '_' . Horde_String::ucfirst($match['controller']) . '_Controller'); $config->setSettingsExporterName($settingsFinder->getSettingsExporterName($config->getControllerName())); } else { $config->setControllerName('Horde_Core_Controller_NotFound'); } return $config; }
/** * Return an Hermes_Driver instance. * * @return Hermes_Driver */ public function create(Horde_Injector $injector) { $driver = $GLOBALS['conf']['storage']['driver']; $signature = serialize(array($driver, $GLOBALS['conf']['storage']['params']['driverconfig'])); if (empty($this->_instances[$signature])) { if ($driver == 'sql' && $GLOBALS['conf']['storage']['params']['driverconfig'] == 'horde') { $params = array('db_adapter' => $injector->getInstance('Horde_Db_Adapter')); } else { throw new Horde_Exception('Using non-global db connection not yet supported.'); } $class = 'Hermes_Driver_' . Horde_String::ucfirst($driver); $this->_instances[$signature] = new $class($params); } return $this->_instances[$signature]; }
/** * Test creating the server object. * * @return NULL */ public function testCreation() { try { $injector = new Horde_Injector(new Horde_Injector_TopLevel()); $config = new stdClass(); $config->driver = 'dummy'; $injector->setInstance('Horde_Kolab_Server_Config', $config); $injector->bindFactory('Horde_Kolab_Server_Structure', 'Horde_Kolab_Server_Factory', 'getStructure'); $injector->bindFactory('Horde_Kolab_Server', 'Horde_Kolab_Server_Factory', 'getServer'); Horde_Kolab_Server_Factory::getServer($injector); $this->assertFail('No error!'); } catch (Horde_Kolab_Server_Exception $e) { $this->assertEquals('Server type definition "Horde_Kolab_Server_Dummy" missing.', $e->getMessage()); } }
public function create(Horde_Injector $injector) { global $conf; if (!empty($conf['activesync']['enabled'])) { $driver = !empty($conf['activesync']['storage']) ? $conf['activesync']['storage'] : 'sql'; switch (Horde_String::lower($driver)) { case 'nosql': $nosql = $injector->getInstance('Horde_Core_Factory_Nosql')->create('horde', 'activesync'); return new Horde_ActiveSync_State_Mongo(array('connection' => $nosql)); case 'sql': return new Horde_ActiveSync_State_Sql(array('db' => $injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'activesync'))); } } throw new Horde_Exception('ActiveSync is disabled.'); }
public function create(Horde_Injector $injector) { $driver = $GLOBALS['conf']['davstorage']['driver']; $params = Horde::getDriverConfig('davstorage', $driver); switch ($driver) { case 'Sql': $class = 'Horde_Dav_Storage_Sql'; $params['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'davstorage'); break; default: throw new Horde_Exception('A storage backend for DAV has not been configured.'); break; } return new $class($params); }
/** * Return the Ulaform_Driver:: instance. * * @param mixed $name Instance name * * @return Ulaform_Driver * @throws Ulaform_Exception */ public function create($name = '') { if (!isset($this->_instances[$name])) { $driver = 'Sql'; $params = Horde::getDriverConfig('sql', $driver); $class = 'Ulaform_Driver_' . $driver; if (!class_exists($class)) { throw new Ulaform_Exception(sprintf('Unable to load the definition of %s.', $class)); } $params = array('db' => $this->_injector->getInstance('Horde_Db_Adapter'), 'charset' => $params['charset']); $driver = new $class($params); $this->_instances[$name] = $driver; } return $this->_instances[$name]; }
public function create(Horde_Injector $injector) { if (empty($GLOBALS['conf']['activesync']['logging']['level'])) { $level = Horde_ActiveSync_Wbxml::LOG_PROTOCOL; } else { $level = $GLOBALS['conf']['activesync']['logging']['level']; } $server = new Horde_ActiveSync($injector->getInstance('Horde_ActiveSyncBackend'), new Horde_ActiveSync_Wbxml_Decoder(fopen('php://input', 'r'), $level), new Horde_ActiveSync_Wbxml_Encoder(fopen('php://output', 'w+'), $level), $injector->getInstance('Horde_ActiveSyncState'), $injector->getInstance('Horde_Controller_Request')); $server->setSupportedVersion($GLOBALS['conf']['activesync']['version']); $server->setLogger(new Horde_Core_ActiveSync_Logger_Factory()); if (!empty($GLOBALS['conf']['openssl']['cafile'])) { $server->setRootCertificatePath($GLOBALS['conf']['openssl']['cafile']); } return $server; }
/** * Attempts to return a concrete instance based on $driver. * * @return Horde_Perms The newly created concrete instance. * @throws Horde_Exception */ public function create(Horde_Injector $injector) { global $conf; $driver = empty($conf['perms']['driver']) ? 'null' : $conf['perms']['driver']; $params = isset($conf['perms']) ? Horde::getDriverConfig('perms', $driver) : array(); switch (Horde_String::lower($driver)) { case 'sql': $params['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'perms'); break; } $params['cache'] = new Horde_Cache(new Horde_Cache_Storage_Stack(array('stack' => array(new Horde_Cache_Storage_Memory(), $injector->getInstance('Horde_Cache'))))); $params['logger'] = $injector->getInstance('Horde_Log_Logger'); $class = $this->_getDriverName($driver, 'Horde_Perms'); return new $class($params); }