コード例 #1
0
 /**
  * @internal
  * @codeCoverageIgnore
  */
 public function __invoke(\Interop\Container\ContainerInterface $container, $requestedName, array $options = null)
 {
     // Retreive database configuration from config file.
     $config = $container->get('Library\\UserConfig')['database'];
     $config['options']['buffer_results'] = true;
     // Set charset to utf8mb4 for MySQL, utf8 for everything else.
     if (stripos($config['driver'], 'mysql') === false) {
         $config['charset'] = 'utf8';
     } else {
         $config['charset'] = 'utf8mb4';
     }
     $adapter = new \Zend\Db\Adapter\Adapter($config);
     $database = \Nada\Factory::getDatabase($adapter);
     if ($database->isSqlite()) {
         $database->emulatedDatatypes = array('bool', 'date', 'decimal', 'timestamp');
     } elseif ($database->isMySql()) {
         $database->emulatedDatatypes = array('bool');
     }
     $database->setTimezone();
     // Return requested service, store instance of other service first
     if ($requestedName == 'Db') {
         $container->setService('Database\\Nada', $database);
         return $adapter;
     } else {
         $container->setService('Db', $adapter);
         return $database;
     }
 }
コード例 #2
0
ファイル: NadaFactory.php プロジェクト: hschletz/braintacle
 /**
  * @internal
  */
 public function __invoke(\Interop\Container\ContainerInterface $container, $requestedName, array $options = null)
 {
     $database = \Nada\Factory::getDatabase($container->get('Db'));
     if ($database->isSqlite()) {
         $database->emulatedDatatypes = array('bool', 'date', 'decimal', 'timestamp');
     } elseif ($database->isMySql()) {
         $database->emulatedDatatypes = array('bool');
     }
     return $database;
 }