honda/url-pattern-matcher

Check if a given path matches a given pattern.

Installs: 2 601

Dependents: 2

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/honda/url-pattern-matcher

1.1.1 2022-01-22 10:20 UTC

This package is auto-updated.

Last update: 2025-09-18 22:35:20 UTC


README

Tests Formats Version Total Downloads License

Checks if a given path like (/articles/4) matches a given pattern like (/articles/*).

Installation

You can install the package via composer:

composer require honda/url-pattern-matcher

Usage

Trailing forward slashes are ignored so the matcher will match /example, example, example/, /example/ if given /example.

use Honda\UrlPatternMatcher\UrlPatternMatcher;
$urlPatternMatcher = new UrlPatternMatcher('/articles/edit');

$urlPatternMatcher->match('/articles');

// See fnmatch() function for reference on how the matching works.
$urlPatternMatcher->match('/articles/*/edit');

// Matches if the path starts with /articles
$urlPatternMatcher->match('^/articles');

// Matches if the path ends with /articles
$urlPatternMatcher->match('/articles$');

Testing

There is 100% code coverage for this package, it's rare, most of the time useless, but it feels good :)

composer test

Url Pattern Matcher was created by Félix Dorn under the MIT license.