PHP code example of opsway / slim-attribute-router

1. Go to this page and download the library: Download opsway/slim-attribute-router 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/ */

    

opsway / slim-attribute-router example snippets



use OpsWay\Slim\AttributeRouter\Router;
use Slim\Factory\AppFactory;
$route = new Router([
    ['NameSpace'], // array of namespaces parts of app 
	AppFactory::determineResponseFactory(),
	new CallableResolver($container) // optional DI container
);
AppFactory::setRouteCollector($attributeRouteCollector);
$app = AppFactory::create();
$app->run();


use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

#[Route([Route::METHOD_GET], '/api/hello-world', '/hello-world-group', 'api.hello-world.route-name')]
class HelloWorld
{
    public function __invoke(Request $request, Response $response): Response
    {
        // some php code
        return $response;
    }
}


use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

class HelloWorld
{
    #[Route([Route::METHOD_GET], '/api/hello-world')]
    public function __invoke(Request $request, Response $response): Response
    {
        // some php code
        return $response;
    }
}


use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

#[Group('/api', [FirstMidleware::class, SecondMidleware::class])]
class HelloWorld
{
    public function __invoke(Request $request, Response $response): Response
    {
        // some php code
        return $response;
    }
}