codexsoft/route-collection-filter

简单的 Symfony RouteCollection 过滤器

v1.1.0 2020-12-29 19:01 UTC

This package is auto-updated.

Last update: 2024-09-29 06:08:34 UTC


README

这个库提供了一种通过声明性约束过滤 RouteCollection 的工具。

使用方法

<?php

use CodexSoft\RouteCollectionFilter\RouteCollectionFilter;
use CodexSoft\RouteCollectionFilter\RouteFilter;
use Psr\Log\NullLogger;

$routes = new \Symfony\Component\Routing\RouteCollection();

$filtered = (new RouteCollectionFilter(new NullLogger()))->apply($routes, [
    (new RouteFilter())
        ->setAllowedMethods(['POST'])
        ->setAllowedHosts(['api.localhost',])
        ->setControllerClassInterfacesWhitelist([SomeInterface::class,])
        ->setControllerClassNamespacesWhitelist(['Some\Namespace',])
        ->setAllowedPathPrefixes(['/v1/','/v2/',]),

    (new RouteFilter())
        ->setAllowedMethods(['GET'])
        ->setAllowedHosts(['api.localhost',])
        ->setControllerClassInterfacesWhitelist([OtherInterface::class, ThirdInterface::class])
        ->setControllerClassNamespacesWhitelist(['Other\Namespace',]),
]);

安装

composer require codexsoft/route-collection-filter