Working Collections. Targeting PHP8.0.
This commit is contained in:
parent
7391011edd
commit
a563e01b76
51 changed files with 235 additions and 896 deletions
|
|
@ -10,7 +10,7 @@
|
|||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.4",
|
||||
"php": ">=8.0",
|
||||
"ext-simplexml": "*",
|
||||
"gone.io/twig-extension-inflection": "^1.0",
|
||||
"gone.io/twig-extension-transform": "^1.0",
|
||||
|
|
|
|||
43
src/Abstracts/AbstractCollection.php
Normal file
43
src/Abstracts/AbstractCollection.php
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Benzine\ORM\Abstracts;
|
||||
|
||||
use Exception;
|
||||
use Traversable;
|
||||
|
||||
abstract class AbstractCollection
|
||||
{
|
||||
protected array $contained = [];
|
||||
|
||||
public function getIterator()
|
||||
{
|
||||
return new \ArrayIterator($this->contained);
|
||||
}
|
||||
|
||||
public function offsetExists($offset) : bool
|
||||
{
|
||||
return isset($this->contained[$offset]);
|
||||
}
|
||||
|
||||
public function offsetUnset($offset) : void
|
||||
{
|
||||
$this->unset($this->contained[$offset]);
|
||||
}
|
||||
|
||||
public function serialize() : string
|
||||
{
|
||||
return serialize($this->contained);
|
||||
}
|
||||
|
||||
public function unserialize($data) : void
|
||||
{
|
||||
$this->contained = unserialize($data);
|
||||
}
|
||||
|
||||
public function count() : int
|
||||
{
|
||||
return count($this->contained);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Benzine\ORM\Abstracts;
|
||||
|
||||
use Benzine\ORM\Interfaces\CollectionsInterface;
|
||||
use Benzine\ORM\TabularData;
|
||||
use Laminas\Db\ResultSet\ResultSet;
|
||||
use Laminas\Db\Sql;
|
||||
|
|
@ -15,13 +16,15 @@ abstract class AbstractService
|
|||
|
||||
abstract public function getTermSingular(): string;
|
||||
|
||||
abstract public function getNewTableGatewayInstance(): AbstractTableGateway;
|
||||
abstract protected function getNewTableGatewayInstance(): AbstractTableGateway;
|
||||
|
||||
abstract protected function getNewCollectionInstance(): AbstractCollection;
|
||||
|
||||
/**
|
||||
* @param null|array|\Closure[] $wheres
|
||||
* @param null|Sql\Expression|string $order
|
||||
*
|
||||
* @return AbstractModel[]
|
||||
* @return CollectionsInterface
|
||||
*/
|
||||
public function getAll(
|
||||
int $limit = null,
|
||||
|
|
@ -29,7 +32,7 @@ abstract class AbstractService
|
|||
array $wheres = null,
|
||||
$order = null,
|
||||
string $orderDirection = null
|
||||
) {
|
||||
) : CollectionsInterface {
|
||||
/** @var AbstractTableGateway $tableGateway */
|
||||
$tableGateway = $this->getNewTableGatewayInstance();
|
||||
[$matches, $count] = $tableGateway->fetchAll(
|
||||
|
|
@ -39,27 +42,26 @@ abstract class AbstractService
|
|||
$order,
|
||||
null !== $orderDirection ? $orderDirection : Sql\Select::ORDER_ASCENDING
|
||||
);
|
||||
$return = [];
|
||||
|
||||
$collection = $this->getNewCollectionInstance();
|
||||
|
||||
if ($matches instanceof ResultSet) {
|
||||
foreach ($matches as $match) {
|
||||
$return[] = $match;
|
||||
}
|
||||
$collection->fromResultSet($matches);
|
||||
}
|
||||
|
||||
return $return;
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|string $distinctColumn
|
||||
* @param null|array|\Closure[] $wheres
|
||||
*
|
||||
* @return AbstractModel[]
|
||||
* @return AbstractCollection
|
||||
*/
|
||||
public function getDistinct(
|
||||
string $distinctColumn,
|
||||
array $wheres = null
|
||||
) {
|
||||
) : AbstractCollection {
|
||||
/** @var AbstractTableGateway $tableGateway */
|
||||
$tableGateway = $this->getNewTableGatewayInstance();
|
||||
[$matches, $count] = $tableGateway->fetchDistinct(
|
||||
|
|
@ -67,24 +69,23 @@ abstract class AbstractService
|
|||
$wheres
|
||||
);
|
||||
|
||||
$return = [];
|
||||
$collection = $this->getNewCollectionInstance();
|
||||
|
||||
if ($matches instanceof ResultSet) {
|
||||
foreach ($matches as $match) {
|
||||
$return[] = $match;
|
||||
}
|
||||
$collection->fromResultSet($matches);
|
||||
}
|
||||
|
||||
return $return;
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|array|\Closure[] $wheres
|
||||
*
|
||||
* @return int
|
||||
* @return integer
|
||||
*/
|
||||
public function countAll(
|
||||
array $wheres = null
|
||||
) {
|
||||
) : integer {
|
||||
/** @var AbstractTableGateway $tableGateway */
|
||||
$tableGateway = $this->getNewTableGatewayInstance();
|
||||
|
||||
|
|
@ -121,7 +122,7 @@ abstract class AbstractService
|
|||
|
||||
abstract public function getByField(string $field, $value, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): ?AbstractModel;
|
||||
|
||||
abstract public function getManyByField(string $field, $value, int $limit = null, int $offset = null, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): ?array;
|
||||
abstract public function getManyByField(string $field, $value, int $limit = null, int $offset = null, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): AbstractCollection;
|
||||
|
||||
abstract public function countByField(string $field, $value): int;
|
||||
|
||||
|
|
|
|||
7
src/Exception/CollectionException.php
Normal file
7
src/Exception/CollectionException.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Benzine\ORM\Exception;
|
||||
|
||||
class CollectionException extends BenzineOrmException
|
||||
{
|
||||
}
|
||||
80
src/Generator/Templates/Collections/basecollection.php.twig
Normal file
80
src/Generator/Templates/Collections/basecollection.php.twig
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace {{ namespace }}\Collections\Base;
|
||||
|
||||
use Benzine\ORM\Abstracts;
|
||||
use Benzine\ORM\Interfaces;
|
||||
use Benzine\ORM\Exception;
|
||||
use {{ namespace }}\Models;
|
||||
use Laminas\Db\ResultSet\ResultSet;
|
||||
|
||||
{% include '_overwrite_warning.twig' %}
|
||||
|
||||
abstract class AbstractBase{{ class_name }}Collection
|
||||
extends Abstracts\AbstractCollection
|
||||
implements Interfaces\CollectionsInterface,
|
||||
\IteratorAggregate,
|
||||
\ArrayAccess,
|
||||
\Serializable,
|
||||
\Countable
|
||||
{
|
||||
|
||||
{% for column in columns %}
|
||||
/**
|
||||
* @return {{ column.phptype }}[]
|
||||
*/
|
||||
public function getAll{{ column.getPropertyFunction|pluralize }}() : \Generator
|
||||
{
|
||||
foreach($this->contained as $contained){
|
||||
yield $contained->get{{ column.getPropertyFunction }}();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{ column.phptype }}|null ${{ column.getFieldSanitised }}
|
||||
*
|
||||
* @return Collections\{{ class_name }}Collection
|
||||
*/
|
||||
public function setAll{{ column.getPropertyFunction|pluralize }}({{ column.phptype }} ${{ column.getFieldSanitised }} = null) : self
|
||||
{
|
||||
foreach($this->contained as $contained){
|
||||
$contained->set{{ column.getPropertyFunction }}(${{ column.getFieldSanitised }});
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
{% endfor %}
|
||||
|
||||
public function fromResultSet(ResultSet $resultSet) : AbstractBase{{ class_name }}Collection
|
||||
{
|
||||
foreach($resultSet as $result){
|
||||
if(!$result instanceof Models\{{ class_name }}Model){
|
||||
throw new Exception\CollectionException(sprintf(
|
||||
"Creating a collection of {{ class_name }}Model, but somehow got given a %s",
|
||||
get_class($result)
|
||||
));
|
||||
}
|
||||
$this->contained[] = $result;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function offsetGet($offset) : Models\{{ class_name }}Model
|
||||
{
|
||||
return $this->contained[$offset];
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value) : void
|
||||
{
|
||||
if(!$value instanceof Models\{{ class_name }}Model){
|
||||
throw new Exception\CollectionException(sprintf(
|
||||
"Creating a collection of {{ class_name }}Model, but somehow got given a %s",
|
||||
get_class($value)
|
||||
));
|
||||
}
|
||||
|
||||
$this->contained[$offset] = $value;
|
||||
}
|
||||
}
|
||||
8
src/Generator/Templates/Collections/collection.php.twig
Normal file
8
src/Generator/Templates/Collections/collection.php.twig
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
namespace {{ namespace }}\Collections;
|
||||
|
||||
class {{ class_name }}Collection extends Base\AbstractBase{{ class_name }}Collection
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
22
src/Generator/Templates/Controllers/basecontroller.php.twig
Normal file
22
src/Generator/Templates/Controllers/basecontroller.php.twig
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace {{ namespace }}\Controllers\Base;
|
||||
|
||||
use {{ namespace }}\Services;
|
||||
use Benzine\Controllers\AbstractCrudController;
|
||||
|
||||
{% include '_overwrite_warning.twig' %}
|
||||
|
||||
abstract class AbstractBase{{ class_name }}Controller extends AbstractCrudController
|
||||
{
|
||||
public const RESPONSIBLE_MODEL = '{{ class_name }}';
|
||||
|
||||
public function __construct(
|
||||
protected Services\{{ class_name }}Service $service
|
||||
) {}
|
||||
|
||||
public function getService() : Services\{{ class_name }}Service
|
||||
{
|
||||
return $this->service;
|
||||
}
|
||||
}
|
||||
|
|
@ -190,7 +190,7 @@ abstract class AbstractBase{{ class_name }}Model extends AbstractModel implement
|
|||
*
|
||||
* @return Models\{{ class_name }}Model
|
||||
*/
|
||||
public function set{{ column.getPropertyFunction }}({{ column.phptype }} ${{ column.getFieldSanitised }} = null): Models\{{ class_name }}Model
|
||||
public function set{{ column.getPropertyFunction }}({{ column.phptype }} ${{ column.getFieldSanitised }} = null): self
|
||||
{
|
||||
$this->{{ column.getFieldSanitised }} = ${{ column.getFieldSanitised }};
|
||||
|
||||
|
|
@ -429,19 +429,16 @@ abstract class AbstractBase{{ class_name }}Model extends AbstractModel implement
|
|||
${{ column.getDbField() }} = $data['{{ column.getDbFieldOptions|join("'] ?? $data['")|raw }}'] ?? null;
|
||||
{% endfor %}
|
||||
|
||||
$this
|
||||
{% for column in columns %}
|
||||
{% if column.getDbType == 'timestamp' %}
|
||||
->set{{ column.getPropertyFunction }}(
|
||||
$this->{{ column.getFieldSanitised }} =
|
||||
${{ column.getDbField() }} !== null
|
||||
? DateTime::createFromFormat("Y-m-d H:i:s", ${{ column.getDbField() }})
|
||||
: null
|
||||
)
|
||||
: null ;
|
||||
{% else %}
|
||||
->set{{ column.getPropertyFunction }}(${{ column.getDbField() }})
|
||||
$this->{{ column.getFieldSanitised }} = ${{ column.getDbField() }};
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
;
|
||||
|
||||
$this->__post_load();
|
||||
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace {{ namespace }}\Services\Base;
|
||||
|
||||
use {{ namespace }}\Collections;
|
||||
use {{ namespace }}\Models;
|
||||
use {{ namespace }}\TableGateways;
|
||||
use Laminas\Db\Sql\Expression;
|
||||
|
|
@ -15,69 +16,31 @@ use Benzine\ORM\Interfaces\ServiceInterface as ServiceInterface;
|
|||
|
||||
abstract class AbstractBase{{ class_name }}Service extends AbstractService implements ServiceInterface
|
||||
{
|
||||
// Related Objects Table Gateways
|
||||
{% for related_object in related_objects_shared|sort|unique %}
|
||||
{% if related_object.getRemoteClass != class_name %}
|
||||
protected TableGateways\{{ related_object.getRemoteClass }}TableGateway ${{ related_object.getRemoteVariable }}TableGateway;
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
// Remote Constraints Table Gateways
|
||||
{% for remote_constraint in remote_constraints %}
|
||||
{% if remote_contraint.getRemoteClass != class_name %}
|
||||
protected TableGateways\{{ remote_constraint.getLocalClass }}TableGateway ${{ remote_constraint.getLocalVariable }}TableGateway;
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
// Self Table Gateway
|
||||
protected TableGateways\{{ class_name }}TableGateway ${{ variable_name }}TableGateway;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
{% for related_object in related_objects_shared|sort|unique %}
|
||||
{% if related_object.getRemoteClass != class_name %}
|
||||
* @param TableGateways\{{ related_object.getRemoteClass }}TableGateway ${{ related_object.getRemoteVariable }}TableGateway
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% for remote_constraint in remote_constraints %}
|
||||
{% if remote_contraint.getRemoteClass != class_name %}
|
||||
* @param TableGateways\{{ remote_constraint.getLocalClass }}TableGateway ${{ remote_constraint.getLocalVariable }}TableGateway
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
* @param TableGateways\{{ class_name }}TableGateway ${{ variable_name }}TableGateway
|
||||
*/
|
||||
public function __construct(
|
||||
{% for related_object in related_objects_shared|sort|unique %}
|
||||
{% if related_object.getRemoteClass != class_name %}
|
||||
TableGateways\{{ related_object.getRemoteClass }}TableGateway ${{ related_object.getRemoteVariable }}TableGateway,
|
||||
private TableGateways\{{ related_object.getRemoteClass }}TableGateway ${{ related_object.getRemoteVariable }}TableGateway,
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% for remote_constraint in remote_constraints %}
|
||||
{% if remote_contraint.getRemoteClass != class_name %}
|
||||
TableGateways\{{ remote_constraint.getLocalClass }}TableGateway ${{ remote_constraint.getLocalVariable }}TableGateway,
|
||||
private TableGateways\{{ remote_constraint.getLocalClass }}TableGateway ${{ remote_constraint.getLocalVariable }}TableGateway,
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
TableGateways\{{ class_name }}TableGateway ${{ variable_name }}TableGateway
|
||||
) {
|
||||
{% for related_object in related_objects_shared|sort|unique %}
|
||||
{% if related_object.getRemoteClass != class_name %}
|
||||
$this->{{ related_object.getRemoteVariable }}TableGateway = ${{ related_object.getRemoteVariable }}TableGateway;
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% for remote_constraint in remote_constraints %}
|
||||
{% if remote_contraint.getRemoteClass != class_name %}
|
||||
$this->{{ remote_constraint.getLocalVariable }}TableGateway = ${{ remote_constraint.getLocalVariable }}TableGateway;
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
$this->{{ variable_name }}TableGateway = ${{ variable_name }}TableGateway;
|
||||
}
|
||||
private TableGateways\{{ class_name }}TableGateway ${{ variable_name }}TableGateway,
|
||||
private Collections\{{ class_name }}Collection ${{ variable_name }}Collection
|
||||
) {}
|
||||
|
||||
public function getNewTableGatewayInstance(): TableGateways\{{ class_name }}TableGateway
|
||||
protected function getNewTableGatewayInstance(): TableGateways\{{ class_name }}TableGateway
|
||||
{
|
||||
return $this->{{ variable_name }}TableGateway;
|
||||
}
|
||||
|
||||
protected function getNewCollectionInstance(): Collections\{{ class_name }}Collection
|
||||
{
|
||||
return $this->{{ variable_name }}Collection;
|
||||
}
|
||||
|
||||
public function getNewModelInstance($dataExchange = []): Models\{{ class_name }}Model
|
||||
{
|
||||
return $this->{{ variable_name }}TableGateway->getNewModelInstance($dataExchange);
|
||||
|
|
@ -90,7 +53,7 @@ abstract class AbstractBase{{ class_name }}Service extends AbstractService imple
|
|||
* @param null|Expression|string $order
|
||||
* @param null|string $orderDirection
|
||||
*
|
||||
* @return Models\{{ class_name }}Model[]
|
||||
* @return Collections\{{ class_name }}Collection
|
||||
*/
|
||||
public function getAll(
|
||||
int $limit = null,
|
||||
|
|
@ -98,7 +61,7 @@ abstract class AbstractBase{{ class_name }}Service extends AbstractService imple
|
|||
array $wheres = null,
|
||||
$order = null,
|
||||
string $orderDirection = null
|
||||
) {
|
||||
) : Collections\{{ class_name }}Collection {
|
||||
return parent::getAll(
|
||||
$limit,
|
||||
$offset,
|
||||
|
|
@ -148,7 +111,7 @@ abstract class AbstractBase{{ class_name }}Service extends AbstractService imple
|
|||
* @param null|string $orderBy Field to sort by
|
||||
* @param null|string $orderDirection Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
*
|
||||
* @return null|Models\{{ class_name }}Model[]
|
||||
* @return Collections\{{ class_name }}Collection
|
||||
*/
|
||||
public function getManyByWhere(
|
||||
Where $where,
|
||||
|
|
@ -156,8 +119,7 @@ abstract class AbstractBase{{ class_name }}Service extends AbstractService imple
|
|||
int $offset = null,
|
||||
$orderBy = null,
|
||||
$orderDirection = Select::ORDER_ASCENDING
|
||||
): ?array
|
||||
{
|
||||
): Collections\{{ class_name }}Collection {
|
||||
${{ variable_name }}Table = $this->getNewTableGatewayInstance();
|
||||
|
||||
return ${{ variable_name }}Table->getManyByWhere($where, $limit, $offset, $orderBy, $orderDirection);
|
||||
|
|
@ -188,7 +150,7 @@ abstract class AbstractBase{{ class_name }}Service extends AbstractService imple
|
|||
* @param null|string $orderBy Field to sort by
|
||||
* @param null|string $orderDirection Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
*
|
||||
* @return null|Models\{{ class_name }}Model[]
|
||||
* @return Collections\{{ class_name }}Collection
|
||||
*/
|
||||
public function getManyByField(
|
||||
string $field,
|
||||
|
|
@ -197,8 +159,7 @@ abstract class AbstractBase{{ class_name }}Service extends AbstractService imple
|
|||
int $offset = null,
|
||||
$orderBy = null,
|
||||
$orderDirection = Select::ORDER_ASCENDING
|
||||
): ?array
|
||||
{
|
||||
) : Collections\{{ class_name }}Collection {
|
||||
${{ variable_name }}Table = $this->getNewTableGatewayInstance();
|
||||
|
||||
return ${{ variable_name }}Table->getManyByField($field, $value, $limit, $offset, $orderBy, $orderDirection);
|
||||
|
|
@ -259,10 +220,14 @@ abstract class AbstractBase{{ class_name }}Service extends AbstractService imple
|
|||
* @param string $orderDirection Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
* @param int $limit Limit the number of matches returned
|
||||
*
|
||||
* @return Models\{{ class_name }}Model[]
|
||||
* @return Collections\{{ class_name }}Collection
|
||||
*/
|
||||
public function getManyMatching($keyValue = [], $orderBy = null, $orderDirection = Select::ORDER_ASCENDING, int $limit = null): ?array
|
||||
{
|
||||
public function getManyMatching(
|
||||
$keyValue = [],
|
||||
$orderBy = null,
|
||||
$orderDirection = Select::ORDER_ASCENDING,
|
||||
int $limit = null
|
||||
) : Collections\{{ class_name }}Collection {
|
||||
${{ variable_name }}Table = $this->getNewTableGatewayInstance();
|
||||
|
||||
return ${{ variable_name }}Table->getManyMatching($keyValue, $orderBy, $orderDirection, $limit);
|
||||
|
|
@ -323,7 +288,7 @@ abstract class AbstractBase{{ class_name }}Service extends AbstractService imple
|
|||
/**
|
||||
* Get a version of this object pre-populated with nonsense.
|
||||
*
|
||||
* @returns Models\{{ class_name }}Model
|
||||
* @return Models\{{ class_name }}Model
|
||||
*/
|
||||
public function getMockObject(): Models\{{ class_name }}Model
|
||||
{
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace {{ namespace }}\Controllers\Base;
|
||||
|
||||
use {{ namespace }}\Services;
|
||||
use Benzine\Controllers\Abstracts\CrudController as AbstractCrudController;
|
||||
|
||||
{% include '_overwrite_warning.twig' %}
|
||||
|
||||
abstract class AbstractBase{{ class_name }}Controller extends AbstractCrudController
|
||||
{
|
||||
public const RESPONSIBLE_MODEL = '{{ class_name }}';
|
||||
|
||||
public function __construct(
|
||||
Services\{{ class_name }}Service ${{ variable_name }}
|
||||
) {
|
||||
$this->service = ${{ variable_name }};
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns Services\{{ class_name }}Service
|
||||
*/
|
||||
public function getService(): Services\{{ class_name }}Service
|
||||
{
|
||||
return parent::getService();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,118 +0,0 @@
|
|||
<?php
|
||||
|
||||
use {{ namespace }}\Models\{{ class_name }}Model;
|
||||
use {{ namespace }}\TableGateways\{{ class_name }}TableGateway;
|
||||
use Benzine\Router\Route;
|
||||
|
||||
if (!defined('DEFAULT_ROUTE_ACCESS_MODE')) {
|
||||
define('DEFAULT_ROUTE_ACCESS_MODE', 'public');
|
||||
}
|
||||
|
||||
$exampleExistingObjectFindFunction = function () {
|
||||
$DIContainer = App::Instance()->getContainer();
|
||||
|
||||
/** @var {{ class_name }}TableGateway $exampleExistingObjectTableGateway */
|
||||
$exampleExistingObjectTableGateway = $DIContainer->get({{ class_name }}TableGateway::class);
|
||||
|
||||
/** @var {{ class_name }}Model $exampleExistingObject */
|
||||
$exampleExistingObject = $exampleExistingObjectTableGateway->getNewMockModelInstance();
|
||||
if (method_exists($exampleExistingObject, 'setId')) {
|
||||
$exampleExistingObject->setId(rand(1000000, 9999999));
|
||||
}
|
||||
|
||||
return $exampleExistingObject;
|
||||
};
|
||||
|
||||
// Router proper begins
|
||||
$router = \⌬\Router\Router::Instance()
|
||||
->addRoute(
|
||||
Route::Factory()
|
||||
->setName('{{ class_name }} List')
|
||||
->setCallback(\{{ namespace }}\Controllers\{{ class_name }}Controller::class.':listRequest')
|
||||
->setSDKClass('{{ class_name }}')
|
||||
->setSDKFunction('list')
|
||||
->setSDKTemplate('list')
|
||||
->setRouterPattern('/v1/{{ controller_route }}')
|
||||
->setHttpEndpoint('/v1/{{ controller_route }}')
|
||||
->setHttpMethod('GET')
|
||||
->setSingular('{{ object_name_singular }}')
|
||||
->setPlural('{{ object_name_plural }}')
|
||||
->setProperties([
|
||||
{% for column in columns %}
|
||||
'{{ column.getPropertyFunction }}',
|
||||
{% endfor %}
|
||||
])
|
||||
->setPropertyOptions([
|
||||
{% for column in columns %}
|
||||
{% if column.getDbType == 'enum' and column.getPhpType == 'string' %}
|
||||
'{{ column.getPropertyFunction }}' => [
|
||||
{% for permittedValue in column.getPermittedValues %}
|
||||
"{{ permittedValue }}",
|
||||
{% endfor %}
|
||||
],
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
])
|
||||
->setAccess(DEFAULT_ROUTE_ACCESS_MODE)
|
||||
->setExampleEntityFindFunction($exampleExistingObjectFindFunction)
|
||||
)
|
||||
->addRoute(
|
||||
Route::Factory()
|
||||
->setName('{{ class_name }} Create')
|
||||
->setCallback(\{{ namespace }}\Controllers\{{ class_name }}Controller::class.':createRequest')
|
||||
->setSDKClass('{{ class_name }}')
|
||||
->setSDKFunction('create')
|
||||
->setSDKTemplate('create')
|
||||
->setRouterPattern('/v1/{{ controller_route }}')
|
||||
->setHttpEndpoint('/v1/{{ controller_route }}')
|
||||
->setHttpMethod('PUT')
|
||||
->setSingular('{{ object_name_singular }}')
|
||||
->setPlural('{{ object_name_plural }}')
|
||||
->setProperties([
|
||||
{% for column in columns %}
|
||||
'{{ column.getPropertyFunction }}',
|
||||
{% endfor %}
|
||||
])
|
||||
->setAccess(DEFAULT_ROUTE_ACCESS_MODE)
|
||||
->setExampleEntityFindFunction($exampleExistingObjectFindFunction)
|
||||
)
|
||||
->addRoute(
|
||||
Route::Factory()
|
||||
->setName('{{ class_name }} Get')
|
||||
->setCallback(\{{ namespace }}\Controllers\{{ class_name }}Controller::class.':getRequest')
|
||||
->setSDKClass('{{ class_name }}')
|
||||
->setSDKFunction('get')
|
||||
->setSDKTemplate('get')
|
||||
->setRouterPattern('/v1/{{ controller_route }}/{id}')
|
||||
->setHttpEndpoint('/v1/{{ controller_route }}/id')
|
||||
->setHttpMethod('GET')
|
||||
->setSingular('{{ object_name_singular }}')
|
||||
->setPlural('{{ object_name_plural }}')
|
||||
->setProperties([
|
||||
{% for column in columns %}
|
||||
'{{ column.getPropertyFunction }}',
|
||||
{% endfor %}
|
||||
])
|
||||
->setAccess(DEFAULT_ROUTE_ACCESS_MODE)
|
||||
->setExampleEntityFindFunction($exampleExistingObjectFindFunction)
|
||||
)
|
||||
->addRoute(
|
||||
Route::Factory()
|
||||
->setName('{{ class_name }} Delete')
|
||||
->setCallback(\{{ namespace }}\Controllers\{{ class_name }}Controller::class.':deleteRequest')
|
||||
->setSDKClass('{{ class_name }}')
|
||||
->setSDKFunction('delete')
|
||||
->setSDKTemplate('delete')
|
||||
->setRouterPattern('/v1/{{ controller_route }}/{id}')
|
||||
->setHttpEndpoint('/v1/{{ controller_route }}/id')
|
||||
->setHttpMethod('DELETE')
|
||||
->setSingular('{{ object_name_singular }}')
|
||||
->setPlural('{{ object_name_plural }}')
|
||||
->setProperties([
|
||||
{% for column in columns %}
|
||||
'{{ column.getPropertyFunction }}',
|
||||
{% endfor %}
|
||||
])
|
||||
->setAccess(DEFAULT_ROUTE_ACCESS_MODE)
|
||||
)
|
||||
;
|
||||
10
src/Interfaces/CollectionsInterface.php
Normal file
10
src/Interfaces/CollectionsInterface.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Benzine\ORM\Interfaces;
|
||||
|
||||
use Laminas\Db\ResultSet\ResultSet;
|
||||
|
||||
interface CollectionsInterface
|
||||
{
|
||||
public function fromResultSet(ResultSet $resultSet) : CollectionsInterface;
|
||||
}
|
||||
|
|
@ -91,7 +91,7 @@ class Laminator
|
|||
$this->setWorkPath(self::$benzineConfig->get(ConfigurationService::KEY_APP_ROOT));
|
||||
}
|
||||
|
||||
$this->loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/Generator/templates');
|
||||
$this->loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/Generator/Templates');
|
||||
$this->twig = new \Twig\Environment($this->loader, ['debug' => true]);
|
||||
$this->twig->addExtension(new \Twig\Extension\DebugExtension());
|
||||
$this->twig->addExtension(new TransformExtension());
|
||||
|
|
@ -417,8 +417,11 @@ class Laminator
|
|||
$this->renderToFile(true, "tests/Models/Generated/{$model->getClassName()}Test.php", 'Models/tests.models.php.twig', $model->getRenderDataset());
|
||||
$this->renderToFile(true, "src/TableGateways/Base/AbstractBase{$model->getClassName()}TableGateway.php", 'Models/basetable.php.twig', $model->getRenderDataset());
|
||||
$this->renderToFile(false, "src/TableGateways/{$model->getClassName()}TableGateway.php", 'Models/table.php.twig', $model->getRenderDataset());
|
||||
$this->renderToFile(true, "src/Collections/Base/AbstractBase{$model->getClassName()}Collection.php", 'Collections/basecollection.php.twig', $model->getRenderDataset());
|
||||
$this->renderToFile(false, "src/Collections/{$model->getClassName()}Collection.php", 'Collections/collection.php.twig', $model->getRenderDataset());
|
||||
}
|
||||
|
||||
|
||||
// "Service" suite
|
||||
if (in_array('Services', $this->getBenzineConfig()->getLaminatorTemplates(), true)) {
|
||||
$this->renderToFile(true, "src/Services/Base/AbstractBase{$model->getClassName()}Service.php", 'Services/baseservice.php.twig', $model->getRenderDataset());
|
||||
|
|
@ -436,11 +439,6 @@ class Laminator
|
|||
if (in_array('Endpoints', $this->getBenzineConfig()->getLaminatorTemplates(), true)) {
|
||||
$this->renderToFile(true, "tests/Api/Generated/{$model->getClassName()}EndpointTest.php", 'ApiEndpoints/tests.endpoints.php.twig', $model->getRenderDataset());
|
||||
}
|
||||
|
||||
// "Routes" suite
|
||||
if (in_array('Routes', $this->getBenzineConfig()->getLaminatorTemplates(), true)) {
|
||||
$this->renderToFile(true, "src/Routes/Generated/{$model->getClassName()}Route.php", 'Router/route.php.twig', $model->getRenderDataset());
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,17 @@
|
|||
|
||||
namespace Benzine\ORM\Migrations;
|
||||
|
||||
use Benzine\ORM\Tests\App;
|
||||
use Faker\Generator;
|
||||
use Monolog\Logger;
|
||||
|
||||
abstract class AbstractSeed extends \Phinx\Seed\AbstractSeed
|
||||
{
|
||||
protected Generator $faker;
|
||||
protected Logger $log;
|
||||
public function __construct()
|
||||
{
|
||||
$this->faker = App::Instance()->get(Generator::class);
|
||||
$this->log = App::Instance()->get(Logger::class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,222 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Benzine\ORM\Tests\Services\Base;
|
||||
|
||||
use Benzine\ORM\Tests\Models;
|
||||
use Benzine\ORM\Tests\TableGateways;
|
||||
use Laminas\Db\Sql\Expression;
|
||||
use Laminas\Db\Sql\Select;
|
||||
use Laminas\Db\Sql\Predicate;
|
||||
use Laminas\Db\Sql\Where;
|
||||
use Benzine\ORM\Abstracts\AbstractService as AbstractService;
|
||||
use Benzine\ORM\Interfaces\ServiceInterface as ServiceInterface;
|
||||
|
||||
/** ___ __
|
||||
* / _ \___ ____ ___ ____ ____/ /
|
||||
* / // / _ `/ _ \/ _ `/ -_) __/_/
|
||||
* /____/\_,_/_//_/\_, /\__/_/ (_)
|
||||
* /___/.
|
||||
*
|
||||
* Anything in this file is prone to being overwritten!
|
||||
*
|
||||
* This file was programmatically generated. To modify
|
||||
* this classes behaviours, do so in the class that
|
||||
* extends this, or modify the Laminator Template!
|
||||
*/
|
||||
abstract class BaseBlogPostsAbstractService extends AbstractService implements ServiceInterface
|
||||
{
|
||||
// Related Objects Table Gateways
|
||||
protected TableGateways\UsersTableGateway $usersTableGateway;
|
||||
|
||||
// Remote Constraints Table Gateways
|
||||
|
||||
// Self Table Gateway
|
||||
protected TableGateways\BlogPostsTableGateway $blogPostsTableGateway;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param TableGateways\UsersTableGateway $usersTableGateway
|
||||
* @param TableGateways\BlogPostsTableGateway $blogPostsTableGateway
|
||||
*/
|
||||
public function __construct(
|
||||
TableGateways\UsersTableGateway $usersTableGateway,
|
||||
TableGateways\BlogPostsTableGateway $blogPostsTableGateway
|
||||
) {
|
||||
$this->usersTableGateway = $usersTableGateway;
|
||||
$this->blogPostsTableGateway = $blogPostsTableGateway;
|
||||
}
|
||||
|
||||
public function getNewTableGatewayInstance(): TableGateways\BlogPostsTableGateway
|
||||
{
|
||||
return $this->blogPostsTableGateway;
|
||||
}
|
||||
|
||||
public function getNewModelInstance($dataExchange = []): Models\BlogPostsModel
|
||||
{
|
||||
return $this->blogPostsTableGateway->getNewModelInstance($dataExchange);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|int $limit
|
||||
* @param null|int $offset
|
||||
* @param null|array|\Closure[] $wheres
|
||||
* @param null|Expression|string $order
|
||||
* @param null|string $orderDirection
|
||||
*
|
||||
* @return Models\BlogPostsModel[]
|
||||
*/
|
||||
public function getAll(
|
||||
int $limit = null,
|
||||
int $offset = null,
|
||||
array $wheres = null,
|
||||
$order = null,
|
||||
string $orderDirection = null
|
||||
) {
|
||||
return parent::getAll(
|
||||
$limit,
|
||||
$offset,
|
||||
$wheres,
|
||||
$order,
|
||||
$orderDirection
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param $value
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
*
|
||||
* @return null|Models\BlogPostsModel
|
||||
*/
|
||||
public function getByField(string $field, $value, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): ?Models\BlogPostsModel
|
||||
{
|
||||
/** @var TableGateways\BlogPostsTableGateway $blogPostsTable */
|
||||
$blogPostsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $blogPostsTable->getByField($field, $value, $orderBy, $orderDirection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param $value
|
||||
* @param $limit int
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
*
|
||||
* @return null|Models\BlogPostsModel[]
|
||||
*/
|
||||
public function getManyByField(string $field, $value, int $limit = null, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): ?array
|
||||
{
|
||||
/** @var TableGateways\BlogPostsTableGateway $blogPostsTable */
|
||||
$blogPostsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $blogPostsTable->getManyByField($field, $value, $limit, $orderBy, $orderDirection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param $value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countByField(string $field, $value): int
|
||||
{
|
||||
$blogPostsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $blogPostsTable->countByField($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Models\BlogPostsModel
|
||||
*/
|
||||
public function getRandom(): ?Models\BlogPostsModel
|
||||
{
|
||||
/** @var TableGateways\BlogPostsTableGateway $blogPostsTable */
|
||||
$blogPostsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $blogPostsTable->fetchRandom();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|\Closure|Predicate\PredicateInterface|string|Where $keyValue
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
*
|
||||
* @return Models\BlogPostsModel
|
||||
*/
|
||||
public function getMatching($keyValue = [], $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): ?Models\BlogPostsModel
|
||||
{
|
||||
/** @var TableGateways\BlogPostsTableGateway $blogPostsTable */
|
||||
$blogPostsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $blogPostsTable->getMatching($keyValue, $orderBy, $orderDirection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|\Closure|Predicate\PredicateInterface|string|Where $keyValue
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
* @param $limit int Limit the number of matches returned
|
||||
*
|
||||
* @return Models\BlogPostsModel[]
|
||||
*/
|
||||
public function getManyMatching($keyValue = [], $orderBy = null, $orderDirection = Select::ORDER_ASCENDING, int $limit = null): ?array
|
||||
{
|
||||
/** @var TableGateways\BlogPostsTableGateway $blogPostsTable */
|
||||
$blogPostsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $blogPostsTable->getManyMatching($keyValue, $orderBy, $orderDirection, $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dataExchange
|
||||
*
|
||||
* @return Models\BlogPostsModel
|
||||
*/
|
||||
public function createFromArray($dataExchange): Models\BlogPostsModel
|
||||
{
|
||||
/** @var TableGateways\BlogPostsTableGateway $blogPostsTable */
|
||||
$blogPostsTable = $this->getNewTableGatewayInstance();
|
||||
$blogPosts = $this->getNewModelInstance($dataExchange);
|
||||
|
||||
return $blogPostsTable->save($blogPosts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param mixed value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function deleteByField(string $field, $value): int
|
||||
{
|
||||
/** @var TableGateways\BlogPostsTableGateway $blogPostsTable */
|
||||
$blogPostsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $blogPostsTable->delete([$field => $value]);
|
||||
}
|
||||
|
||||
public function getTermPlural(): string
|
||||
{
|
||||
return 'BlogPosts';
|
||||
}
|
||||
|
||||
public function getTermSingular(): string
|
||||
{
|
||||
return 'BlogPosts';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a version of this object pre-populated with nonsense.
|
||||
*
|
||||
* @returns Models\BlogPostsModel
|
||||
*/
|
||||
public function getMockObject(): Models\BlogPostsModel
|
||||
{
|
||||
return $this->getNewTableGatewayInstance()->getNewMockModelInstance();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,218 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Benzine\ORM\Tests\Services\Base;
|
||||
|
||||
use Benzine\ORM\Tests\Models;
|
||||
use Benzine\ORM\Tests\TableGateways;
|
||||
use Laminas\Db\Sql\Expression;
|
||||
use Laminas\Db\Sql\Select;
|
||||
use Laminas\Db\Sql\Predicate;
|
||||
use Laminas\Db\Sql\Where;
|
||||
use Benzine\ORM\Abstracts\AbstractService as AbstractService;
|
||||
use Benzine\ORM\Interfaces\ServiceInterface as ServiceInterface;
|
||||
|
||||
/** ___ __
|
||||
* / _ \___ ____ ___ ____ ____/ /
|
||||
* / // / _ `/ _ \/ _ `/ -_) __/_/
|
||||
* /____/\_,_/_//_/\_, /\__/_/ (_)
|
||||
* /___/.
|
||||
*
|
||||
* Anything in this file is prone to being overwritten!
|
||||
*
|
||||
* This file was programmatically generated. To modify
|
||||
* this classes behaviours, do so in the class that
|
||||
* extends this, or modify the Laminator Template!
|
||||
*/
|
||||
abstract class BaseMigrationsAbstractService extends AbstractService implements ServiceInterface
|
||||
{
|
||||
// Related Objects Table Gateways
|
||||
|
||||
// Remote Constraints Table Gateways
|
||||
|
||||
// Self Table Gateway
|
||||
protected TableGateways\MigrationsTableGateway $migrationsTableGateway;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param TableGateways\MigrationsTableGateway $migrationsTableGateway
|
||||
*/
|
||||
public function __construct(
|
||||
TableGateways\MigrationsTableGateway $migrationsTableGateway
|
||||
) {
|
||||
$this->migrationsTableGateway = $migrationsTableGateway;
|
||||
}
|
||||
|
||||
public function getNewTableGatewayInstance(): TableGateways\MigrationsTableGateway
|
||||
{
|
||||
return $this->migrationsTableGateway;
|
||||
}
|
||||
|
||||
public function getNewModelInstance($dataExchange = []): Models\MigrationsModel
|
||||
{
|
||||
return $this->migrationsTableGateway->getNewModelInstance($dataExchange);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|int $limit
|
||||
* @param null|int $offset
|
||||
* @param null|array|\Closure[] $wheres
|
||||
* @param null|Expression|string $order
|
||||
* @param null|string $orderDirection
|
||||
*
|
||||
* @return Models\MigrationsModel[]
|
||||
*/
|
||||
public function getAll(
|
||||
int $limit = null,
|
||||
int $offset = null,
|
||||
array $wheres = null,
|
||||
$order = null,
|
||||
string $orderDirection = null
|
||||
) {
|
||||
return parent::getAll(
|
||||
$limit,
|
||||
$offset,
|
||||
$wheres,
|
||||
$order,
|
||||
$orderDirection
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param $value
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
*
|
||||
* @return null|Models\MigrationsModel
|
||||
*/
|
||||
public function getByField(string $field, $value, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): ?Models\MigrationsModel
|
||||
{
|
||||
/** @var TableGateways\MigrationsTableGateway $migrationsTable */
|
||||
$migrationsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $migrationsTable->getByField($field, $value, $orderBy, $orderDirection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param $value
|
||||
* @param $limit int
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
*
|
||||
* @return null|Models\MigrationsModel[]
|
||||
*/
|
||||
public function getManyByField(string $field, $value, int $limit = null, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): ?array
|
||||
{
|
||||
/** @var TableGateways\MigrationsTableGateway $migrationsTable */
|
||||
$migrationsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $migrationsTable->getManyByField($field, $value, $limit, $orderBy, $orderDirection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param $value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countByField(string $field, $value): int
|
||||
{
|
||||
$migrationsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $migrationsTable->countByField($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Models\MigrationsModel
|
||||
*/
|
||||
public function getRandom(): ?Models\MigrationsModel
|
||||
{
|
||||
/** @var TableGateways\MigrationsTableGateway $migrationsTable */
|
||||
$migrationsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $migrationsTable->fetchRandom();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|\Closure|Predicate\PredicateInterface|string|Where $keyValue
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
*
|
||||
* @return Models\MigrationsModel
|
||||
*/
|
||||
public function getMatching($keyValue = [], $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): ?Models\MigrationsModel
|
||||
{
|
||||
/** @var TableGateways\MigrationsTableGateway $migrationsTable */
|
||||
$migrationsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $migrationsTable->getMatching($keyValue, $orderBy, $orderDirection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|\Closure|Predicate\PredicateInterface|string|Where $keyValue
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
* @param $limit int Limit the number of matches returned
|
||||
*
|
||||
* @return Models\MigrationsModel[]
|
||||
*/
|
||||
public function getManyMatching($keyValue = [], $orderBy = null, $orderDirection = Select::ORDER_ASCENDING, int $limit = null): ?array
|
||||
{
|
||||
/** @var TableGateways\MigrationsTableGateway $migrationsTable */
|
||||
$migrationsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $migrationsTable->getManyMatching($keyValue, $orderBy, $orderDirection, $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dataExchange
|
||||
*
|
||||
* @return Models\MigrationsModel
|
||||
*/
|
||||
public function createFromArray($dataExchange): Models\MigrationsModel
|
||||
{
|
||||
/** @var TableGateways\MigrationsTableGateway $migrationsTable */
|
||||
$migrationsTable = $this->getNewTableGatewayInstance();
|
||||
$migrations = $this->getNewModelInstance($dataExchange);
|
||||
|
||||
return $migrationsTable->save($migrations);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param mixed value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function deleteByField(string $field, $value): int
|
||||
{
|
||||
/** @var TableGateways\MigrationsTableGateway $migrationsTable */
|
||||
$migrationsTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $migrationsTable->delete([$field => $value]);
|
||||
}
|
||||
|
||||
public function getTermPlural(): string
|
||||
{
|
||||
return 'Migrations';
|
||||
}
|
||||
|
||||
public function getTermSingular(): string
|
||||
{
|
||||
return 'Migrations';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a version of this object pre-populated with nonsense.
|
||||
*
|
||||
* @returns Models\MigrationsModel
|
||||
*/
|
||||
public function getMockObject(): Models\MigrationsModel
|
||||
{
|
||||
return $this->getNewTableGatewayInstance()->getNewMockModelInstance();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,218 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Benzine\ORM\Tests\Services\Base;
|
||||
|
||||
use Benzine\ORM\Tests\Models;
|
||||
use Benzine\ORM\Tests\TableGateways;
|
||||
use Laminas\Db\Sql\Expression;
|
||||
use Laminas\Db\Sql\Select;
|
||||
use Laminas\Db\Sql\Predicate;
|
||||
use Laminas\Db\Sql\Where;
|
||||
use Benzine\ORM\Abstracts\AbstractService as AbstractService;
|
||||
use Benzine\ORM\Interfaces\ServiceInterface as ServiceInterface;
|
||||
|
||||
/** ___ __
|
||||
* / _ \___ ____ ___ ____ ____/ /
|
||||
* / // / _ `/ _ \/ _ `/ -_) __/_/
|
||||
* /____/\_,_/_//_/\_, /\__/_/ (_)
|
||||
* /___/.
|
||||
*
|
||||
* Anything in this file is prone to being overwritten!
|
||||
*
|
||||
* This file was programmatically generated. To modify
|
||||
* this classes behaviours, do so in the class that
|
||||
* extends this, or modify the Laminator Template!
|
||||
*/
|
||||
abstract class BaseUsersAbstractService extends AbstractService implements ServiceInterface
|
||||
{
|
||||
// Related Objects Table Gateways
|
||||
|
||||
// Remote Constraints Table Gateways
|
||||
|
||||
// Self Table Gateway
|
||||
protected TableGateways\UsersTableGateway $usersTableGateway;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param TableGateways\UsersTableGateway $usersTableGateway
|
||||
*/
|
||||
public function __construct(
|
||||
TableGateways\UsersTableGateway $usersTableGateway
|
||||
) {
|
||||
$this->usersTableGateway = $usersTableGateway;
|
||||
}
|
||||
|
||||
public function getNewTableGatewayInstance(): TableGateways\UsersTableGateway
|
||||
{
|
||||
return $this->usersTableGateway;
|
||||
}
|
||||
|
||||
public function getNewModelInstance($dataExchange = []): Models\UsersModel
|
||||
{
|
||||
return $this->usersTableGateway->getNewModelInstance($dataExchange);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|int $limit
|
||||
* @param null|int $offset
|
||||
* @param null|array|\Closure[] $wheres
|
||||
* @param null|Expression|string $order
|
||||
* @param null|string $orderDirection
|
||||
*
|
||||
* @return Models\UsersModel[]
|
||||
*/
|
||||
public function getAll(
|
||||
int $limit = null,
|
||||
int $offset = null,
|
||||
array $wheres = null,
|
||||
$order = null,
|
||||
string $orderDirection = null
|
||||
) {
|
||||
return parent::getAll(
|
||||
$limit,
|
||||
$offset,
|
||||
$wheres,
|
||||
$order,
|
||||
$orderDirection
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param $value
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
*
|
||||
* @return null|Models\UsersModel
|
||||
*/
|
||||
public function getByField(string $field, $value, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): ?Models\UsersModel
|
||||
{
|
||||
/** @var TableGateways\UsersTableGateway $usersTable */
|
||||
$usersTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $usersTable->getByField($field, $value, $orderBy, $orderDirection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param $value
|
||||
* @param $limit int
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
*
|
||||
* @return null|Models\UsersModel[]
|
||||
*/
|
||||
public function getManyByField(string $field, $value, int $limit = null, $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): ?array
|
||||
{
|
||||
/** @var TableGateways\UsersTableGateway $usersTable */
|
||||
$usersTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $usersTable->getManyByField($field, $value, $limit, $orderBy, $orderDirection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param $value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countByField(string $field, $value): int
|
||||
{
|
||||
$usersTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $usersTable->countByField($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Models\UsersModel
|
||||
*/
|
||||
public function getRandom(): ?Models\UsersModel
|
||||
{
|
||||
/** @var TableGateways\UsersTableGateway $usersTable */
|
||||
$usersTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $usersTable->fetchRandom();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|\Closure|Predicate\PredicateInterface|string|Where $keyValue
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
*
|
||||
* @return Models\UsersModel
|
||||
*/
|
||||
public function getMatching($keyValue = [], $orderBy = null, $orderDirection = Select::ORDER_ASCENDING): ?Models\UsersModel
|
||||
{
|
||||
/** @var TableGateways\UsersTableGateway $usersTable */
|
||||
$usersTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $usersTable->getMatching($keyValue, $orderBy, $orderDirection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|\Closure|Predicate\PredicateInterface|string|Where $keyValue
|
||||
* @param $orderBy string Field to sort by
|
||||
* @param $orderDirection string Direction to sort (Select::ORDER_ASCENDING || Select::ORDER_DESCENDING)
|
||||
* @param $limit int Limit the number of matches returned
|
||||
*
|
||||
* @return Models\UsersModel[]
|
||||
*/
|
||||
public function getManyMatching($keyValue = [], $orderBy = null, $orderDirection = Select::ORDER_ASCENDING, int $limit = null): ?array
|
||||
{
|
||||
/** @var TableGateways\UsersTableGateway $usersTable */
|
||||
$usersTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $usersTable->getManyMatching($keyValue, $orderBy, $orderDirection, $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $dataExchange
|
||||
*
|
||||
* @return Models\UsersModel
|
||||
*/
|
||||
public function createFromArray($dataExchange): Models\UsersModel
|
||||
{
|
||||
/** @var TableGateways\UsersTableGateway $usersTable */
|
||||
$usersTable = $this->getNewTableGatewayInstance();
|
||||
$users = $this->getNewModelInstance($dataExchange);
|
||||
|
||||
return $usersTable->save($users);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param mixed value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function deleteByField(string $field, $value): int
|
||||
{
|
||||
/** @var TableGateways\UsersTableGateway $usersTable */
|
||||
$usersTable = $this->getNewTableGatewayInstance();
|
||||
|
||||
return $usersTable->delete([$field => $value]);
|
||||
}
|
||||
|
||||
public function getTermPlural(): string
|
||||
{
|
||||
return 'Users';
|
||||
}
|
||||
|
||||
public function getTermSingular(): string
|
||||
{
|
||||
return 'Users';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a version of this object pre-populated with nonsense.
|
||||
*
|
||||
* @returns Models\UsersModel
|
||||
*/
|
||||
public function getMockObject(): Models\UsersModel
|
||||
{
|
||||
return $this->getNewTableGatewayInstance()->getNewMockModelInstance();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue