Matching path to route with Symfony Routing component

Code
<?php

use Symfony\Component\Routing\Router;
use 
Symfony\Component\Routing\Route;
use 
Symfony\Component\Routing\RouteCollection;
use 
Symfony\Component\Routing\Loader\ClosureLoader;

// a collection of routes and their controllers
$collection = new RouteCollection();
$collection->add('foo', new Route('/foo/{baz}', [
    
'_controller' => function ($baz) {
        
dump($baz);
    },
]));
$collection->add('bar', new Route('/bar/{baz}/{qux}', [
    
'_controller' => function ($baz$qux) {
        
dump($baz $qux);
    },
]));

// create Router
$closure = function () use ($collection) {
    return 
$collection;
};
$loader = new ClosureLoader();
$router = new Router($loader$closure);

// matching path of url
$match1 $router->match('/foo/test');
$match2 $router->match('/bar/3/5');

// function for executing controller
$executeController = function (array $match) {
    
$controller $match['_controller'];
    unset(
$match['_controller'], $match['_route']);
    
    
$match array_values($match);
    
$controller(...$match);
};

// execute controller
echo 'foo route controller:';
$executeController($match1);
echo 
'bar route controller:';
$executeController($match2);
Result
foo route controller:
^ "test"

bar route controller:
^ 8
Used Versions
PHP 8.2, Laminas MVC 3.2, Symfony 5.2, Laravel 8.28, PHPUnit 9.5, Doctrine ORM 2.8