Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/parable-php/routing
Parable Routing is a fast, intuitive url routing library.
https://github.com/parable-php/routing
library parable php8 routes routing url
Last synced: 2 months ago
JSON representation
Parable Routing is a fast, intuitive url routing library.
- Host: GitHub
- URL: https://github.com/parable-php/routing
- Owner: parable-php
- License: mit
- Created: 2019-03-08T11:54:35.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-01-24T13:44:55.000Z (11 months ago)
- Last Synced: 2024-10-10T23:41:10.519Z (2 months ago)
- Topics: library, parable, php8, routes, routing, url
- Language: PHP
- Homepage:
- Size: 28.3 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Parable Routing
[![Workflow Status](https://github.com/parable-php/routing/workflows/Tests/badge.svg)](https://github.com/parable-php/routing/actions?query=workflow%3ATests)
[![Latest Stable Version](https://poser.pugx.org/parable-php/routing/v/stable)](https://packagist.org/packages/parable-php/routing)
[![Latest Unstable Version](https://poser.pugx.org/parable-php/routing/v/unstable)](https://packagist.org/packages/parable-php/routing)
[![License](https://poser.pugx.org/parable-php/routing/license)](https://packagist.org/packages/parable-php/routing)Parable Routing is a fast, intuitive url routing library.
## Install
Php 8.0+ and [composer](https://getcomposer.org) are required.
```bash
$ composer require parable-php/routing
```## Usage
```php
$router = new Router();$route1 = new Route(
['GET'],
'simple-route',
'route/simple',
[Controller::class, 'actionName']
);$route2 = new Route(
['GET', 'POST'],
'param-route',
'route/{param}/hello',
function (string $param) {
echo 'Hello, ' . $username . '!';
}
);$router->addRoutes($route1, $route2);
$match = $router->match('GET', 'route/devvoh/hello');
echo $match->getName();
```This would echo `param-route`.
Routing does not provide a direct way of executing a route, but it's easy enough:
```php
$callable = $match->getCallable();
$callable(...$match->getParameterValues()->getAll());
```For more free-form metadata you want to attach to a `Route`, you can use metadata:
```php
$route = new Route(
['GET'],
'simple-route',
'route/simple',
[Controller::class, 'actionName'],
[
'metadata' => 'enabled'
]
);$route->getMetadataValue('metadata'); // returns 'enabled'
```You can use this to add template paths to a route, whether it should be visible to admins only, etc.
## Contributing
Any suggestions, bug reports or general feedback is welcome. Use github issues and pull requests, or find me over at [devvoh.com](https://devvoh.com).
## License
All Parable components are open-source software, licensed under the MIT license.