Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ldrahnik/url-matcher

Url matcher.
https://github.com/ldrahnik/url-matcher

nette package php

Last synced: 10 days ago
JSON representation

Url matcher.

Awesome Lists containing this project

README

        

ldrahnik/url-matcher
======

[![Build Status](https://travis-ci.org/ldrahnik/url-matcher.svg)](https://travis-ci.org/ldrahnik/url-matcher)
[![Latest stable](https://img.shields.io/packagist/v/ldrahnik/url-matcher.svg)](https://packagist.org/packages/ldrahnik/url-matcher)
[![Downloads total](https://img.shields.io/packagist/dt/ldrahnik/url-matcher.svg?style=flat-square)](https://packagist.org/packages/ldrahnik/url-matcher)

Requirements
------------

ldrahnik/url-matcher requires PHP 5.4 or higher.

- [Nette Framework](https://github.com/nette/nette)

Installation
------------

Install url-matcher to your project using [Composer](http://getcomposer.org/):

```sh
$ composer require ldrahnik/url-matcher
```

Usage
-----

create url

```php
$patterns = [
'lang' => 'cz',
'presenter' => 'home',
'action' => 4
];
$mask = '[/]/';
$matcher = new Matcher($mask, $patterns);

$results = $matcher->parse();
/*array [
'home/4',
'cz/home/4',
];*/
```

confirm url

```php
$mask = '[/][/]';
$matcher = new Matcher($mask);

$result = $matcher->match('en/admin');
// true
```
Examples
------------

```php
$mask = 'root///.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
-------------

```php
$default = [
'separator_lft' => '<',
'separator_rgt' => '>',
'optional_lft' => '[',
'optional_rgt' => ']'
];
$matcher = new Matcher(..., ..., $default);
```