1. Go to this page and download the library: Download vertilia/response 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/ */
// web/index.php
use Vertilia\Request\HttpRequest;
use Vertilia\Response\JsonResponse;
use Vertilia\Router\HttpRouter;
// initialize request object
$request = new HttpRequest(
$_SERVER,
$_GET,
$_POST,
$_COOKIE,
$_FILES,
file_get_contents('php://stdin')
);
// initialise HttpRouter with request and a list of routes
$router = new HttpRouter($request, ['../etc/api-routes.php']);
// get leaf structure from router, inject filters and parameters into $request
// elements to be present in leaf structure:
// - "container" to identify controller name
// - "filters" to validate request parameters filters
// - "response" filters for response structure
$leaf_structure = $router->getControllerFromRequest(App\NotFoundResponse::class);
// get HttpResponse object and render it
$response = new ($leaf_structure['controller'])($leaf_structure['response'] ?? [], $request);
$response->render();
// app/Controller/UserGetEmail.php
namespace App\Controller;
use Vertilia\Request\HttpRequest;
use Vertilia\Response\JsonResponse;
class UserGetEmail extends JsonResponse
{
protected $request;
public function __construct(array $filters, HttpRequest $request)
{
parent::__construct($filters);
$this->request = $request;
}
public function preRender()
{
$this['id'] = $this->request['id'];
$user = new App\Model\User($this['id']);
$this['email'] = $user->getEmail();
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.