ronte-ltd/common-bundle

用于收集常用库及其他内容的工具包

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

This package is not auto-updated.

Last update: 2024-09-23 06:28:15 UTC


README

此工具包包含一些辅助方法

安装

Composer

composer require ronte-ltd/common-bundle

AppKernel.php

new RonteLtd\ElasticBundle\RonteLtdCommonBundle()

使用方法

实体

<?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
{
}

仓库

<?php

namespace AppBundle\Repository;

use RonteLtd\CommonBundle\Repository\AbstractBaseRepository;

class DefaultRepository extends AbstractBaseRepository
{
}

服务

<?php

namespace AppBundle\Service;

use RonteLtd\CommonBundle\Service\AbstractBaseService;

class EntityService extends AbstractBaseService
{
}

为了解释,我们可以使用以下代码来定义自定义服务

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']]

控制器

快速示例

// 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)