Exemplo n.º 1
0
 /**
  * Make a database connection.
  * @param string $name Name of database connection.
  * @param DatabaseSchema $schema Database schema (collecton of table schemas).
  * @throws ConfigurationException If the $options-array does not
  * contain the necessary information for a connection to be made.
  * @throws InvalidSchemaException If one of the schema names listed
  * in the $schemas-parameter is unknown.
  * @throws ConnectionException If the connection fails.
  * @return LoadableDatabase A database object.
  */
 public function connect($name, DatabaseSchema $schema = null)
 {
     if (!isset($this->config[$name])) {
         throw new ConfigurationException(tr('Database "%1" not configured', $name));
     }
     $config = $this->config->getSubset($name);
     $driver = $config->get('driver', null);
     if (!isset($driver)) {
         throw new ConfigurationException(tr('Database driver not set'));
     }
     try {
         $driverInfo = $this->checkDriver($driver);
     } catch (InvalidDriverException $e) {
         throw new ConnectionException(tr('Invalid database driver: %1', $e->getMessage()), 0, $e);
     }
     foreach ($driverInfo['requiredOptions'] as $option) {
         if (!isset($config[$option])) {
             throw new ConfigurationException(tr('Database option missing: "%1"', $option));
         }
     }
     try {
         $class = 'Jivoo\\Databases\\Drivers\\' . $driver . '\\' . $driver . 'Database';
         Assume::isSubclassOf($class, 'Jivoo\\Databases\\LoadableDatabase');
         if (!isset($schema)) {
             $schema = new DynamicDatabaseSchema();
         }
         $object = new $class($schema, $config);
         $object->setLogger($this->logger);
         $this->connections[$name] = new DatabaseConnection($object);
         return $object;
     } catch (ConnectionException $exception) {
         throw new ConnectionException(tr('Database connection failed (%1): %2', $driver, $exception->getMessage()), 0, $exception);
     }
 }
Exemplo n.º 2
0
 /**
  * Conmstruct message list.
  * @param Document $session Notifications.
  * @param string $type Message type.
  */
 public function __construct(Document $session, $type)
 {
     $this->type = $type;
     $this->list = $session->get($type, array());
     $this->session = $session;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function run(App $app, Document $config)
 {
     $app->m->request = new Request($config->get('cookiePrefix', ''), $this->app->basePath);
     $app->m->addProperty('request', $this->m->request);
 }