Exemplo n.º 1
0
 /**
  * @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);
     }
 }
Exemplo n.º 2
0
 /**
  * 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);
     }
 }
Exemplo n.º 3
0
 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;
 }