zalas/param-converter-bundle

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

提供额外参数转换器的Bundle,用于Symfony

安装: 175

依赖: 0

建议者: 0

安全: 0

星星: 16

关注者: 4

分支: 2

开放问题: 0

类型:bundle

v1.1.0 2017-05-23 15:42 UTC

This package is auto-updated.

Last update: 2021-08-05 11:49:59 UTC


README

此Bundle为Symfony提供额外的参数转换器。

Scrutinizer Code Quality Build Status

参数解析器服务参数在Symfony 3.3中引入以来,此Bundle提供的参数转换器是多余的。我们可以通过直接向控制器操作注入服务来实现几乎相同的效果。

安装

此Bundle需要

  • PHP ^7.0
  • sensio/framework-extra-bundle ~3.0

安装它的最简单方法是使用Composer

$ composer require zalas/param-converter-bundle:^1.0

服务参数转换器

服务参数转换器调用一个配置的服务将请求属性转换为对象。

选项

  • service - 服务ID
  • method - 在服务上调用的方法名
  • arguments - 要作为方法调用参数传递的请求属性列表

示例

<?php

namespace AppBundle\Controller;

use AppBundle\Site\Visitor;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;

class DemoController
{
    /**
     * @Route("/hello/{name}")
     * @ParamConverter(
     *     "visitor",
     *     converter="service",
     *     options={
     *         "service": "visitor_repository",
     *         "method": "findByName",
     *         "arguments": {"name"}
     *     }
     * )
     */
    public function indexAction(Visitor $visitor)
    {
        return new Response('Hello '.$visitor->getName());
    }
}