コード例 #1
0
 /**
  *
  * @param Adapter $adapter
  * @param string $schema default schema, taken from adapter if not given
  * @throws Exception\InvalidArgumentException if schema parameter not valid
  */
 public function __construct(Adapter $adapter, $schema = null)
 {
     $this->adapter = $adapter;
     if ($schema === null) {
         $schema = $adapter->getCurrentSchema();
     }
     $this->setDefaultSchema($schema);
 }
コード例 #2
0
ファイル: AdapterTest.php プロジェクト: rajanlamic/IntTest
 /**
  * @testdox unit test: Test getCurrentSchema() returns current schema from connection object
  * @covers Zend\Db\Adapter\Adapter::getCurrentSchema
  */
 public function testGetCurrentSchema()
 {
     $this->mockConnection->expects($this->any())->method('getCurrentSchema')->will($this->returnValue('FooSchema'));
     $this->assertEquals('FooSchema', $this->adapter->getCurrentSchema());
 }
コード例 #3
0
ファイル: AbstractSource.php プロジェクト: totolouis/ZF2-Auth
 /**
  * Constructor
  *
  * @param Adapter $adapter
  */
 public function __construct(Adapter $adapter)
 {
     $this->adapter = $adapter;
     $this->defaultSchema = $adapter->getCurrentSchema() ?: self::DEFAULT_SCHEMA;
 }
コード例 #4
0
 public function getLinkedTables($tableName)
 {
     $getTableSql = "SELECT TABLE_NAME, COLUMN_NAME FROM information_schema.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = " . "'" . $this->db->getCurrentSchema() . "'" . " AND REFERENCED_TABLE_NAME = '" . $tableName . "'" . " AND CONSTRAINT_NAME <>'PRIMARY' AND REFERENCED_TABLE_NAME is not null;";
     $rowSet = $this->db->query($getTableSql, Adapter\Adapter::QUERY_MODE_EXECUTE);
     return $rowSet->toArray();
 }
コード例 #5
0
ファイル: Singlesite.php プロジェクト: gridguyz/core
 /**
  * Setup services which depends on the db
  *
  * @param   \Zend\Db\Adapter\Adapter $db
  * @return  \Zend\Db\Adapter\Adapter
  */
 public function configure(DbAdapter $db)
 {
     $sm = $this->getServiceLocator();
     $platform = $db->getPlatform();
     $driver = $db->getDriver();
     $matches = array();
     $fulldomain = strtolower($this->getDomain());
     $config = $driver->getConnection()->getConnectionParameters();
     /// TODO: remove this
     if (isset($_SERVER['GRIDGUYZ_DOMAIN'])) {
         $domain = $_SERVER['GRIDGUYZ_DOMAIN'];
         $subdomain = isset($_SERVER['GRIDGUYZ_SUBDOMAIN']) ? $_SERVER['GRIDGUYZ_SUBDOMAIN'] : '';
     } elseif (preg_match('/^[\\da-fA-F:]+/', $fulldomain) || preg_match('/^\\d+(\\.\\d+){3}$/', $fulldomain)) {
         $subdomain = '';
         $domain = $fulldomain;
     } else {
         $fullLength = strlen($fulldomain);
         if (empty($config['validDomains'])) {
             $validDomains = array('localhost');
         } else {
             $validDomains = array_map('strtolower', (array) $config['validDomains']);
         }
         if (!empty($config['defaultDomain'])) {
             $defaultDomain = strtolower($config['defaultDomain']);
             if (!in_array($defaultDomain, $validDomains)) {
                 array_unshift($validDomains, $defaultDomain);
             }
         }
         foreach ($validDomains as $validDomain) {
             if ($fulldomain == $validDomain) {
                 $subdomain = '';
                 $domain = $fulldomain;
                 break;
             }
             $length = $fullLength - strlen($validDomain) - 1;
             if ($length > 0 && '.' . $validDomain == substr($fulldomain, $length)) {
                 $subdomain = substr($fulldomain, 0, $length);
                 $domain = $validDomain;
                 break;
             }
         }
     }
     if (!isset($subdomain) || !isset($domain)) {
         if (preg_match('/^(.+)\\.([a-z0-9-]+\\.[a-z]+)$/', $fulldomain, $matches)) {
             $subdomain = $matches[1];
             $domain = $matches[2];
         } else {
             $subdomain = '';
             $domain = $fulldomain;
         }
     }
     $query = $db->query('
         SELECT *
           FROM ' . $platform->quoteIdentifier('subdomain') . '
          WHERE LOWER( ' . $platform->quoteIdentifier('subdomain') . ' )
              = LOWER( ' . $driver->formatParameterName('subdomain') . ' )
     ');
     $result = $query->execute(array('subdomain' => $subdomain));
     if ($result->getAffectedRows() > 0) {
         $schema = $db->getCurrentSchema();
         foreach ($result as $data) {
             $info = new SiteInfo(array('schema' => $schema, 'domain' => $domain, 'subdomain' => $subdomain, 'subdomainId' => $data['id'], 'fulldomain' => $fulldomain, 'scheme' => $this->getScheme(), 'port' => $this->getPort()));
             $sm->setService('SiteInfo', $info);
             return $db;
         }
     } else {
         if ($domain) {
             $sm->setService('RedirectToDomain', new RedirectionService($this->getScheme(), $domain, $this->getPort(), 'sub-domain not found', false));
         } else {
             if (empty($config['defaultDomain'])) {
                 throw new Exception\InvalidArgumentException('Domain not found, and default domain not set');
             } else {
                 $sm->setService('RedirectToDomain', new RedirectionService($this->getScheme(), $config['defaultDomain'], $this->getPort(), 'sub-domain not found', false));
             }
         }
     }
     return $db;
 }
コード例 #6
0
ファイル: TestCaseDb.php プロジェクト: sporkcode/spork
 /**
  * Copies table structure and creates temporary table on top of it.
  * 
  * @param string $table Table name
  * @param Adapter $db
  */
 private function createTestTable($table, Adapter $source, Adapter $dest)
 {
     $createTable = $this->getCreateTable($table, $source);
     if ($source->getCurrentSchema() == $dest->getCurrentSchema()) {
         $createTable = str_replace('CREATE TABLE', 'CREATE TEMPORARY TABLE', $createTable);
     }
     $createTable = preg_replace('/ENGINE=\\w+/', 'ENGINE=Memory', $createTable, 1);
     $createTable = preg_replace(array('`\\s(tiny|medium|long)?text(\\s|,)`i', '`\\s(tiny|medium|long)?blob(\\s|,)`i'), array(' varchar(512)$2', ' varbinary(512)$2'), $createTable);
     $dest->query($createTable, Adapter::QUERY_MODE_EXECUTE);
 }