本文整理汇总了PHP中Horde_Injector::setInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Horde_Injector::setInstance方法的具体用法?PHP Horde_Injector::setInstance怎么用?PHP Horde_Injector::setInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Horde_Injector
的用法示例。
在下文中一共展示了Horde_Injector::setInstance方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(Horde_Injector $injector = null)
{
if ($injector === null) {
$this->_injector = new Horde_Injector(new Horde_Injector_TopLevel());
$this->_injector->bindFactory('Horde_Log_Logger', 'Horde_Kolab_Filter_Factory', 'getLogger');
$this->_injector->bindFactory('Horde_Kolab_Server_Composite', 'Horde_Kolab_Filter_Factory', 'getUserDb');
$this->_injector->bindImplementation('Horde_Kolab_Filter_Temporary', 'Horde_Kolab_Filter_Temporary_File');
$this->_injector->setInstance('Horde_Kolab_Filter', $this);
} else {
$this->_injector = $injector;
}
}
示例2: _getFactory
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;
}
示例3: add
/**
* Add a new element to the service container.
*
* @oaram string $interface The interface name to register the service with.
* @param string $factory The (abbreviated) name of the factory.
* @param string $method The factory method that will generate the
* service.
* @param array $params All parameters necessary for creating the
* service.
*
* @return NULL
*/
public function add($interface, $factory, $method, $params)
{
if (!empty($this->_error)) {
return;
}
if (!class_exists('Horde_Test_Factory_' . $factory) && !class_exists($factory)) {
$this->_error = "Neither the class \"Horde_Test_Factory_{$factory}\" nor \"{$factory}\" exist. \"{$interface}\" cannot be created!";
return;
}
if (class_exists('Horde_Test_Factory_' . $factory)) {
$f = $this->_injector->getInstance('Horde_Test_Factory_' . $factory);
} else {
$f = $this->_injector->getInstance($factory);
}
if (!method_exists($f, $method) && !method_exists($f, 'create' . $method)) {
$this->_error = "The factory lacks the specified method \"{$method}\"!";
return;
}
if (method_exists($f, 'create' . $method)) {
$method = 'create' . $method;
}
$params = array_merge($this->_params, $params);
try {
$this->_injector->setInstance($interface, $f->{$method}($params));
} catch (Horde_Test_Exception $e) {
$this->_error = $e->getMessage() . "\n\n" . $e->getFile() . ':' . $e->getLine();
}
}
示例4: testCreation
/**
* 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());
}
}
示例5: __construct
/**
* Create a new Horde_Registry instance.
*
* @param integer $session_flags Any session flags.
* @param array $args See appInit().
*
* @throws Horde_Exception
*/
public function __construct($session_flags = 0, array $args = array())
{
/* Set a valid timezone. */
date_default_timezone_set(ini_get('date.timezone') ?: getenv('TZ') ?: 'UTC');
/* Save arguments. */
$this->_args = $args;
/* Define factories. By default, uses the 'create' method in the given
* classname (string). If other function needed, define as the second
* element in an array. */
$factories = array('Horde_ActiveSyncBackend' => 'Horde_Core_Factory_ActiveSyncBackend', 'Horde_ActiveSyncServer' => 'Horde_Core_Factory_ActiveSyncServer', 'Horde_ActiveSyncState' => 'Horde_Core_Factory_ActiveSyncState', 'Horde_Alarm' => 'Horde_Core_Factory_Alarm', 'Horde_Browser' => 'Horde_Core_Factory_Browser', 'Horde_Cache' => 'Horde_Core_Factory_Cache', 'Horde_Controller_Request' => 'Horde_Core_Factory_Request', 'Horde_Controller_RequestConfiguration' => array('Horde_Core_Controller_RequestMapper', 'getRequestConfiguration'), 'Horde_Core_Auth_Signup' => 'Horde_Core_Factory_AuthSignup', 'Horde_Core_CssCache' => 'Horde_Core_Factory_CssCache', 'Horde_Core_JavascriptCache' => 'Horde_Core_Factory_JavascriptCache', 'Horde_Core_Perms' => 'Horde_Core_Factory_PermsCore', 'Horde_Dav_Server' => 'Horde_Core_Factory_DavServer', 'Horde_Dav_Storage' => 'Horde_Core_Factory_DavStorage', 'Horde_Db_Adapter' => 'Horde_Core_Factory_DbBase', 'Horde_Editor' => 'Horde_Core_Factory_Editor', 'Horde_ElasticSearch_Client' => 'Horde_Core_Factory_ElasticSearch', 'Horde_Group' => 'Horde_Core_Factory_Group', 'Horde_HashTable' => 'Horde_Core_Factory_HashTable', 'Horde_History' => 'Horde_Core_Factory_History', 'Horde_Kolab_Server_Composite' => 'Horde_Core_Factory_KolabServer', 'Horde_Kolab_Session' => 'Horde_Core_Factory_KolabSession', 'Horde_Kolab_Storage' => 'Horde_Core_Factory_KolabStorage', 'Horde_Lock' => 'Horde_Core_Factory_Lock', 'Horde_Log_Logger' => 'Horde_Core_Factory_Logger', 'Horde_Mail' => 'Horde_Core_Factory_MailBase', 'Horde_Memcache' => 'Horde_Core_Factory_Memcache', 'Horde_Nosql_Adapter' => 'Horde_Core_Factory_NosqlBase', 'Horde_Notification' => 'Horde_Core_Factory_Notification', 'Horde_Perms' => 'Horde_Core_Factory_Perms', 'Horde_Queue_Storage' => 'Horde_Core_Factory_QueueStorage', 'Horde_Routes_Mapper' => 'Horde_Core_Factory_Mapper', 'Horde_Routes_Matcher' => 'Horde_Core_Factory_Matcher', 'Horde_Secret' => 'Horde_Core_Factory_Secret', 'Horde_Secret_Cbc' => 'Horde_Core_Factory_Secret_Cbc', 'Horde_Service_Facebook' => 'Horde_Core_Factory_Facebook', 'Horde_Service_Twitter' => 'Horde_Core_Factory_Twitter', 'Horde_Service_UrlShortener' => 'Horde_Core_Factory_UrlShortener', 'Horde_SessionHandler' => 'Horde_Core_Factory_SessionHandler', 'Horde_Template' => 'Horde_Core_Factory_Template', 'Horde_Timezone' => 'Horde_Core_Factory_Timezone', 'Horde_Token' => 'Horde_Core_Factory_Token', 'Horde_Variables' => 'Horde_Core_Factory_Variables', 'Horde_View' => 'Horde_Core_Factory_View', 'Horde_View_Base' => 'Horde_Core_Factory_View', 'Horde_Weather' => 'Horde_Core_Factory_Weather', 'Net_DNS2_Resolver' => 'Horde_Core_Factory_Dns', 'Text_LanguageDetect' => 'Horde_Core_Factory_LanguageDetect');
/* Define implementations. */
$implementations = array('Horde_Controller_ResponseWriter' => 'Horde_Controller_ResponseWriter_Web');
/* Setup injector. */
$GLOBALS['injector'] = $injector = new Horde_Injector(new Horde_Injector_TopLevel());
foreach ($factories as $key => $val) {
if (is_string($val)) {
$val = array($val, 'create');
}
$injector->bindFactory($key, $val[0], $val[1]);
}
foreach ($implementations as $key => $val) {
$injector->bindImplementation($key, $val);
}
$GLOBALS['registry'] = $this;
$injector->setInstance(__CLASS__, $this);
/* Setup autoloader instance. */
$injector->setInstance('Horde_Autoloader', $GLOBALS['__autoloader']);
/* Import and global Horde's configuration values. */
$this->importConfig('horde');
$conf = $GLOBALS['conf'];
/* Set the umask according to config settings. */
if (isset($conf['umask'])) {
umask($conf['umask']);
}
/* Set the error reporting level in accordance with the config
* settings. */
error_reporting($conf['debug_level']);
/* Set the maximum execution time in accordance with the config
* settings, but only if not running from the CLI */
if (!isset($GLOBALS['cli'])) {
set_time_limit($conf['max_exec_time']);
}
/* The basic framework is up and loaded, so set the init flag. */
$this->hordeInit = true;
/* Initial Horde-wide settings. */
/* Initialize browser object. */
$GLOBALS['browser'] = $injector->getInstance('Horde_Browser');
/* Get modified time of registry files. */
$regfiles = array(HORDE_BASE . '/config/registry.php', HORDE_BASE . '/config/registry.d');
if (file_exists(HORDE_BASE . '/config/registry.local.php')) {
$regfiles[] = HORDE_BASE . '/config/registry.local.php';
}
if (!empty($conf['vhosts'])) {
$vhost = HORDE_BASE . '/config/registry-' . $conf['server']['name'] . '.php';
if (file_exists($vhost)) {
$regfiles[] = $this->vhost = $vhost;
}
}
$this->_regmtime = max(array_map('filemtime', $regfiles));
/* Start a session. */
if ($session_flags & self::SESSION_NONE) {
/* Never start a session if the session flags include
SESSION_NONE. */
$GLOBALS['session'] = $session = new Horde_Session_Null();
$session->setup(true, $args['session_cache_limiter']);
} elseif (PHP_SAPI === 'cli' || empty($_SERVER['SERVER_NAME']) && (PHP_SAPI === 'cgi' || PHP_SAPI === 'cgi-fcgi')) {
$GLOBALS['session'] = $session = new Horde_Session();
$session->setup(false, $args['session_cache_limiter']);
} else {
$GLOBALS['session'] = $session = new Horde_Session();
$session->setup(true, $args['session_cache_limiter']);
if ($session_flags & self::SESSION_READONLY) {
/* Close the session immediately so no changes can be made but
values are still available. */
$session->close();
}
}
$injector->setInstance('Horde_Session', $session);
/* Always need to load applications information. */
$this->_loadApplications();
/* Stop system if Horde is inactive. */
if ($this->applications['horde']['status'] == 'inactive') {
throw new Horde_Exception(Horde_Core_Translation::t("This system is currently deactivated."));
}
/* Initialize language configuration object. */
$this->nlsconfig = new Horde_Registry_Nlsconfig();
/* Initialize the localization routines and variables. */
$this->setLanguageEnvironment(null, 'horde');
/* Initialize global page output object. */
$GLOBALS['page_output'] = $injector->getInstance('Horde_PageOutput');
/* Initialize notification object. Always attach status listener by
* default. */
//.........这里部分代码省略.........
示例6: testShouldReturnSharedInstanceIfRequested
public function testShouldReturnSharedInstanceIfRequested()
{
$injector = new Horde_Injector($this->_getTopLevelNeverCalledMock());
$instance = new StdClass();
$injector->setInstance('INSTANCE_INTERFACE', $instance);
$this->assertSame($instance, $injector->getInstance('INSTANCE_INTERFACE'));
}
示例7: __construct
* PHP version 5
*
* @category Horde
* @package Injector
* @author Gunnar Wrobel <wrobel@pardus.de>
* @license http://www.horde.org/licenses/bsd BSD
* @link http://pear.horde.org/index.php?package=Injector
*/
require 'Horde/Autoloader.php';
class Greet
{
public function __construct($somebody)
{
$this->somebody = $somebody;
}
public function greet()
{
print 'Hello ' . $this->somebody;
}
}
class Factory
{
public static function getGreeter(Horde_Injector $injector)
{
return new Greet($injector->getInstance('Person'));
}
}
$a = new Horde_Injector(new Horde_Injector_TopLevel());
$a->setInstance('Person', 'Bob');
$a->bindFactory('Greet', 'Factory', 'getGreeter');
$a->getInstance('Greet')->greet();
示例8: set
/**
* Set an element to the given value.
*
* @param string $interface The element to set.
* @param mixed $instance The value to set the element to.
*
* @return NULL
*/
public function set($interface, $instance)
{
return $this->_injector->setInstance($interface, $instance);
}
示例9:
<?php
/**
* Demonstrates settings/getting concrete instances.
*
* PHP version 5
*
* @category Horde
* @package Injector
* @author Gunnar Wrobel <wrobel@pardus.de>
* @license http://www.horde.org/licenses/bsd BSD
* @link http://pear.horde.org/index.php?package=Injector
*/
require 'Horde/Autoloader.php';
$a = new Horde_Injector(new Horde_Injector_TopLevel());
$a->setInstance('a', 'a');
var_dump($a->getInstance('a'));