73 lines
3.1 KiB
PHP
73 lines
3.1 KiB
PHP
<?php
|
|
namespace Aldarien\Common\Definition;
|
|
|
|
use Psr\Container\ContainerInterface;
|
|
use Aldarien\Common\Factory\Model as ModelFactory;
|
|
|
|
interface Model extends \JsonSerializable {
|
|
/**
|
|
* Get table name
|
|
* @param string $model_class Model class
|
|
* @return string Return model table name
|
|
*/
|
|
public static function getTable(string $model_class): string;
|
|
/**
|
|
* Set container for dependency injection
|
|
* @param ContainerInterface $container Dependency injection container
|
|
* @return Model Returns $this
|
|
*/
|
|
public function setContainer(ContainerInterface $container): Model;
|
|
/**
|
|
* Transitions save, rolls back on exception
|
|
* @return mixed BaseModel::save
|
|
*/
|
|
public function save();
|
|
/**
|
|
* Child relationship
|
|
* @param string $parent_class Parent model class
|
|
* @param array $id_definitions ['self_key' => '<parent_table|singular>_id', 'parent_key' => 'id']
|
|
* @return Model Return parent model
|
|
*/
|
|
public function childOf(string $parent_class, array $id_definitions);
|
|
/**
|
|
* Parent relationship
|
|
* @param string $child_class Child model class
|
|
* @param array $id_definitions ['self_key' => 'id', 'child_key' => '<self_table|singular>_id']
|
|
* @return ModelFactory ModelFactory for modification before returning model
|
|
*/
|
|
public function parentOf(string $child_class, array $id_definitions): ModelFactory;
|
|
/**
|
|
* Parent relationship to one
|
|
* @param string $child_class Child model class
|
|
* @param array $id_definitions ['self_key' => 'id', 'child_key' => '<self_table|singular>_id']
|
|
* @return Model Return child model
|
|
*/
|
|
public function parentOfOne(string $child_class, array $id_definitions);
|
|
/**
|
|
* Parent relationship to many
|
|
* @param string $child_class Child model class
|
|
* @param array $id_definitions ['self_key' => 'id', 'child_key' => '<self_table|singular>_id']
|
|
* @return array Return array with child models
|
|
*/
|
|
public function parentOfMany(string $child_class, array $id_definitions);
|
|
/**
|
|
* Many to Many relationship
|
|
* @param string $sibling_class Sibling model class
|
|
* @param string $table_through Table connecting siblings
|
|
* @param array $id_definitions ['sibling_through_key' => '<sibling_table|singular>_id',
|
|
* 'sibling_key' => 'id',
|
|
* 'self_through_key' => '<self_table|singular>_id',
|
|
* 'self_key' => 'id'
|
|
* ]
|
|
* @return array Return array with sibling models
|
|
*/
|
|
public function siblingOf(string $sibling_class, string $table_through, array $id_definitions): ModelFactory;
|
|
public function siblingOfOne(string $sibling_class, string $table_through, array $id_definitions);
|
|
public function siblingOfMany(string $sibling_class, string $table_through, array $id_definitions);
|
|
/**
|
|
* Cast to array
|
|
* @return array Return array with all columns, can be overriden to include children
|
|
*/
|
|
public function toArray(): array;
|
|
}
|