Skip to content
This repository has been archived by the owner on Aug 13, 2023. It is now read-only.

Commit

Permalink
new version. migrate to new database
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed Apr 10, 2017
1 parent 67bf5cb commit d2573ae
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 30 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": "^7.0",
"doctrine/inflector": "~1.0",
"deimos/database": "~1.0"
"deimos/database": "~2.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0",
Expand Down
8 changes: 4 additions & 4 deletions demo/static.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Role extends \Deimos\ORM\Entity
}

$builder = new \Deimos\Builder\Builder();

$configObject = new \Deimos\Config\ConfigObject($builder, [
$helper = new \Deimos\Helper\Helper($builder);
$slice = new \Deimos\Slice\Slice($helper, [
'adapter' => 'mysql',
// 'host' => 'localhost', // optional
// 'port' => 3306, // optional
Expand All @@ -23,9 +23,9 @@ class Role extends \Deimos\ORM\Entity
'password' => 'root'
]);

$database = new \Deimos\Database\Database($configObject);
$database = new \Deimos\Database\Database($slice);

$orm = new \Deimos\ORM\ORM($builder, $database);
$orm = new \Deimos\ORM\ORM($helper, $database);

$orm->register('role', Role::class);

Expand Down
8 changes: 4 additions & 4 deletions demo/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Role extends \Deimos\ORM\Entity
}

$builder = new \Deimos\Builder\Builder();

$configObject = new \Deimos\Config\ConfigObject($builder, [
$helper = new \Deimos\Helper\Helper($builder);
$slice = new \Deimos\Slice\Slice($helper, [
'adapter' => 'mysql',
// 'host' => 'localhost', // optional
// 'port' => 3306, // optional
Expand All @@ -23,9 +23,9 @@ class Role extends \Deimos\ORM\Entity
'password' => 'root'
]);

$database = new \Deimos\Database\Database($configObject);
$database = new \Deimos\Database\Database($slice);

$orm = new \Deimos\ORM\ORM($builder, $database);
$orm = new \Deimos\ORM\ORM($helper, $database);

//$orm->setConfig([
//
Expand Down
11 changes: 6 additions & 5 deletions src/ORM/ORM.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace Deimos\ORM;

use Deimos\Builder\Builder;
use Deimos\Config\ConfigObject;
use Deimos\Database\Database;
use Deimos\Helper\Helper;
use Deimos\Slice\Slice;
use Doctrine\Common\Inflector\Inflector;

class ORM
Expand Down Expand Up @@ -52,12 +53,12 @@ class ORM
/**
* ORM constructor.
*
* @param Builder $builder
* @param Helper $helper
* @param Database $database
*/
public function __construct(Builder $builder, Database $database)
public function __construct(Helper $helper, Database $database)
{
$this->builder = $builder;
$this->helper = $helper;
$this->database = $database;
}

Expand Down Expand Up @@ -121,7 +122,7 @@ protected function registerConfig($left, array $allConfig)
{
foreach ($allConfig as $right => $config)
{
$object = new ConfigObject($this->builder, $config);
$object = new Slice($this->helper, $config);

$type = $object->getRequired('type');

Expand Down
24 changes: 12 additions & 12 deletions src/ORM/Relationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace Deimos\ORM;

use Deimos\Config\ConfigObject;
use Deimos\Slice\Slice;
use Doctrine\Common\Inflector\Inflector;

class Relationships
{

/**
* @var ConfigObject
* @var Slice
*/
protected $config;
protected $slice;

/**
* @var array
Expand Down Expand Up @@ -46,13 +46,13 @@ class Relationships
protected $init;

/**
* @param ConfigObject $config
* @param Slice $slice
*
* @return static
*/
public function config(ConfigObject $config)
public function config(Slice $slice)
{
$this->config = $config;
$this->slice = $slice;

return $this;
}
Expand Down Expand Up @@ -86,25 +86,25 @@ protected function init()
$leftTable = Inflector::pluralize($this->left);
$rightTable = Inflector::pluralize($this->right);

$type = $this->config->get('type');
$table = $this->config->get('table', $leftTable . ucfirst($rightTable));
$left = $this->config->get('left');
$type = $this->slice->getData('type');
$table = $this->slice->getData('table', $leftTable . ucfirst($rightTable));
$left = $this->slice->getData('left');

if ($left === null)
{
$left = Inflector::singularize($this->right);
}

$leftId = $this->config->get('leftId');
$leftId = $this->slice->getData('leftId');

$right = $this->config->get('right');
$right = $this->slice->getData('right');

if ($right === null)
{
$right = Inflector::singularize($this->left);
}

$rightId = $this->config->get('rightId');
$rightId = $this->slice->getData('rightId');

$item = $this->right;
if (in_array($type, $this->leftPluralize, true))
Expand Down
8 changes: 4 additions & 4 deletions tests/Test/Orm/Orm.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public function setUp()
parent::setUp();

$builder = new \Deimos\Builder\Builder();

$configObject = new \Deimos\Config\ConfigObject($builder, [
$helper = new \Deimos\Helper\Helper($builder);
$slice = new \Deimos\Slice\Slice($helper, [
'adapter' => 'sqlite',
'file' => ':memory:',
]);

$this->database = new \Deimos\Database\Database($configObject);
$this->database = new \Deimos\Database\Database($slice);

$this->database->exec('CREATE TABLE IF NOT EXISTS events (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,num INTEGER NOT NULL,event TEXT NOT NULL)');
$this->database->exec('CREATE TABLE IF NOT EXISTS users (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,name TEXT NOT NULL)');
Expand All @@ -54,7 +54,7 @@ public function setUp()
}
while ($i--);

$this->orm = new \Deimos\ORM\ORM($builder, $this->database);
$this->orm = new \Deimos\ORM\ORM($helper, $this->database);

$this->orm->setConfig([

Expand Down

0 comments on commit d2573ae

Please sign in to comment.