ronte-ltd/common-bundle

The bundle for collecting common libraries and everything else

v3.1 2017-05-19 09:15 UTC

This package is not auto-updated.

Last update: 2024-11-18 07:17:05 UTC


README

This bundle contains some methods for help

Installation

Composer

composer require ronte-ltd/common-bundle

AppKernel.php

new RonteLtd\ElasticBundle\RonteLtdCommonBundle()

Usage

Entity

<?php

namespace AppBundle\Entity;

use RonteLtd\CommonBundle\Entity\AbstractBaseEntity;
use Doctrine\ORM\Mapping as ORM;

/**
 * Entity
 *
 * @ORM\Entity(repositoryClass="AppBundle\Repository\DefaultRepository")
 * @ORM\Table(name="some_entity")
 */
class Entity extends AbstractBaseEntity
{
}

Repository

<?php

namespace AppBundle\Repository;

use RonteLtd\CommonBundle\Repository\AbstractBaseRepository;

class DefaultRepository extends AbstractBaseRepository
{
}

Service

<?php

namespace AppBundle\Service;

use RonteLtd\CommonBundle\Service\AbstractBaseService;

class EntityService extends AbstractBaseService
{
}

For explanation we can use this code to define custom service

services:
    ## Repositories
    app.entity_repository:
        class: AppBundle\Repository\DefaultRepository
        factory: ["@doctrine.orm.entity_manager", getRepository]
        arguments:
            - AppBundle\Entity\Entity

    ## Services
    app.entity_service:
        class: AppBundle\Service\EntityService
        arguments: ["@validator", "@event_dispatcher"]
        calls:
            - [setRepository, ['@app.entity_repository']]

Controller

For quick example

// We are recieving the service with repository
$service = $this->get('app.entity_service');
$entity = new Entity();

// validate
$result = $service->validate($entity)

// save|remove
$service->save($entity);
$service->remove($entity);

// paginate
$service->paginate($query)