Skip to content

Commit

Permalink
Merge pull request #19 from SerafimArts/master
Browse files Browse the repository at this point in the history
Change schema direct accessing to scheme getter.
  • Loading branch information
wolfy-j authored Jun 23, 2019
2 parents be11e7b + 49024c9 commit 0e656e4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
10 changes: 3 additions & 7 deletions src/ORM.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ final class ORM implements ORMInterface
*/
public function __construct(FactoryInterface $factory, SchemaInterface $schema = null)
{
$this->generator = new CommandGenerator();
$this->factory = $factory;
$this->schema = $schema;
$this->schema = $schema ?? new Schema([]);

$this->heap = new Heap();
$this->generator = new CommandGenerator();
}

/**
Expand Down Expand Up @@ -134,7 +134,7 @@ public function make(string $role, array $data = [], int $node = Node::NEW)
}

// init entity class and prepared (typecasted) data
list($e, $prepared) = $m->init($data);
[$e, $prepared] = $m->init($data);

$node = new Node($node, $prepared, $m->getRole());

Expand Down Expand Up @@ -179,10 +179,6 @@ public function withSchema(SchemaInterface $schema): ORMInterface
*/
public function getSchema(): SchemaInterface
{
if (is_null($this->schema)) {
throw new ORMException("ORM is not configured, schema is missing");
}

return $this->schema;
}

Expand Down
7 changes: 4 additions & 3 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class Schema implements SchemaInterface
public function __construct(array $schema)
{
// split into two?
list($this->schema, $this->aliases) = $this->normalize($schema);
[$this->schema, $this->aliases] = $this->normalize($schema);
}

/**
Expand Down Expand Up @@ -60,7 +60,8 @@ public function defines(string $role): bool
*/
public function define(string $role, int $property)
{
$role = $this->resolveAlias($role);
$role = $this->resolveAlias($role) ?? $role;

if (!isset($this->schema[$role])) {
throw new SchemaException("Undefined schema `{$role}`, not found");
}
Expand Down Expand Up @@ -178,4 +179,4 @@ private function normalizeRelations(array $relations, array $aliases): \Generato
yield $name => $rel;
}
}
}
}

0 comments on commit 0e656e4

Please sign in to comment.