1. Go to this page and download the library: Download chani/wajha 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/ */
chani / wajha example snippets
use Safi\Wajha\WajhaCompiler;
use Safi\Wajha\WajhaDispatcher;
$compiler = new WajhaCompiler();
$compiler->get('/users', 'UserController@index');
$compiler->post('/users', 'UserController@store');
$compiledData = $compiler->compile();
$dispatcher = new WajhaDispatcher($compiledData);
// HTTP Method MUST be uppercase
$result = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
switch ($result[0]) {
case WajhaDispatcher::FOUND:
$handler = $result[1];
$vars = $result[2];
break;
case WajhaDispatcher::METHOD_NOT_ALLOWED:
$allowedMethods = $result[1]; // Array of allowed HTTP methods
break;
case WajhaDispatcher::NOT_FOUND:
http_response_code(404);
break;
}
// Compiles to: /users/(\d+)
$compiler->get('/users/{id:int}', 'UserController@show');
// Compiles to RFC 4122 UUID pattern
$compiler->get('/files/{id:uuid}', 'FileController@show');
// Compiles to: /posts/([a-z0-9-]+)
$compiler->get('/posts/{slug:slug}', 'PostController@show');
enum OrderStatus: string {
case Pending = 'pending';
case Paid = 'paid';
case Shipped = 'shipped';
}
// Compiled regex constraint: (pending|paid|shipped)
$compiler->get('/orders/{status:' . OrderStatus::class . '}', 'OrderController@index');