PHP code example of diogodg / neoframework

1. Go to this page and download the library: Download diogodg/neoframework 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/ */

    

diogodg / neoframework example snippets


#[RoutePrefix('/api/users')]
#[Middleware(ApiAuthentication::class)]
final class UserController extends Controller
{
    #[Route('/{id:\\d+}', ['GET'], name: 'users.show')]
    public function show(int $id): Response
    {
        return $this->json(['id' => $id]);
    }
}

$response = (new Response())
    ->withStatus(201)
    ->withHeader('Location', '/api/users/42')
    ->json(['id' => 42], 201);

final class ApiAuthentication implements MiddlewareInterface
{
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        return $handler->handle($request)->withHeader('X-Authenticated', '1');
    }
}