Compare commits
30 Commits
230faaf3cc
...
2.2.0
Author | SHA1 | Date | |
---|---|---|---|
d12f3f7897 | |||
3811e8224b | |||
9834eb70a4 | |||
7fc7de7390 | |||
55275d2d75 | |||
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,4 +61,8 @@ abstract class Model implements ModelInterface
|
|||||||
}
|
}
|
||||||
$this->isDirty();
|
$this->isDirty();
|
||||||
}
|
}
|
||||||
|
public function delete(): void
|
||||||
|
{
|
||||||
|
$this->getFactory()->get(get_class($this))->delete($this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,12 @@ 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,4 +15,5 @@ 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,7 +7,5 @@ interface Factory
|
|||||||
{
|
{
|
||||||
public function setContainer(ContainerInterface $container): Factory;
|
public function setContainer(ContainerInterface $container): Factory;
|
||||||
public function getContainer(): ContainerInterface;
|
public function getContainer(): ContainerInterface;
|
||||||
public function setNamespace(string $namespace): Factory;
|
public function get(string $repository_class): Repository;
|
||||||
public function getNamespace(): string;
|
|
||||||
public function get(string $repository_name): Repository;
|
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ 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;
|
||||||
}
|
}
|
||||||
|
29
src/Implement/Model/Factory.php
Normal file
29
src/Implement/Model/Factory.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
namespace ProVM\Implement\Model;
|
||||||
|
|
||||||
|
use Psr\Container\ContainerInterface;
|
||||||
|
use ProVM\Concept\Model\Factory as FactoryInterface;
|
||||||
|
use ProVM\Concept\Model\Repository;
|
||||||
|
|
||||||
|
class Factory implements FactoryInterface
|
||||||
|
{
|
||||||
|
public function __construct(ContainerInterface $container)
|
||||||
|
{
|
||||||
|
$this->setContainer($container);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ContainerInterface $container;
|
||||||
|
public function setContainer(ContainerInterface $container): FactoryInterface
|
||||||
|
{
|
||||||
|
$this->container = $container;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function getContainer(): ContainerInterface
|
||||||
|
{
|
||||||
|
return $this->container;
|
||||||
|
}
|
||||||
|
public function get(string $repository_class): Repository
|
||||||
|
{
|
||||||
|
return $this->getContainer()->get($repository_class);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user