honda/url-pattern-matcher

Check if a given path matches a given pattern.

1.1.1 2022-01-22 10:20 UTC

This package is auto-updated.

Last update: 2024-11-18 20:10:37 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.