Skip to content

codexsoft/route-collection-filter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Symfony RouteCollection Filter

This library provides tool to filter RouteCollection by declarative constraints.

Usage

<?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',]),
]);

Installation

composer require codexsoft/route-collection-filter

About

simple Symfony RouteCollection filtering library

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages