承接 setono/symfony-main-request-trait 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

setono/symfony-main-request-trait

最新稳定版本:v1.0.0

Composer 安装命令:

composer require setono/symfony-main-request-trait

包简介

A PHP trait that makes the main/master request issue work on multiple Symfony versions

README 文档

README

Latest Version Software License Build Status Code Coverage Mutation testing

A convenience library for library maintainers of Symfony bundles or libraries using Symfony components. When Symfony changed the naming from master to main in multiple places this had the consequence that certain methods were deprecated in Symfony v5 and removed in v6.

This library will let you support Symfony v4-v6 and not even think about the renaming :)

Installation

composer require setono/symfony-main-request-trait

Usage

Example with the RequestStack

<?php

declare(strict_types=1);

use Setono\MainRequestTrait\MainRequestTrait;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

final class YourService
{
    use MainRequestTrait;

    private RequestStack $requestStack;

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

    public function action(): void
    {
        /**
         * This is how you get the main request from the RequestStack. No need to worry about master/main, just get it
         * @var Request|null $request
         */
        $request = $this->getMainRequestFromRequestStack($this->requestStack);

        // do something with the request
    }
}

Example with event subscriber

<?php

declare(strict_types=1);

use Setono\MainRequestTrait\MainRequestTrait;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\KernelEvent;
use Symfony\Component\HttpKernel\KernelEvents;

final class YourSubscriber implements EventSubscriberInterface
{
    use MainRequestTrait;

    public static function getSubscribedEvents(): array
    {
        return [
            KernelEvents::RESPONSE => 'handle'
        ];
    }

    public function handle(KernelEvent $event): void
    {
        if (!$this->isMainRequest($event)) {
            return;
        }

        // Now we know we are dealing with the main request
    }
}

统计信息

  • 总下载量: 325.96k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-06-07