Compare commits
26 Commits
3811e8224b
...
1.1.0
Author | SHA1 | Date | |
---|---|---|---|
7fc7de7390 | |||
3bc54fb9d1 | |||
123d46d33c | |||
65c224c636 | |||
6cd26a88ea | |||
022ba575b7 | |||
c913f65b91 | |||
c8a7781c88 | |||
1505539e61 | |||
3087a48c43 | |||
43f545516d | |||
b757ed19b2 | |||
9dc71e4d77 | |||
c6806a1c62 | |||
6fd19a11be | |||
7c727d93e9 | |||
e02b8c4063 | |||
89d1db7a7e | |||
8dc0a27fd9 | |||
ae172b902c | |||
7f81b987c9 | |||
af801e769f | |||
c40baaad3f | |||
a82fdce64b | |||
8126b1f67d | |||
2177cb4652 |
@ -61,8 +61,4 @@ abstract class Model implements ModelInterface
|
|||||||
}
|
}
|
||||||
$this->isDirty();
|
$this->isDirty();
|
||||||
}
|
}
|
||||||
public function delete(): void
|
|
||||||
{
|
|
||||||
$this->getFactory()->get(get_class($this))->delete($this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -100,12 +100,6 @@ abstract class Repository implements RepositoryInterface
|
|||||||
}
|
}
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
public function delete(Model $model): void
|
|
||||||
{
|
|
||||||
$query = $this->getQueryBuilder()->delete($this->getTable())->where(['id = ?']);
|
|
||||||
$this->getConnection()->execute($query, [$model->getId()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fetchById(int $id): Model
|
public function fetchById(int $id): Model
|
||||||
{
|
{
|
||||||
$query = $this->getQueryBuilder()
|
$query = $this->getQueryBuilder()
|
||||||
|
@ -15,5 +15,4 @@ interface Model
|
|||||||
public function isDirty(): bool;
|
public function isDirty(): bool;
|
||||||
public function save(): void;
|
public function save(): void;
|
||||||
public function edit(array $data): void;
|
public function edit(array $data): void;
|
||||||
public function delete(): void;
|
|
||||||
}
|
}
|
||||||
|
@ -7,5 +7,7 @@ interface Factory
|
|||||||
{
|
{
|
||||||
public function setContainer(ContainerInterface $container): Factory;
|
public function setContainer(ContainerInterface $container): Factory;
|
||||||
public function getContainer(): ContainerInterface;
|
public function getContainer(): ContainerInterface;
|
||||||
public function get(string $repository_class): Repository;
|
public function setNamespace(string $namespace): Factory;
|
||||||
|
public function getNamespace(): string;
|
||||||
|
public function get(string $repository_name): Repository;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ interface Repository
|
|||||||
public function save(Model $model): void;
|
public function save(Model $model): void;
|
||||||
public function edit(Model $model, array $data): Model;
|
public function edit(Model $model, array $data): Model;
|
||||||
public function create(array $data): Model;
|
public function create(array $data): Model;
|
||||||
public function delete(Model $model): void;
|
|
||||||
public function fetchById(int $id): Model;
|
public function fetchById(int $id): Model;
|
||||||
public function fetchAll(): array;
|
public function fetchAll(): array;
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,25 @@ class Factory implements FactoryInterface
|
|||||||
{
|
{
|
||||||
return $this->container;
|
return $this->container;
|
||||||
}
|
}
|
||||||
public function get(string $repository_class): Repository
|
protected string $namespace;
|
||||||
|
public function setNamespace(string $namespace): FactoryInterface
|
||||||
{
|
{
|
||||||
return $this->getContainer()->get($repository_class);
|
$this->namespace = $namespace;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function getNamespace(): string
|
||||||
|
{
|
||||||
|
return $this->namespace;
|
||||||
|
}
|
||||||
|
protected function buildRepository(string $repository_name): string
|
||||||
|
{
|
||||||
|
return implode("\\", [
|
||||||
|
$this->getNamespace(),
|
||||||
|
$repository_name
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
public function get(string $repository_name): Repository
|
||||||
|
{
|
||||||
|
return $this->getContainer()->get($this->buildRepository($repository_name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user