zendframework / zend-router

Standalone routing implementation for HTTP and console requests
BSD 3-Clause "New" or "Revised" License
32 stars 20 forks source link

Wildcard no longer works when route ends on slash #49

Open roelvanduijnhoven opened 6 years ago

roelvanduijnhoven commented 6 years ago

One can reproduce this using:

$request = new \Zend\Http\Request;
$request->setUri('http://www.test.nl/bla/');

$route = \Zend\Router\Http\Wildcard::factory([]);
$match = $route->match($request);

// Now `$match === null`

Was introduced in https://github.com/zendframework/zend-router/pull/47 by @weierophinney

roelvanduijnhoven commented 6 years ago

Excuse me; I think this bug was not recently introduced. But matches existing behaviour.

As this will be deprecated; feel free to close.

I'll roll my own wildcard implementation for now that simply consumes the remainder of the path.

roelvanduijnhoven commented 6 years ago

Reference for anybody looking for something like what I described:

class MatchEverything implements RouteInterface
{
    /** @var array */
    private $defaults;

    public function __construct(array $defaults)
    {
        $this->defaults = $defaults;
    }

    public function getAssembledParams()
    {
        return [];
    }

    public static function factory($options = [])
    {
        return new self($options['defaults'] ?? []);
    }

    public function match(Request $request, $pathOffset = null)
    {
        if (!method_exists($request, 'getUri')) {
            return null;
        }

        $remainder = substr($request->getUri()->getPath(), $pathOffset);

        return new RouteMatch($this->defaults, strlen($remainder));
    }

    public function assemble(array $params = [], array $options = [])
    {
        return '';
    }
}
weierophinney commented 4 years ago

This repository has been closed and moved to laminas/laminas-router; a new issue has been opened at https://github.com/laminas/laminas-router/issues/4.