本文整理汇总了PHP中Horde_Injector::createInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Horde_Injector::createInstance方法的具体用法?PHP Horde_Injector::createInstance怎么用?PHP Horde_Injector::createInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Horde_Injector
的用法示例。
在下文中一共展示了Horde_Injector::createInstance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* @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);
}
}
示例2: dispatch
/**
* Handle the current request.
*
* @return NULL
*/
public function dispatch()
{
try {
$this->get('Horde_Controller_ResponseWriter')->writeResponse($this->get('Horde_Controller_Runner')->execute($this->_injector, $this->get('Horde_Controller_Request'), $this->get('Horde_Kolab_FreeBusy_Controller_RequestConfiguration')));
} catch (Exception $e) {
$this->_injector->bindFactory('Horde_Controller_ResponseWriter', 'Horde_Kolab_FreeBusy_Factory_Base', 'createResponseWriter');
$response = $this->_injector->createInstance('Horde_Controller_Response');
$response->setHeaders(array('Status' => '404 Not Found', 'HTTP/1.0' => '404 Not Found'));
$response->setBody($e->getMessage());
$this->get('Horde_Controller_ResponseWriter')->writeResponse($response);
}
}
示例3: getRequestConfiguration
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;
}