Пример #1
0
 /**
  * @param Options $options
  *
  * @return ConnectionInterface
  * @throws \Aviogram\DAL\Exception\Exception
  */
 public function connect(Options $options)
 {
     try {
         $extraOptions = $options->getExtraOptions();
         $pdoOptions = array();
         if (array_key_exists('pdo', $extraOptions) === true) {
             $pdoOptions = $extraOptions['pdo'];
         }
         return new Connection($this->getDSN($options), $options->getUsername(), $options->getPassword(), $pdoOptions);
     } catch (\Aviogram\DAL\Databases\Shared\PDO\Exception\PDO $e) {
         throw Driver::adapterException($this, $e);
     }
 }
Пример #2
0
 /**
  * Register a new driver with the Database
  *
  * @param string $name  The name/alias of the driver
  * @param string $class The class name of the driver (Full class name required)
  *
  * @return $this
  * @throws Exception\Database
  */
 public function registerDriver($name, $class)
 {
     $interface = 'Aviogram\\DAL\\Databases\\Shared\\DriverInterface';
     // Check if the name is not already taken
     if (array_key_exists($name, $this->drivers) === true) {
         throw Exception\Driver::driverExists($name);
     }
     // Check if the class even exists
     if (class_exists($class) === false) {
         throw Exception\Driver::driverClassNotFound($name, $class);
     }
     // Check if the class implements the required interface
     if (is_subclass_of($class, $interface) === false) {
         throw Exception\Driver::invalidClassDriver($name, $class, $interface);
     }
     // Register the driver
     $this->drivers[$name] = $class;
     // Return the platform instance
     return $this;
 }