proklung/bitrixannotatedresolversbundle

用于将请求参数转换为 DTO 的 Symfony 扩展包。Bitrix 指定部分

1.0.9 2021-08-14 11:45 UTC

This package is auto-updated.

Last update: 2024-09-14 18:58:51 UTC


README

用于 https://github.com/ProklUng/AnnotatedParamResolverBundle 的转换器,没有它,该包没有意义,也无法启动

  1. BitrixFile

在控制器动作中,当请求类型为 /route?file=7(其中 7 是文件在 Bitrix 中的 ID)时,将会得到一个与 CFile::GetFileArray 返回的数组相同的数组。

use Prokl\BitrixAnnotatedResolversBundle\Annotation\BitrixFile;
use Prokl\BitrixAnnotatedResolversBundle\ArgumentsResolver\Services\BitrixFileParam;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;

class SampleControllerBitrixFile extends AbstractController
{
    /**
     * Параметры аннотации необязательны!
     *
     * @param BitrixFileParam $file
     * @return JsonResponse $content
     * @BitrixFile(
     *    var="file"
     * )
     */
    public function action(
        BitrixFileParam $file
    ): JsonResponse {

        return new JsonResponse([
            'url' => $file->url()
        ]);
    }
}
  1. BitrixFileUrl

在控制器动作中,当请求类型为 /route?file=7(其中 7 是文件在 Bitrix 中的 ID)时,将会得到文件的 URL。

use Prokl\BitrixAnnotatedResolversBundle\Annotation\BitrixFileUrl;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;

class SampleControllerBitrixFileUrl extends AbstractController
{
    /**
     * Параметры аннотации необязательны!
     *
     * @param string $file
     * @return JsonResponse $content
     * @BitrixFileUrl(
     *    var="file"
     * )
     */
    public function action(
        string $file
    ): JsonResponse {

        return new JsonResponse([
            'url' => $file
        ]);
    }
}