simplethings/distribution-bundle

此包已被废弃,不再维护。未建议替代包。

此包提供便捷方法、辅助工具、实用工具和基于 Sensio CodeGenerators 的简单运行时管理器生成器。

dev-master 2013-09-04 12:49 UTC

This package is auto-updated.

Last update: 2022-02-01 12:19:59 UTC


README

存储库服务检测器

此包提供依赖注入扩展,可自动检测 Doctrine ORM 实体的存储库服务。注册约定为 '{bundle_alias}.repository.{entity}',全部使用小写。

控制器工具

服务 simple_things.distribution.controller_utils 实现了框架包的基控制器中的所有方法,以下列例外

* No access to the container possible through `has()` and `get()`
* Added method `getRestView()` to access the fos_rest.view service if defined.
* Added methods `isPut()`, `isPost()`, `isDelete()` and `isXmlHttpRequest()`.
* Added methods `getUser()` and `isGranted($attributes, $object = null)` that checks for permissions
* Added methods for throwing more http related exceptions
* Added method `getSession()`
* Added method `getLogger()`

控制器

默认情况下,Symfony2 控制器不是服务,服务是通过服务定位器方法通过直接访问 Symfony DI 容器来获取的。这非常方便,但从长远来看会导致难以维护的代码。

此包提供 SimpleThings\DistributionBundle\Controller\Controller,该控制器根据约定 "{bundle_alias}.controller.{controller_name}" 自动注册为服务。此控制器自动注入 Controller#utils 变量作为控制器工具服务。

为了简单起见,还实现了 Controller#__call,它将尽可能多的 API 兼容性委托给默认控制器。

use SimpleThings\DistributionBundle\Controller\Controller;

/**
 * Controller to access jira instances through a HTTP-JSON interface
 *
 * @Extra\Route(service="whitewashing.controller.jira")
 */
class JiraController extends Controller
{
    private $jiraFactory;

    public function __construct($jiraFactory)
    {
        $this->jiraFactory = $jiraFactory;
    }

    /**
     * @Extra\Route("/jira/projects", name="ww_jira_projects")
     * @Extra\Method("GET")
     */
    public function projectsAction(Request $request)
    {
    }
}