public function connect() { if ($this->_connection) { return; } // parse dsn $config = $this->_config['connection']; $dsn = $this->_config["connection"]["dsn"]; $dsn_temp = explode(':', $dsn); $this->_db_type = $dsn_temp[0]; foreach (explode(';', $dsn_temp[1]) as $row) { $row_temp = explode('=', $row); $config[$row_temp[0]] = $row_temp[1]; } // regist namespace-path mapping to fuel as PSR-0 so Symfony\Finder can't find entities normally. $proxy_dir = APPPATH . "vendor" . DS . "sakuraiyuta" . DS . "fuel-orientdb" . DS . "tmp" . DS; $entity_dir = isset($this->_config["entity_dir"]) ? $this->_config["entity_dir"] : APPPATH . "classes" . DS . "Entity" . DS; \Autoloader::add_namespace("Doctrine", $proxy_dir . DS . "/Doctrine" . DS, TRUE); \Autoloader::add_namespace("Entity", $entity_dir, TRUE); // initialize ODM-Manager $parameters = BindingParameters::create("http://{$config['username']}:{$config['password']}@{$config['host']}:{$config['port']}/{$config['dbname']}"); $binding = new HttpBinding($parameters); $reader = new Reader(new ArrayCache()); $mapper = new Mapper($proxy_dir, $reader); $mapper->setDocumentDirectories(array($entity_dir => "Entity")); $manager = new Manager($mapper, $binding); // Prevent this information from showing up in traces unset($config['username'], $config['password']); $this->_connection = array("manager" => $manager, "binding" => $binding, "mapper" => $mapper); return $this->_connection; }
protected function getBindingParameters($options) { $parameters = array(); array_walk($options, function ($value, $key) use(&$parameters) { if (0 === ($pos = strpos($key, 'odb.'))) { $parameters[substr($key, strpos($key, '.') + 1)] = $value; } }); return BindingParameters::fromArray($parameters); }
protected static function getBindingParameters($options) { $options = array_merge(['odb.host' => TEST_ODB_HOST, 'odb.port' => TEST_ODB_HTTP_PORT, 'odb.username' => TEST_ODB_USER, 'odb.password' => TEST_ODB_PASSWORD, 'odb.database' => TEST_ODB_DATABASE], $options); $parameters = []; array_walk($options, function ($value, $key) use(&$parameters) { if (0 === ($pos = strpos($key, 'odb.'))) { $parameters[substr($key, strpos($key, '.') + 1)] = $value; } }); return BindingParameters::fromArray($parameters); }
/** * Instantiates a new binding. * * @param BindingParameters $parameters * @param HttpClientAdapterInterface $adapter */ public function __construct(BindingParameters $parameters, HttpClientAdapterInterface $adapter = null) { $this->server = "{$parameters->getHost()}:{$parameters->getPort()}"; $this->database = $parameters->getDatabase(); $this->adapter = $adapter ?: new CurlClientAdapter(new CurlClient()); $this->setAuthentication($parameters->getUsername(), $parameters->getPassword()); }
public function __construct(BindingParameters $parameters) { $this->client = $client = new PhpOrient($parameters->getHost(), $parameters->getPort()); $this->clusterMap = $client->dbOpen($parameters->getDatabase(), $parameters->getUsername(), $parameters->getPassword()); }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Invalid parameters type */ public function testParametersCreateAcceptsOnlyStringsOrArrays() { $this->assertInstanceOf('Doctrine\\OrientDB\\Binding\\BindingParameters', BindingParameters::create(array())); $this->assertInstanceOf('Doctrine\\OrientDB\\Binding\\BindingParameters', BindingParameters::create('')); BindingParameters::create((object) array()); }
<?php use Doctrine\OrientDB\Binding\HttpBinding; use Doctrine\OrientDB\Binding\BindingParameters; require __DIR__ . '/../autoload.php'; $parameters = BindingParameters::create('http://*****:*****@127.0.0.1:2480/friends'); $binding = new HttpBinding($parameters); $friends = $binding->query('select from friends where any() traverse(0,1) ( @rid = #5:3 ) and @rid <> #5:3'); foreach ($friends as $friend) { echo $friend->name, "\n"; }
/** * Creates the HttpBinding connection instance. * This method is called by [[open]] to establish a DB connection. * The default implementation will create a HttpBinding instance. * You may override this method if the default HttpBinding needs to be adapted for certain DBMS. * @return HttpBinding the pdo instance */ public function createHttpBindingInstance() { $fromUri = BindingParameters::create($this->uri); return new HttpBinding(BindingParameters::create(['host' => $fromUri->getHost(), 'port' => $fromUri->getPort(), 'database' => $fromUri->getDatabase(), 'username' => $this->username, 'password' => $this->password])); }