honda / url-pattern-matcher
Check if a given path matches a given pattern.
Installs: 2 587
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3
- pestphp/pest: ^1.0.5
- phpstan/phpstan: ^1.1
- symfony/var-dumper: ^5.2.0
README
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.