Skip to content

nwnisworking/php-route

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

PHP-Route

PHP Router to route request.

This library solves the following use case below:

  • Add Route attribute to class and function
  • Implement main middleware together with sub-middlewares
  • Loop through middleware after matching url and method

Usages

Initialize a Route class that will store all paths

<?php

#[Route('/api', Method::GET, [self::class, 'auth'])]
class API{
	public function auth(){}
	
	public function check_awesome(){}

	#[Route('/get', Method::POST, [self::class, 'check_awesome'])]
	public function get(){
	}

	#[Route('/get', Method::POST, [self::class, 'check_awesome'])]
	public function get(){
	}
}

$url = '/about';
foreach(Route::get(API::class)->match($url, Method::POST) as $middleware_with_matches)
	var_dump($middleware_with_matches);

This will collect all the routes stated in the class and loop through the middlewares if the path that holds the middlewares matches.

About

PHP Router to route request.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages