ldrahnik / url-matcher
Installs: 1 469
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >= 5.4
- nette/nette: ~2.3.0
Requires (Dev)
- nette/tester: ~1.3
This package is not auto-updated.
Last update: 2024-09-28 17:59:55 UTC
README
Requirements
ldrahnik/url-matcher requires PHP 5.4 or higher.
Installation
Install url-matcher to your project using Composer:
$ composer require ldrahnik/url-matcher
Usage
create url
$patterns = [ 'lang' => 'cz', 'presenter' => 'home', 'action' => 4 ]; $mask = '[<lang>/]<presenter>/<action>'; $matcher = new Matcher($mask, $patterns); $results = $matcher->parse(); /*array [ 'home/4', 'cz/home/4', ];*/
confirm url
$mask = '[<lang>/]<presenter>[/<action>]'; $matcher = new Matcher($mask); $result = $matcher->match('en/admin'); // true
Examples
$mask = 'root/<folder>/<subfolder>/<file>.latte'; $matcher = new UrlMatcher\Matcher($mask, [ 'folder' => '*', 'subfolder' => 'foo', 'file' => '*' ]); $mask = $matcher->parse(); // root/*/foo/*.latte foreach (glob($mask) as $filename) { echo basename($filename); }
Configuration
$default = [ 'separator_lft' => '<', 'separator_rgt' => '>', 'optional_lft' => '[', 'optional_rgt' => ']' ]; $matcher = new Matcher(..., ..., $default);