Compare commits
8 Commits
e576ef5054
...
3.0.0
Author | SHA1 | Date | |
---|---|---|---|
67fea3b15f | |||
d2c5c1180b | |||
2a06507876 | |||
e4cec2e2f2 | |||
faf615e79d | |||
8a03d9e675 | |||
b8409182d7 | |||
100df73916 |
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
namespace ProVM\Alias\Model;
|
||||
|
||||
use ProVM\Concept\Model;
|
||||
|
||||
abstract class Mapping implements \ProVM\Concept\Model\Mapping
|
||||
{
|
||||
protected string $input;
|
||||
protected string $output;
|
||||
protected \Closure $transformation;
|
||||
|
||||
public function getInputName(): string
|
||||
{
|
||||
return $this->input;
|
||||
}
|
||||
public function getOutputName(): string
|
||||
{
|
||||
return $this->output;
|
||||
}
|
||||
public function getTransformation(): callable
|
||||
{
|
||||
return $this->transformation;
|
||||
}
|
||||
|
||||
public function setInputName(string $input): \ProVM\Concept\Model\Mapping
|
||||
{
|
||||
$this->input = $input;
|
||||
return $this;
|
||||
}
|
||||
public function setOutputName(string $output): \ProVM\Concept\Model\Mapping
|
||||
{
|
||||
$this->output = $output;
|
||||
return $this;
|
||||
}
|
||||
public function setTransformation(callable $transformation): \ProVM\Concept\Model\Mapping
|
||||
{
|
||||
$this->transformation = $transformation;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __invoke(mixed $input, mixed &$output, ?array $params = null): void
|
||||
{
|
||||
if (is_array($input)) {
|
||||
$input_value = $input[$this->getInputName()];
|
||||
}
|
||||
if (is_a($input, Model::class)) {
|
||||
$input_value = $input->{$this->getInputName()}();
|
||||
}
|
||||
|
||||
$args = [$input_value];
|
||||
if ($params !== null) {
|
||||
$args = array_merge($args, $params);
|
||||
}
|
||||
$output_value = call_user_func_array($this->getTransformation(), $args);
|
||||
|
||||
if (is_array($output)) {
|
||||
$output[$this->getOutputName()] = $output_value;
|
||||
}
|
||||
if (is_a($output, Model::class)) {
|
||||
$output->{$this->getOutputName()}($output_value);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,13 @@
|
||||
<?php
|
||||
namespace ProVM\Alias\Model;
|
||||
|
||||
use PDOException;
|
||||
use ProVM\Concept\Database\Connection;
|
||||
use ProVM\Concept\Database\QueryBuilder;
|
||||
use ProVM\Concept\Model;
|
||||
use ProVM\Concept\Model\Factory;
|
||||
use ProVM\Concept\Model\Mapping;
|
||||
use ProVM\Concept\Model\Repository as RepositoryInterface;
|
||||
use ProVM\Exception\BlankResult;
|
||||
|
||||
abstract class Repository implements RepositoryInterface
|
||||
{
|
||||
@ -19,255 +20,164 @@ abstract class Repository implements RepositoryInterface
|
||||
}
|
||||
|
||||
protected Connection $connection;
|
||||
public function setConnection(Connection $connection): Repository
|
||||
{
|
||||
$this->connection = $connection;
|
||||
return $this;
|
||||
}
|
||||
protected QueryBuilder $builder;
|
||||
protected Factory $factory;
|
||||
protected string $model;
|
||||
protected string $table;
|
||||
|
||||
public function getConnection(): Connection
|
||||
{
|
||||
return $this->connection;
|
||||
}
|
||||
protected QueryBuilder $builder;
|
||||
public function setQueryBuilder(QueryBuilder $builder): RepositoryInterface
|
||||
{
|
||||
$this->builder = $builder;
|
||||
return $this;
|
||||
}
|
||||
public function getQueryBuilder(): QueryBuilder
|
||||
{
|
||||
return $this->builder;
|
||||
}
|
||||
protected Factory $factory;
|
||||
public function setFactory(Factory $factory): RepositoryInterface
|
||||
{
|
||||
$this->factory = $factory;
|
||||
return $this;
|
||||
}
|
||||
public function getFactory(): Factory
|
||||
{
|
||||
return $this->factory;
|
||||
}
|
||||
protected string $model;
|
||||
public function setModel(string $model_class): RepositoryInterface
|
||||
{
|
||||
$this->model = $model_class;
|
||||
return $this;
|
||||
}
|
||||
public function getModel(): string
|
||||
{
|
||||
return $this->model;
|
||||
}
|
||||
public function getNewModel(): Model
|
||||
public function getTable(): string
|
||||
{
|
||||
$class = $this->getModel();
|
||||
return (new $class())
|
||||
->setRepository($this);
|
||||
return $this->table;
|
||||
}
|
||||
|
||||
public function setConnection(Connection $connection): Repository
|
||||
{
|
||||
$this->connection = $connection;
|
||||
return $this;
|
||||
}
|
||||
public function setQueryBuilder(QueryBuilder $builder): RepositoryInterface
|
||||
{
|
||||
$this->builder = $builder;
|
||||
return $this;
|
||||
}
|
||||
public function setFactory(Factory $factory): RepositoryInterface
|
||||
{
|
||||
$this->factory = $factory;
|
||||
return $this;
|
||||
}
|
||||
public function setModel(string $model_class): RepositoryInterface
|
||||
{
|
||||
$this->model = $model_class;
|
||||
return $this;
|
||||
}
|
||||
protected string $table;
|
||||
public function setTable(string $table): RepositoryInterface
|
||||
{
|
||||
$this->table = $table;
|
||||
return $this;
|
||||
}
|
||||
public function getTable(): string
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
protected array $column_mappings;
|
||||
protected array $property_mappings;
|
||||
public function getColumnMappings(): array
|
||||
{
|
||||
return $this->column_mappings;
|
||||
}
|
||||
public function addColumnMapping(Mapping $mapping): RepositoryInterface
|
||||
{
|
||||
$this->column_mappings []= $mapping;
|
||||
return $this;
|
||||
}
|
||||
public function setColumnMappings(array $mappings): RepositoryInterface
|
||||
{
|
||||
foreach ($mappings as $mapping) {
|
||||
$this->addColumnMapping($mapping);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
public function getPropertyMappings(): array
|
||||
{
|
||||
return $this->property_mappings;
|
||||
}
|
||||
public function addPropertyMapping(Mapping $mapping): Repository
|
||||
{
|
||||
$this->property_mappings []= $mapping;
|
||||
return $this;
|
||||
}
|
||||
public function setPropertyMappings(array $mappings): Repository
|
||||
{
|
||||
foreach ($mappings as $mapping) {
|
||||
$this->addPropertyMapping($mapping);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
protected array $columns;
|
||||
public function setColumns(array $columns): RepositoryInterface
|
||||
{
|
||||
foreach ($columns as $column) {
|
||||
$this->addColumn($column);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
public function addColumn(string $column): RepositoryInterface
|
||||
{
|
||||
$this->columns []= $column;
|
||||
return $this;
|
||||
}
|
||||
public function getColumns(): array
|
||||
{
|
||||
return $this->columns;
|
||||
}
|
||||
protected array $properties;
|
||||
public function getProperties(): array
|
||||
{
|
||||
return $this->properties;
|
||||
}
|
||||
public function addProperty(string $property): RepositoryInterface
|
||||
{
|
||||
$this->properties []= $property;
|
||||
return $this;
|
||||
}
|
||||
public function setProperties(array $properties): RepositoryInterface
|
||||
{
|
||||
foreach ($properties as $property) {
|
||||
$this->addProperty($property);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
protected array $required;
|
||||
public function setRequired(array $columns): RepositoryInterface
|
||||
{
|
||||
foreach ($columns as $item) {
|
||||
$this->addRequired($item);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
public function addRequired(string $column): RepositoryInterface
|
||||
{
|
||||
$this->required []= $column;
|
||||
return $this;
|
||||
}
|
||||
public function getRequired(): array
|
||||
{
|
||||
if (isset($this->optional) and !isset($this->required)) {
|
||||
return array_diff($this->getColumns(), $this->getOptional());
|
||||
}
|
||||
return $this->required ?? $this->getColumns();
|
||||
}
|
||||
protected array $optional;
|
||||
public function setOptional(array $columns): RepositoryInterface
|
||||
{
|
||||
foreach ($columns as $item) {
|
||||
$this->addColumn($item);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
public function addOptional(string $column): RepositoryInterface
|
||||
{
|
||||
$this->optional []= $column;
|
||||
return $this;
|
||||
}
|
||||
public function getOptional(): array
|
||||
{
|
||||
if (isset($this->required) and !isset($this->optional)) {
|
||||
return array_diff($this->getColumns(), $this->getRequired());
|
||||
}
|
||||
return $this->optional ?? [];
|
||||
}
|
||||
|
||||
public function getMethod(string $property, bool $get = true): string
|
||||
public function save(Model &$model): void
|
||||
{
|
||||
$m = str_replace(' ', '', ucwords(str_replace('_', ' ', $property)));
|
||||
if ($get) {
|
||||
return "get{$m}";
|
||||
try {
|
||||
$old = $this->defaultFind($model);
|
||||
$this->update($model, $old);
|
||||
} catch (BlankResult $e) {
|
||||
$this->insert($model);
|
||||
$model->setId($this->getConnection()->getPDO()->lastInsertId());
|
||||
}
|
||||
return "set{$m}";
|
||||
}
|
||||
public function getProperty(string $method): string
|
||||
public function update(Model $model, Model $old): void
|
||||
{
|
||||
$parts = preg_split('/(?=[A-Z])/', $method);
|
||||
if (in_array(strtolower($parts[0]), ['get', 'set'])) {
|
||||
array_shift($parts);
|
||||
$model_values = $this->valuesForUpdate($model);
|
||||
$old_values = $this->valuesForUpdate($old);
|
||||
|
||||
$columns = [];
|
||||
$values = [];
|
||||
foreach ($this->fieldsForUpdate() as $i => $column) {
|
||||
if (isset($model_values[$i]) and $old_values[$i] !== $model_values[$i]) {
|
||||
$columns []= "`{$column}` = ?";
|
||||
$values []= $model_values[$i];
|
||||
}
|
||||
}
|
||||
return strtolower(implode('_', $parts));
|
||||
}
|
||||
public function fillData(Model $model, array $data): Model
|
||||
{
|
||||
foreach ($this->getPropertyMappings() as $mapping) {
|
||||
$mapping($data, $model);
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
public function mapArray(Model $model, array $data): array
|
||||
{
|
||||
foreach ($this->getColumnMappings() as $mapping) {
|
||||
$mapping($model, $data);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
public function load(array $data): Model
|
||||
{
|
||||
return $this->fillData($this->getNewModel()
|
||||
->setId($data['id']), $data);
|
||||
}
|
||||
public function save(Model $model): void
|
||||
{
|
||||
if (!$model->isDirty() and !$model->isNew()) {
|
||||
if (count($columns) === 0) {
|
||||
return;
|
||||
}
|
||||
if (!$model->isNew()) {
|
||||
$this->update($model);
|
||||
return;
|
||||
}
|
||||
$values = array_replace(array_flip($this->getColumns()), $this->mapArray($model, []));
|
||||
$cols = array_fill(0, count($values), '?');
|
||||
$query = $this->getQueryBuilder()->insert($this->getTable())->columns($this->getColumns())->values($cols);
|
||||
$this->getConnection()->execute($query, array_values($values));
|
||||
}
|
||||
public function update(Model $model): void
|
||||
{
|
||||
if (!$model->isDirty() and !$model->isNew()) {
|
||||
return;
|
||||
}
|
||||
$values = $this->mapArray($model, []);
|
||||
$cols = array_map(function($column) {
|
||||
return "{$column} = ?";
|
||||
}, $values);
|
||||
|
||||
$values = array_values($values);
|
||||
$values []= $model->getId();
|
||||
$query = $this->getQueryBuilder()->update($this->getTable())->set($cols)->where(['id = ?']);
|
||||
$values []= $old->{$this->idProperty()}();
|
||||
$query = $this->getQueryBuilder()->update($this->getTable())->set($columns)->where(["{$this->idField()}} = ?"]);
|
||||
$this->getConnection()->execute($query, $values);
|
||||
}
|
||||
public function create(array $data): Model
|
||||
{
|
||||
return $this->fillData($this->getNewModel()
|
||||
->setNew(), $data);
|
||||
}
|
||||
public function edit(Model $model, array $data): Model
|
||||
{
|
||||
foreach ($this->getColumns() as $col) {
|
||||
if (isset($data[$col])) {
|
||||
$m = $this->getMethod($col, false);
|
||||
if (!method_exists($model, $m)) {
|
||||
continue;
|
||||
}
|
||||
$model->{$m}($data[$col]);
|
||||
}
|
||||
try {
|
||||
return $this->defaultSearch($data);
|
||||
} catch (PDOException | BlankResult $e) {
|
||||
$data[$this->idField()] = 0;
|
||||
return $this->load($data);
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
public function delete(Model $model): void
|
||||
{
|
||||
$query = $this->getQueryBuilder()->delete($this->getTable())->where(['id = ?']);
|
||||
$this->getConnection()->execute($query, [$model->getId()]);
|
||||
$this->resetIndex();
|
||||
$this->optimize();
|
||||
}
|
||||
|
||||
protected function idProperty(): string
|
||||
{
|
||||
return 'getId';
|
||||
}
|
||||
protected function idField(): string
|
||||
{
|
||||
return 'id';
|
||||
}
|
||||
protected function insert(Model $model): void
|
||||
{
|
||||
$fields = $this->fieldsForInsert();
|
||||
$fields_string = array_map(function($field) {
|
||||
return "`{$field}`";
|
||||
}, $fields);
|
||||
$fields_questions = array_fill(0, count($fields), '?');
|
||||
$query = $this->getQueryBuilder()->insert($this->getTable())->columns($fields_string)->values($fields_questions);
|
||||
$values = $this->valuesForInsert($model);
|
||||
$this->getConnection()->execute($query, $values);
|
||||
}
|
||||
protected function resetIndex(): void
|
||||
{
|
||||
$query = "ALTER TABLE `{$this->getTable()}` AUTO_INCREMENT = 1";
|
||||
$this->getConnection()->query($query);
|
||||
}
|
||||
protected function optimize(): void
|
||||
{
|
||||
$query = "OPTIMIZE TABLE `{$this->getTable()}`";
|
||||
$this->getConnection()->query($query);
|
||||
}
|
||||
|
||||
protected function fetchOne(string $query, ?array $values = null): Model
|
||||
{
|
||||
if ($values !== null) {
|
||||
$rs = $this->getConnection()->prepare($query);
|
||||
$rs->execute($values);
|
||||
} else {
|
||||
$rs = $this->getConnection()->query($query);
|
||||
}
|
||||
$row = $rs->getFirstAsArray();
|
||||
if (!$row) {
|
||||
throw new BlankResult();
|
||||
}
|
||||
return $this->load($row);
|
||||
}
|
||||
protected function fetchMany(string $query, ?array $values = null): array
|
||||
{
|
||||
if ($values !== null) {
|
||||
$rs = $this->getConnection()->prepare($query);
|
||||
$rs->execute($values);
|
||||
} else {
|
||||
$rs = $this->getConnection()->query($query);
|
||||
}
|
||||
$rows = $rs->getAsArray();
|
||||
if (!$rows) {
|
||||
throw new BlankResult();
|
||||
}
|
||||
return array_map([$this, 'load'], $rows);
|
||||
}
|
||||
|
||||
public function fetchById(int $id): Model
|
||||
@ -277,13 +187,20 @@ abstract class Repository implements RepositoryInterface
|
||||
->from($this->getTable())
|
||||
->where(['id = ?'])
|
||||
->limit(1);
|
||||
return $this->load($this->getConnection()->execute($query, [$id])->getFirstAsArray());
|
||||
return $this->fetchOne($query, [$id]);
|
||||
}
|
||||
public function fetchAll(): array
|
||||
{
|
||||
$query = $this->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable());
|
||||
return array_map([$this, 'load'], $this->getConnection()->query($query)->getAsArray());
|
||||
return $this->fetchMany($query);
|
||||
}
|
||||
|
||||
abstract protected function fieldsForUpdate(): array;
|
||||
abstract protected function fieldsForInsert(): array;
|
||||
abstract protected function valuesForUpdate(Model $model): array;
|
||||
abstract protected function valuesForInsert(Model $model): array;
|
||||
abstract protected function defaultFind(Model $model): Model;
|
||||
abstract protected function defaultSearch(array $data): Model;
|
||||
}
|
||||
|
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
namespace ProVM\Concept\Model;
|
||||
|
||||
interface Mapping
|
||||
{
|
||||
public function getInputName(): string;
|
||||
public function getOutputName(): string;
|
||||
public function getTransformation(): callable;
|
||||
public function setInputName(string $input): Mapping;
|
||||
public function setOutputName(string $output): Mapping;
|
||||
public function setTransformation(callable $transformation): Mapping;
|
||||
public function __invoke(mixed $input, mixed &$output, ?array $params = null): mixed;
|
||||
}
|
@ -7,55 +7,52 @@ use ProVM\Concept\Model;
|
||||
|
||||
interface Repository
|
||||
{
|
||||
/**
|
||||
* @return Connection
|
||||
*/
|
||||
public function getConnection(): Connection;
|
||||
/**
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
public function getQueryBuilder(): QueryBuilder;
|
||||
/**
|
||||
* @return Factory
|
||||
*/
|
||||
public function getFactory(): Factory;
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getModel(): string;
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTable(): string;
|
||||
|
||||
/**
|
||||
* @param Connection $connection
|
||||
* @return Repository
|
||||
*/
|
||||
public function setConnection(Connection $connection): Repository;
|
||||
|
||||
/**
|
||||
* @return Connection
|
||||
*/
|
||||
public function getConnection(): Connection;
|
||||
|
||||
/**
|
||||
* @param QueryBuilder $builder
|
||||
* @return Repository
|
||||
*/
|
||||
public function setQueryBuilder(QueryBuilder $builder): Repository;
|
||||
|
||||
/**
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
public function getQueryBuilder(): QueryBuilder;
|
||||
|
||||
/**
|
||||
* @param Factory $factory
|
||||
* @return Repository
|
||||
*/
|
||||
public function setFactory(Factory $factory): Repository;
|
||||
|
||||
/**
|
||||
* @return Factory
|
||||
*/
|
||||
public function getFactory(): Factory;
|
||||
|
||||
/**
|
||||
* @param string $model_class
|
||||
* @return Repository
|
||||
*/
|
||||
public function setModel(string $model_class): Repository;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @param string $table
|
||||
* @return Repository
|
||||
*/
|
||||
public function getModel(): string;
|
||||
|
||||
/**
|
||||
* Get clean empty Model
|
||||
* @return Model
|
||||
*/
|
||||
public function getNewModel(): Model;
|
||||
public function setTable(string $table): Repository;
|
||||
|
||||
/**
|
||||
* Set up the Repository
|
||||
@ -69,195 +66,30 @@ interface Repository
|
||||
*/
|
||||
public function setup(): Repository;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTable(): string;
|
||||
|
||||
/**
|
||||
* @param string $table
|
||||
* @return Repository
|
||||
*/
|
||||
public function setTable(string $table): Repository;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getColumnMappings(): array;
|
||||
|
||||
/**
|
||||
* @param Mapping $mapping
|
||||
* @return Repository
|
||||
*/
|
||||
public function addColumnMapping(Mapping $mapping): Repository;
|
||||
|
||||
/**
|
||||
* @param array $mappings
|
||||
* @return Repository
|
||||
*/
|
||||
public function setColumnMappings(array $mappings): Repository;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getPropertyMappings(): array;
|
||||
|
||||
/**
|
||||
* @param Mapping $mapping
|
||||
* @return Repository
|
||||
*/
|
||||
public function addPropertyMapping(Mapping $mapping): Repository;
|
||||
|
||||
/**
|
||||
* @param array $mappings
|
||||
* @return Repository
|
||||
*/
|
||||
public function setPropertyMappings(array $mappings): Repository;
|
||||
|
||||
/**
|
||||
* Set columns in table
|
||||
* @param array $columns
|
||||
* @return Repository
|
||||
*/
|
||||
public function setColumns(array $columns): Repository;
|
||||
|
||||
/**
|
||||
* @param string $column
|
||||
* @return Repository
|
||||
*/
|
||||
public function addColumn(string $column): Repository;
|
||||
|
||||
/**
|
||||
* Get table columns
|
||||
* @return array
|
||||
*/
|
||||
public function getColumns(): array;
|
||||
|
||||
/**
|
||||
* Get Model properties
|
||||
* @return array
|
||||
*/
|
||||
public function getProperties(): array;
|
||||
|
||||
/**
|
||||
* @param string $property
|
||||
* @param $value
|
||||
* @return Repository
|
||||
*/
|
||||
public function addProperty(string $property): Repository;
|
||||
|
||||
/**
|
||||
* Set Model properties
|
||||
* @param array $properties
|
||||
* @return Repository
|
||||
*/
|
||||
public function setProperties(array $properties): Repository;
|
||||
|
||||
/**
|
||||
* Set required columns
|
||||
* Optional
|
||||
* @param array $columns
|
||||
* @return Repository
|
||||
*/
|
||||
public function setRequired(array $columns): Repository;
|
||||
|
||||
/**
|
||||
* @param string $column
|
||||
* @return Repository
|
||||
*/
|
||||
public function addRequired(string $column): Repository;
|
||||
|
||||
/**
|
||||
* Get required columns
|
||||
* @return array
|
||||
*/
|
||||
public function getRequired(): array;
|
||||
|
||||
/**
|
||||
* Set optional columns
|
||||
* @param array $columns
|
||||
* @return Repository
|
||||
*/
|
||||
public function setOptional(array $columns): Repository;
|
||||
|
||||
/**
|
||||
* @param string $column
|
||||
* @return Repository
|
||||
*/
|
||||
public function addOptional(string $column): Repository;
|
||||
|
||||
/**
|
||||
* Get optional columns
|
||||
* @return array
|
||||
*/
|
||||
public function getOptional(): array;
|
||||
|
||||
/**
|
||||
* Get Model method
|
||||
* @param string $property
|
||||
* @param bool $get
|
||||
* @return string
|
||||
*/
|
||||
public function getMethod(string $property, bool $get = true): string;
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @return string
|
||||
*/
|
||||
public function getProperty(string $method): string;
|
||||
|
||||
/**
|
||||
* Fill empty Model with data
|
||||
* @param Model $model
|
||||
* @param array $data
|
||||
* @return Model
|
||||
*/
|
||||
public function fillData(Model $model, array $data): Model;
|
||||
|
||||
/**
|
||||
* Fill data array with Model values. Accepts a preset data array
|
||||
* @param Model $model
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function mapArray(Model $model, array $data): array;
|
||||
|
||||
/**
|
||||
* Transform result array to Model
|
||||
* @param array $data
|
||||
* @return Model
|
||||
*/
|
||||
public function load(array $data): Model;
|
||||
|
||||
/**
|
||||
* Save Model to table
|
||||
* @param Model $model
|
||||
* @return void
|
||||
*/
|
||||
public function save(Model $model): void;
|
||||
|
||||
public function save(Model &$model): void;
|
||||
/**
|
||||
* Update table value with Model
|
||||
* @param Model $model
|
||||
* @return void
|
||||
*/
|
||||
public function update(Model $model): void;
|
||||
|
||||
public function update(Model $model, Model $old): void;
|
||||
/**
|
||||
* Create new Model with data
|
||||
* @param array $data
|
||||
* @return Model
|
||||
*/
|
||||
public function create(array $data): Model;
|
||||
|
||||
/**
|
||||
* Edit Model with data
|
||||
* @param Model $model
|
||||
* @param array $data
|
||||
* @return Model
|
||||
*/
|
||||
public function edit(Model $model, array $data): Model;
|
||||
|
||||
/**
|
||||
* Delete Model from table
|
||||
* @param Model $model
|
||||
@ -271,7 +103,6 @@ interface Repository
|
||||
* @return Model
|
||||
*/
|
||||
public function fetchById(int $id): Model;
|
||||
|
||||
/**
|
||||
* Fetch all Models
|
||||
* @return array
|
||||
|
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
namespace ProVM\Implement\Model\Mapping;
|
||||
|
||||
use ProVM\Alias\Model\Mapping;
|
||||
|
||||
class Basic extends Mapping
|
||||
{
|
||||
public function __construct(string $input, string $output)
|
||||
{
|
||||
$this->setInputName($input)
|
||||
->setOutputName($output)
|
||||
->setTransformation(function($item) {
|
||||
return $item;
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user