2017 © Pedro Peláez
 

library crud

CRUD module for zend framework 3

image

vim/crud

CRUD module for zend framework 3

  • Wednesday, June 13, 2018
  • by vanvas
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

crud

Module for Zend Framework 3., (*1)

Installation

Installation of this module uses composer. For composer documentation, please refer to getcomposer.org., (*2)

composer require vim/crud

Register Vim\Crud in config/modules.config.php:, (*3)

<?php
return [
    'Vim\Crud',
];

Usage

  1. Create Entity, for example: Application\Entity\ArticleEntity, (*4)

  2. Create InputFilterBuilder, for example: Application\InputFilterBuilder\ArticleInputFilterBuilder, (*5)

  3. Create CRUD Service, for example: Application\Service\ArticleService, (*6)

  4. Call the necessary methods:, (*7)

<?php
/** @var \Application\Service\ArticleService $service */
$service = $container->get(\Application\Service\ArticleService::class);

//create
$service->create(...);

//update
$service->update(...);

//delete
$service->delete(...);

//read
$service->find(...);
$service->findAll(...);
$service->has(...);

Example

Create Entity

<?php
namespace Application\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Table(name="article")
 * @ORM\Entity
 */
class ArticleEntity
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    protected $identity;

    /**
     * @var string
     * @ORM\Column(name="alias", type="string", nullable=false)
     */
    public $alias;

    /**
     * @var string
     * @ORM\Column(name="title", type="string", nullable=false)
     */
    public $title;
}

If application is multilanguage: vanvas/translatable, (*8)

Create InputFilterBuilder

An example can be found here: vanvas/input-filter, (*9)

Create CRUD Service

<?php
namespace Application\Service;

use Vim\Crud\Service\CreateAwareInterface;
use Vim\Crud\Service\CreateAwareTrait;
use Vim\Crud\Service\UpdateAwareInterface;
use Vim\Crud\Service\UpdateAwareTrait;
use Vim\Crud\Service\DeleteAwareInterface;
use Vim\Crud\Service\DeleteAwareTrait;
use Vim\Crud\Service\ReadAwareInterface;
use Vim\Crud\Service\ReadAwareTrait;

class ArticleService implements CreateAwareInterface, UpdateAwareInterface, DeleteAwareInterface, ReadAwareInterface
{
    use CreateAwareTrait;
    use UpdateAwareTrait;
    use DeleteAwareTrait;
    use ReadAwareTrait;
}

Is similar:, (*10)

<?php
namespace Application\Service;

use Vim\Crud\Service\CrudAwareInterface;
use Vim\Crud\Service\CrudAwareTrait;

class ArticleService implements CrudAwareInterface
{
    use CrudAwareTrait;
}
<?php
/** @var \Application\Service\ArticleService $service */
$service = $container->get(\Application\Service\ArticleService::class);

create entity:

<?php
$data = [
    'alias' => 'some_alias',
    'title' => 'some title',
];

$service->create($data);

If Entity implements for \Vim\Translatable\Entity\TranslatableEntityAwareInterface:, (*11)

<?php
$data = [
    'alias' => 'some_alias',
    'translation' => [
        'en' => [
            'title' => 'some title'
        ],    
    ],
];

$service->create($data);

or:, (*12)

<?php
$data = [
    'alias' => 'some_alias',
    'title' => [
        'en' => 'some title',    
    ],
];

$service->create($data);

update entity:

<?php
$data = [
    'alias' => 'some_alias',
    'title' => 'some title',
];

$identity = 1;

$service->update($identity, $data);

If Entity implements for \Vim\Translatable\Entity\TranslatableEntityAwareInterface:, (*13)

<?php
$data = [
    'alias' => 'some_alias',
    'translation' => [
        'en' => [
            'title' => 'some title'
        ],    
    ],
];

$service->update($identity, $data);

or:, (*14)

<?php
$data = [
    'alias' => 'some_alias',
    'title' => [
        'en' => 'some title',    
    ],
];

$service->update($identity, $data);

delete entity:

<?php
$identity = 1;
$service->delete($identity);

read entity

<?php
$identity = 1;
$service->find($identity);

$service->has($identity);

$service->findAll();

The Versions