Consists of all common methods and properties for all database drivers.
Since: 04-10-2010
Author: anza
 /**
  * @param $value
  *
  * @return mixed|string
  */
 public static function serialize($value)
 {
     if (empty(self::$driver)) {
         self::$driver = new Driver();
     }
     return self::$driver->serialize($value);
 }
 /**
  * Whether the class with the specified name should have its metadata loaded.
  *
  * This is only the case for non-transient classes either mapped as an Document or MappedSuperclass.
  *
  * @param string $className
  * @return boolean
  */
 public function isTransient($className)
 {
     if (strpos($className, self::NAME_SPACE) === 0) {
         return $this->builtinDriver->isTransient($className);
     }
     return $this->wrappedDriver->isTransient($className);
 }
Example #3
0
 /**
  *
  * @param string $name database name
  * @param string $driver Driver implementation class name
  * @param array $parameters Driver-specific parameters
  * @param array $classMapper Class mapper configuration (optional)
  */
 public function __construct($name, $driver, $parameters, $classMapper = [])
 {
     $this->name = $name;
     if (isset($parameters['prefix'])) {
         $this->prefix = $parameters['prefix'];
         unset($parameters['prefix']);
     }
     // load driver
     if ($driver[0] !== '\\') {
         // class is relative to this namespace
         $driver = "\\selective\\ORM\\Driver\\{$driver}";
     }
     $this->driver = new $driver();
     $this->driver->loadParameters($parameters);
     $this->driver->connect($this);
     // load class mapper
     if (isset($classMapper['class'])) {
         $classMapperClass = $classMapper['class'];
         unset($classMapper['class']);
         if ($classMapperClass[0] !== '\\') {
             // class is relative to this namespace
             $classMapperClass = "\\selective\\ORM\\ClassMapper\\{$classMapperClass}";
         }
     } else {
         $classMapperClass = "\\selective\\ORM\\ClassMapper\\BuiltIn";
     }
     $this->classMapper = new $classMapperClass();
     $this->classMapper->loadParameters($classMapper);
 }
Example #4
0
 /**
  * @inheritdoc
  */
 public function drive(Driver $driver)
 {
     if ($driver->isDrunk()) {
         return 'Driver cannot drive';
     }
     return $this->car->drive($driver);
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function send(Message $message)
 {
     $queueName = $this->router->queueFor($message);
     if (!$queueName) {
         throw new Exception\QueueNotFound(sprintf('Could not find a queue for "%s"', $message->getName()));
     }
     $this->driver->enqueue($queueName, $message);
 }
Example #6
0
 /**
  * Makes sure timer is stopped and measurement registered. Subsequent call gives no effect.
  */
 public function stop()
 {
     if ($this->startTime !== null) {
         $time = \microtime(true) - $this->startTime;
         $this->driver->measureTime($this->measurementName, $time);
         $this->startTime = null;
     }
 }
Example #7
0
 /**
  * 事务查询
  * @param string $sql
  */
 protected function query($sql)
 {
     try {
         if ($this->driver->query($sql, null, true)) {
             $status = true;
         } else {
             $status = false;
         }
     } catch (\Exception $e) {
         $status = false;
     }
     return $status;
 }
Example #8
0
 /**
  * @param Driver $driver
  * @param Table $table
  * @param Query $query
  * @param bool $asArray
  */
 public function __construct(Driver $driver, Table $table, Query $query, $asArray = false)
 {
     $this->asArray = $asArray;
     $this->table = $table;
     $params = [];
     $this->tableName = $table->getName();
     if (!$this->asArray) {
         $this->recordClasses = [$this->tableName => $table->getDatabase()->getClassMapper()->getClassForRecord($this->tableName)];
     }
     $sql = $query->getRawSql();
     if ($sql === null) {
         $sql = $driver->buildSQL($table, $query, $params);
         $this->fetchStyle = \PDO::FETCH_NUM;
         foreach ($table->getColumns() as $column) {
             if ($column->isPrimaryKey()) {
                 $this->primaryKeyOrdinals[$this->tableName][$column->getOrdinal()] = true;
             }
             $this->columnOrdinalMap[$this->tableName][$column->getOrdinal()] = $column->getName();
         }
         $offset = count($table->getColumns());
         foreach ($query->getJoins() as $join) {
             if (isset($join['cardinality'])) {
                 $joinedTableName = $join['table'];
                 $joinedTable = $table->getDatabase()->getTable($joinedTableName);
                 $this->joinedTables[$joinedTableName] = $joinedTable;
                 if (!$this->asArray) {
                     $this->recordClasses[$joinedTableName] = $joinedTable->getDatabase()->getClassMapper()->getClassForRecord($joinedTableName);
                 }
                 foreach ($joinedTable->getColumns() as $column) {
                     if ($column->isPrimaryKey()) {
                         $this->primaryKeyOrdinals[$joinedTableName][$offset + $column->getOrdinal()] = true;
                     }
                     $this->columnOrdinalMap[$joinedTableName][$offset + $column->getOrdinal()] = $column->getName();
                 }
                 $this->cardinalities[$joinedTableName] = $join['cardinality'];
                 if ($join['cardinality'] === Query::CARDINALITY_ONE_TO_MANY) {
                     $this->properties[$joinedTableName] = $joinedTableName;
                 } else {
                     $this->properties[$joinedTableName] = array_keys($join['on']);
                 }
                 $offset += count($joinedTable->getColumns());
             }
         }
     } else {
         $this->fetchStyle = \PDO::FETCH_ASSOC;
         $this->rawSql = true;
     }
     $this->result = $driver->query($sql, $params);
     $this->fetchNextRow();
 }
Example #9
0
 public static function getInstance()
 {
     if (!isset(self::$_instance)) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #10
0
 /**
  * {@inheritdoc}
  */
 public function rm($hash)
 {
     $this->setConnectorFromPlugin();
     if ($this->allow()) {
         return parent::rm($hash);
     }
 }
Example #11
0
 /**
  * {@inheritdoc}
  */
 public function rm($hash)
 {
     $this->setConnectorFromPlugin();
     if ($this->connector->security->isGranted('ROLE_ADMIN')) {
         return parent::rm($hash);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function upload($fp, $dst, $name, $tmpname)
 {
     $this->setConnectorFromPlugin();
     // upload file by elfinder.
     $result = parent::upload($fp, $dst, $name, $tmpname);
     $name = $result['name'];
     $filtered = \URLify::filter($result['name'], 80);
     if (strcmp($name, $filtered) != 0) {
         /*$arg = array('target' => $file['hash'], 'name' => $filtered);
           $elFinder->exec('rename', $arg);*/
         $this->rename($result['hash'], $filtered);
     }
     $realPath = $this->realpath($result['hash']);
     if (!empty($realPath)) {
         // Getting file info
         //$info = $elFinder->exec('file', array('target' => $file['hash']));
         /** @var elFinderVolumeLocalFileSystem $volume */
         //$volume = $info['volume'];
         //$root = $volume->root();
         //var/www/chamilogits/data/courses/NEWONE/document
         $realPathRoot = $this->getCourseDocumentSysPath();
         // Removing course path
         $realPath = str_replace($realPathRoot, '/', $realPath);
         \FileManager::add_document($this->connector->course, $realPath, 'file', intval($result['size']), $result['name']);
     }
     return $result;
 }
Example #13
0
 /**
  * {@inheritdoc}
  *
  * @codeCoverageIgnore
  */
 public function __construct($connection = null, $tablePrefix = null)
 {
     $this->_db = \JFactory::getDbo();
     $tablePrefix = $this->_db->getPrefix();
     $connection = $this->_db->getConnection();
     parent::__construct($connection, $tablePrefix);
 }
Example #14
0
 private function poll()
 {
     $links = [];
     foreach ($this->active as $link) {
         $links[] = $link;
     }
     list($read, $error) = $this->driver->poll($links);
     foreach ($error as $link) {
         $query = $this->active[$link];
         $err = $this->driver->error($link);
         $this->free($link);
         $query->reject($err);
     }
     foreach ($read as $link) {
         $query = $this->active[$link];
         try {
             $result = $this->driver->read($link);
         } catch (\Exception $err) {
             $this->free($link);
             $query->reject($err);
             continue;
         }
         $this->free($link);
         $subquery = $query->resolve($result);
         if ($subquery instanceof Query) {
             $this->execQuery($subquery);
         } elseif ($subquery instanceof \Iterator) {
             $this->execIterator($subquery);
         }
     }
 }
Example #15
0
 public static function getInstance()
 {
     if (self::$_instance === null) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function rm($hash)
 {
     $this->setConnectorFromPlugin();
     if ($this->connector->security->isGranted('IS_AUTHENTICATED_FULLY')) {
         return parent::rm($hash);
     }
 }
Example #17
0
 /**
  * Constructs this role strategy for the specified configuration.
  * 
  * @param \PHPixie\Pixie $pixie Pixie dependency container
  * @param string $config Name of the configuration
  */
 public function __construct($pixie, $config)
 {
     parent::__construct($pixie, $config);
     $this->relation = $pixie->config->get("auth.{$config}.roles.relation");
     $this->name_field = $pixie->config->get("auth.{$config}.roles.name_field");
     $this->type = $pixie->config->get("auth.{$config}.roles.type");
 }
Example #18
0
 protected function calculateCrumb(BaseObject $object)
 {
     $parentId = $object->getParentId();
     if (!$parentId) {
         $this->crumbsByObjectId[$object->getId()] = array($object->getName());
         return $this->crumbsByObjectId[$object->getId()];
     }
     if (isset($this->crumbsByObjectId[$parentId])) {
         $this->crumbsByObjectId[$object->getId()] = $this->crumbsByObjectId[$parentId];
         $this->crumbsByObjectId[$object->getId()][] = $object->getName();
         return $this->crumbsByObjectId[$object->getId()];
     }
     $storage = $object->getStorage();
     $fake = Driver::getInstance()->getFakeSecurityContext();
     $this->crumbsByObjectId[$object->getId()] = array();
     foreach ($object->getParents($fake, array('select' => array('ID', 'NAME', 'TYPE')), SORT_DESC) as $parent) {
         if ($parent->getId() == $storage->getRootObjectId()) {
             continue;
         }
         $this->crumbsByObjectId[$object->getId()][] = $parent->getName();
     }
     unset($parent);
     $this->crumbsByObjectId[$parentId] = $this->crumbsByObjectId[$object->getId()];
     $this->crumbsByObjectId[$object->getId()][] = $object->getName();
     return $this->crumbsByObjectId[$object->getId()];
 }
Example #19
0
 /**
  * @covers Phossa\Db\Pdo\Statement::prepare()
  * @covers Phossa\Db\Pdo\Statement::execute()
  */
 public function testExecute2()
 {
     // must emulate
     $this->driver->setAttribute('PDO::ATTR_EMULATE_PREPARES', true);
     $this->statement->prepare("SELECT :idx, :color");
     $res = $this->statement->execute(['idx' => 1, 'color' => 'red']);
     $this->assertEquals([[1 => "1", "red" => "red"]], $res->fetchRow());
 }
Example #20
0
function titulacionRenderComboBox()
{
    $render = new templateEngine();
    $db = Driver::getInstance();
    $titulaciones = new Titulacion($db);
    $render->titulaciones = $titulaciones->all();
    return $render->render('titulacionCB_v.php');
}
 function run()
 {
     set_time_limit(0);
     try {
         DB::query("UPDATE Driver SET Active = 0");
         DB::query("UPDATE DriverRelease SET Active = 0");
         $url = 'http://stackalytics.com/driverlog/api/1.0/drivers';
         $jsonResponse = @file_get_contents($url);
         $driverArray = json_decode($jsonResponse, true);
         $array = $driverArray['drivers'];
         foreach ($array as $contents) {
             if (!isset($contents['project_name']) || !isset($contents['name'])) {
                 continue;
             }
             $driver = Driver::get()->filter(array("Name" => trim($contents['name']), "Project" => trim($contents['project_name'])))->first();
             if (!$driver) {
                 $driver = new Driver();
             }
             $driver->Name = trim($contents['name']);
             $driver->Description = isset($contents['description']) ? $contents['description'] : null;
             $driver->Project = $contents['project_name'];
             $driver->Vendor = isset($contents['vendor']) ? $contents['vendor'] : null;
             $driver->Url = isset($contents['wiki']) ? $contents['wiki'] : null;
             $driver->Active = 1;
             if (isset($contents['releases_info'])) {
                 $releases = $contents['releases_info'];
                 foreach ($releases as $release) {
                     $driver_release = DriverRelease::get()->filter("Name", trim($release['name']))->first();
                     if (!$driver_release) {
                         $driver_release = new DriverRelease();
                     }
                     $driver_release->Name = trim($release['name']);
                     $driver_release->Url = $release['wiki'];
                     $driver_release->Active = 1;
                     $driver_release->write();
                     $driver->Releases()->add($driver_release);
                 }
             }
             $driver->write();
         }
         return 'OK';
     } catch (Exception $ex) {
         SS_Log::log($ex, SS_Log::ERR);
         echo $ex->getMessage();
     }
 }
Example #22
0
function materiaRenderComboBox()
{
    $render = new templateEngine();
    $db = Driver::getInstance();
    $materias = new Materia($db);
    $render->materias = $materias->all();
    return $render->render('materiaCB_v.php');
}
Example #23
0
 /**
  * Load a fixture's data into the database.
  * We'll also store it inside the fixtures property for easy
  * access as an array element or class property from our tests.
  *
  * @param  string $fixture
  * @return void
  */
 protected function loadFixture($fixture)
 {
     $tableName = basename($fixture, '.php');
     $records = (include $fixture);
     if (!is_array($records)) {
         throw new Exceptions\InvalidFixtureDataException("Invalid fixture: {$fixture}, please ensure this file returns an array of data.", 1);
     }
     $this->fixtures[$tableName] = $this->driver->buildRecords($tableName, $records);
 }
 public function getDriver($id)
 {
     $driver = Driver::find($id);
     if ($driver == null) {
         return Error::make("No Driver Found");
     } else {
         return Error::success("Driver found", $driver->toArray());
     }
 }
Example #25
0
 public static function getUserId($token)
 {
     $driver = Driver::model()->findByAttributes(array('token' => $token));
     if ($driver == null) {
         echo CJSON::encode(array('error' => 'user not register'));
         Yii::app()->end();
     } else {
         return $driver->user_id;
     }
 }
Example #26
0
 public static function getInstance()
 {
     if (isset(Driver::$man)) {
         return Driver::$man;
     } else {
         Driver::$man = new Driver();
         Driver::$man->connect();
         return Driver::$man;
     }
 }
Example #27
0
 /**
  * Apply substitutions to indentifier and delimites it.
  * @param  string indentifier
  * @return string
  * @internal
  */
 public function delimite($value)
 {
     $value = $this->connection->substitute($value);
     $parts = explode('.', $value);
     foreach ($parts as &$v) {
         if ($v !== '*') {
             $v = $this->driver->escapeIdentifier($v);
         }
     }
     return implode('.', $parts);
 }
 public function setUpCarsAndDrivers()
 {
     Doctrine::createTablesFromArray(array('Car', 'Driver'));
     $bmw = new Car();
     $bmw->make = 'BMW';
     $bmw->save();
     $this->cars['bmw'] = $bmw;
     $audi = new Car();
     $audi->make = 'Audi';
     $audi->save();
     $this->cars['audi'] = $audi;
     $kiro = new Driver();
     $kiro->name = 'Kiril Zyapkov';
     $kiro->save();
     $this->drivers['kiro'] = $kiro;
     $emo = new Driver();
     $emo->name = 'Emil Ivanov';
     $emo->save();
     $this->drivers['emo'] = $emo;
 }
Example #29
0
 private function connectDB()
 {
     $this->settings = $this->config->getDBAccess();
     $settings = $this->settings;
     try {
         $this->db = new PDO(Driver::loadDriver($settings['db']['type'], $settings['db']['host'], $settings['db']['db_name'], $settings['db']['path']), $settings['db']['username'], $settings['db']['password']);
         $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         $this->db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
     } catch (PDOException $ex) {
         echo $ex->getMessage();
         exit;
     }
 }
Example #30
0
 protected function list_ids()
 {
     if ($this->_list_ids === NULL) {
         $this->_list_ids = (array) $this->_driver->all($this->_locator->xpath(), $this->_parent->id());
         if ($this->_locator->filters()) {
             foreach ($this->_list_ids as $offset => $id) {
                 if (!$this->_locator->is_filtered($this->_load($id), $offset)) {
                     unset($this->_list_ids[$offset]);
                 }
             }
         }
     }
     return $this->_list_ids;
 }