dev-master
9999999-dev http://github.com/sakuraiyuta/fuel-orientdbOrientDB connection manager for FuelPHP
MIT
The Requires
- php >=5.3.3
- doctrine/orientdb-odm dev-master
by Yuta Sakurai
fuelphp orientdb
Wallogit.com
2017 © Pedro Pelรกez
OrientDB connection manager for FuelPHP
fuel-orientdb is a library for using OrientDB with FuelPHP., (*1)
This library is still experimental. You should not use for production., (*2)
TODO: implement, (*3)
composer.json file. Strongly recommended: set vendor-dir value to fuel/app/vendor, and set minimum-stability to dev. (because it uses doctrine/orientdb-odm development ver) ex:{
"config" : {
"vendor-dir" : "fuel/app/vendor"
},
"minimum-stability" : "dev",
"require" : {
"sakuraiyuta/fuel-orientdb" : "dev-master"
}
}
composer install. This command downloads the library and dependencies."project-dir"/fuel/app/vendor/sakuraiyuta/fuel-orientdb/tmp writable for HTTP Server. ex: chmod 777 "project-dir"/fuel/app/vendor/sakuraiyuta/fuel-orientdb/tmp
"project-dir"/fuel/app/bootstrap.php. Add some classes to Autoloader in line Autoloader::add_classes(). ex:Autoloader::add_classes(array(
// Add classes you want to override here
// Example: 'View' => APPPATH.'classes/view.php',
"Fuel\\Core\\OrientDB" => APPPATH . "vendor/sakuraiyuta/fuel-orientdb/src/Fuel/Core/OrientDB.php",
"Fuel\\Core\\Database_Orientdb_Connection" => APPPATH . "vendor/sakuraiyuta/fuel-orientdb/src/Fuel/Core/Database_Orientdb_Connection.php",
));
You can configure database connection settings using FuelPHP common config file, and also can use dsn notation., (*4)
Target file is "project-dir"/fuel/app/config/{development,staging,test,production}/db.php. ex:, (*5)
return array(
'default' => array(
'type' => 'orientdb',
'entity_dir' => __DIR__ . '/../test/Entity/',
'connection' => array(
'dsn' => 'orientdb:host=localhost;dbname=school-manager;port=2480',
'username' => 'admin',
'password' => 'admin',
),
),
);
$config["default"]["type"] is regular value orientdb. Do not change.$config["default"]["entity_dir"] is directory read by Object-Document mapper. Default is "project-dir"/fuel/app/classes/Entity. See details: Object-Document mapping
$config["default"]["connection"]["dsn"] can splits some sections. Expression is "dbtype":host="yourdbhostname";dbname="yourdbname";port="yourdbport".
dbtype is regular value orientdb. Do not change.host is your hostname (or IPaddress) working OrientDB.dbname is database name you want to use.port is a port to connect OrientDB you want to use.$config["default"]["connection"]["username"] is username you want to use for connecting the database.$config["default"]["connection"]["password"] is password you want to use for connecting the database.You can use SQL+ query provided by OrientDB, in FuelPHP controllers., (*6)
Notice: You can only use SELECT statement. Executing INSERT, UPDATE, and DELETE statement feature is not implemented yet., (*7)
// ex: Using FuelPHP DB class.
// In DB class, creates instance Database_Orientdb_Connection and execute query.
// This returns array contains stdClass object. These objects contains properties.
$result = DB::query("SELECT * FROM User");
var_dump($result);
$result = OrientDB::insert("User")
->set(
array(
"username" => "testuser",
"password" => "hashedpassword",
)
)->execute();
var_dump($result);
If you want to use a feature, mapping records to object, write as below:, (*8)
// ex: Using raw OrientDB class.
// The class extends FuelPHP DB class (but many methods are not implemented yet).
// This returns array contains User object. These objects are mapped to records.
$result = OrientDB::get_manager()
->getRepository("User")
->findAll();
var_dump($result);
You need to create User class for mapping entities., (*9)
Instruction is below:, (*10)
Entity in "project-dir"/fuel/app/classes/.
User.php
// Need definition of namespace "Entity" for autoloading.
namespace Entity;
use Doctrine\ODM\OrientDB\Mapper\Annotations as ODM;
/**
* @ODM\Document(class="User")
*/
class User
{
/**
* @ODM\Property(name="@rid", type="string")
*/
protected $rid;
/**
* @ODM\Property(type="string", notnull="true")
*/
protected $username;
/**
* @ODM\Property(type="string", notnull="true")
*/
protected $password;
public function getUsername()
{
return $this->username;
}
public function setUsername($username)
{
$this->username = $username;
}
public function getPassword()
{
return $this->password;
}
public function setPassword($password)
{
$this->password = $password;
}
public function getRid()
{
return $this->rid;
}
public function setRid($rid)
{
$this->rid = $rid;
}
}
This library uses PHPUnit for testing. If you want to modify, contribute to this, use PHPUnit bootstrap and configuration contains the library. Instruction is below:, (*11)
config_phpunit/db.php.sample to config_phpunit/db.php and modify settings. PHPUnit uses the configuration for connecting database.phpunit.xml and modify settings if you want.phpunit test in fuel-orientdb directory.You can use generator for generating test-class (Needs phpunit-skelgen. you can install with PEAR.), (*12)
Directories and files related to testing are below:, (*13)
bootstrap_phpunit.php // bootstrap for PHPUnit. This prepares fixtures PHPUnit allows to call FuelPHP features. phpunit.xml // This supplies env-variables that includes directory informations. config_phpunit/ // contains database settings for testing CRUD. written in FuelPHP common config scheme. โโโ db.php โโโ db.php.sample test โโโ Entity // contains entity-class for testing Object-Document mapping. โ โโโ TestClass.php โโโ ... // test codes under the directory.
OrientDB connection manager for FuelPHP
MIT
fuelphp orientdb