PHP code example of erikfig / suhymeblas
1. Go to this page and download the library: Download erikfig/suhymeblas 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/ */
erikfig / suhymeblas example snippets
// classe
namespace SuHyMeBlaS;
use SuHyMeBlaS\Collection;
class Router implements \ArrayAccess
{
use Collection;
public function handler()
{
$path = $_SERVER['PATH_INFO'] ?? '/';
if (strlen($path) > 1) {
$path = rtrim($path, '/');
}
if ($this->offsetExists($path)) {
$handler = $this->offsetGet($path);
return $handler();
}
http_response_code(404);
echo 'Página inexistente';
exit;
}
}
// uso da classe
$router = new SuHyMeBlaS\Router;
$router['/'] = function() {
return View::render('home');
};
$result = $router->handler();