PHP code example of louiss0 / slim-route-registry

1. Go to this page and download the library: Download louiss0/slim-route-registry library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

louiss0 / slim-route-registry example snippets


composer 

use Slim\Factory\AppFactory;
use Louiss0\SlimRouteRegistry\RouteRegstry

$app = AppFactory::create();

RouteRegistry::setup($app);



RouteRegistry::resource(string $path, string $class_name);



RouteRegistry::resource(array $resource_options);



// will tell the resource method to register a http get request
#[Get(name, path)]
function fetchTheCars(){}

// will tell the resource method to register a http post request
#[Post(name, path)]
function loginAUser(){}

// will tell the resource method to register a http patch request
#[Patch(name, path)]
function changeTheCarInfo(){}

// will tell the resource method to register a http put request
#[Put(name, path)]
function putTheArticleInTheCollectionOrCreateANewOne(){}

// will tell the resource method to register a http delete request
#[Delete(name, path)]
function deleteThisPost(){}



	// Will be used as a plain get request handler
	function collect() {}

	// Will be used as a  get request handler with id passed as params
	function show() {}

	// Will be used as a plain post request handler
	function store() {}

	// Will be used as a  put request handler with id passed as params
	function upsert() {}

	// Will be used as a  patch request handler with id passed as params
	function update() {}

	// Will be used as a  delete request handler with id passed as params
	function destroy() {}




RouteRegistry::group(string $path, Closure $closure);



#[UseMiddleware([TestMiddleware::class])]
class Controller {}


class Controller {


	#[UseMiddleware([TestMiddleware::class])]
	function getOrdersByName(){}

}




	// takes a string of middleware
	#[UseMiddleware(array $middleware)]
	class PostController {}



#[UseMiddlewareOn(array $method_names, array $middleware)]
	class AuthController {}




#[UseMiddlewareExceptFor(array $method_names, array $middleware)]
	class PostController {}



#[
	UseMiddlewareOn(
		["collect", "destroy"],
		[]
	),
	UseMiddlewareOn(
		["update", "store"],
	)
]
class Controller {}



#[
UseMiddlewareOn(["collect", "store"],[Test4Middleware::class])
UseMiddlewareExceptOn(["collect", "upsert"],[Test3Middleware::class])

]
class Controller {}


RouteRegistry::groupMiddleware(MiddlewareInterface...$middleware);