Addin a sandbox enviorment to test the Library

This commit is contained in:
2026-08-20 07:50:24 -03:00
parent 5b6d9553ac
commit 84ed545c69
11 changed files with 260 additions and 0 deletions
Executable
+4
View File
@@ -0,0 +1,4 @@
#!/bin/bash
cd sandbox/public
sudo php -S 0.0.0.0:8081
+10
View File
@@ -0,0 +1,10 @@
<?php
use \App\Routes\RoutesController;
use Routes\RouteCollection as RouteCollection;
RouteCollection::group("/routes", function(){
RouteCollection::get("/", "\App\Routes\RoutesController@index");
RouteCollection::get("/tag/[d:tag]", "\App\Routes\RoutesController@withTag");
RouteCollection::get("/group/[d:group]", "\App\Routes\RoutesController@fromGroup");
});
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace App\Routes;
use Routes\Route;
use Routes\RouteCollection;
class RoutesController
{
function index(): array
{
return array_map(function (Route $route) {
return implode(" | ", $route->_verb) . " === $route->_uri";
}, RouteCollection::getInstance()->_routes);
}
function withTag(string $tag): array
{
return Array();
}
function fromGroup(string $group): array
{
return Array();
}
}
+57
View File
@@ -0,0 +1,57 @@
<?php
namespace App\Users\Clients;
class Client
{
public private(set) int $id;
public private(set) string $name;
private static Array $listOfFirstNames = [
'ROBERTO', 'CIBELE', 'GILSA', 'TADEU', 'ELENICE', 'FRANCISCO', 'MARIA', 'JANAINA', 'RUBIA', 'MIRIAN', 'MARIA', 'EZIELMA', 'DEBORA', 'SILVANA', 'SELMA', 'RENICE', 'ALINE', 'ROSIMARA', 'ANDREA', 'JOSE', 'KATIUSCIA', 'GERALDO', 'WANDA', 'JUCIANE', 'ANTONIA', 'LUCIANA', 'CRISTIANE', 'ANA', 'MARIA', 'SANDRA', 'CONCEICAO', 'CRISTINA', 'VERA', 'ROMINA', 'MAX', 'EDMAR', 'NEIDE', 'TÂNIA', 'NARELAINE', 'SANDRA', 'ANGELA', 'ADRIANA', 'ANA', 'SIMONE', 'CRISTIANA', 'REDUZINA', 'RIVANIA', 'LUCIANA', 'ANANDA', 'CLAUDIA', 'LUCIANA', 'DANIELLE', 'CLAUDIA', 'FERNANDA', 'LUCIANE', 'RENATA', 'ROBERTO', 'PAULO', 'REGINA', 'JOSE', 'EVERALDO', 'SHEILA', 'CARMEM', 'CATIA', 'JOSE', 'ANGELITA', 'EDGARD', 'CLEBER', 'WILSON', 'EDNA', 'RITA', 'JOSELMA', 'MAURO', 'ANA', 'AUGUSTO', 'HAMILTON', 'JOANESLEY', 'JORGE', 'SUZAN', 'JOVANDIR', 'JOAO', 'RENATA', 'LETICIA', 'JAQUELINE', 'ILNA', 'AMELIA', 'PEDRO', 'JULIO', 'REUS', 'LEDA', 'VIRGINIA', 'FRANCEROSE', 'MAURO'
];
private static Array $listOfMiddleNames = [
'TERNES', 'AMOROSO', 'GISELE', 'AMOROSO', 'DIVINA', 'VIANA', 'LUIZA', 'MONICI', 'CARLA', 'CONCEICAO', 'VALREZ', 'ALVES', 'FRAGOSO', 'GOULART', 'BARROS', 'SUMAN', 'MENS', 'MORESCHI', 'NARA', 'ANTONIO', 'LUCAS', 'ALMEIDA', 'LOPES', 'MELO', 'BERTULLI', 'KARINA', 'DAS', 'NIEL', 'FIGUEREDO', 'TIBURCIO', 'LUCIA', 'DIAS', 'JUCA', 'TEIXEIRA', 'LUCIA', 'MARIA', 'GOMES', 'CRISTINA', 'MARIA', 'PAULA', 'ALMEIDA', 'PROCOPIO', 'LIMA', 'TABOSA', 'MENEZES', 'JORGE', 'GONCALVES', 'MARIA', 'NEVES', 'BASTOS', 'TAU', 'CÉSAR', 'D\'ARC', 'REINALDO', 'CRISTINA', 'LUCIA', 'JOSÉ', 'EDUARDO', 'AMARANTE', 'FELIX', 'VILLA', 'PEREIRA', 'MARIA', 'RAMOS', 'ROMAO', 'LUCIA', 'PAZ', 'BATUIRA', 'ARY', 'PAULA', 'BOTELHO', 'BATISTA', 'FURTADO', 'HARDMANN', 'CRISTINA', 'LUIZ', 'CÉSAR', 'ANTUNES', 'MARCIA', 'SOFIA', 'CLARA', 'ORLANDO', 'CHARLES', 'PAULA', 'FERREIRA', 'CRISTINA', 'UBALDINO'
];
private static Array $listOfLastNames = [
'ASSIS', 'ROCHA', 'JUNIOR', 'LIMA', 'MAGALHAES', 'MOURA', 'REIS', 'SILVA', 'SILVANO', 'ARRIAL', 'MAIA', 'SANTANA', 'GONCALVES', 'FILHO', 'SOUZA', 'LOPES', 'TEIXEIRA', 'SOUSA', 'DANTAS', 'PERES', 'MARQUES', 'MELO', 'CARVALHO', 'CUNHA', 'BARBOSA', 'LEMOS', 'GUIMARAES', 'CIPRIANO', 'MESQUITA', 'ALMEIDA', 'MONTEIRO', 'OLIVEIRA', 'PONCE', 'RIBEIRO', 'VIEIRA', 'KOKAY', 'MIZIARA', 'GONÇALVES', 'NEVES', 'CRUZ', 'MAGELA', 'TRINDADE', 'FALCAO', 'CUSTODIO', 'LEITE', 'INACIO', 'RODRIGUES', 'RAMOS', 'VALENÇA', 'NOBRE', 'MOREIRA', 'MORAES', 'GARCIA', 'FLOR', 'PINTO', 'MOUTA', 'TARACHUK', 'LEAL', 'TELES', 'VALENCA', 'ARARIPE', 'BEVILACQUA', 'MATOS', 'DUMONT', 'ALBUQUERQUE', 'NOGUEIRA'
];
/**
* Client Constructor
*
* @param int $id
*/
function __construct(int $id = 0)
{
if($id == 0){
return;
}
$this->id = $id;
$this->name = self::generateRandomName();
}
/**
* Generate a random Client Name
*
* @param int $id Id of the Client
* @return string
*/
public static function generateClient(int $id): Client
{
return new Client($id);
}
public static function generateRandomName(): string
{
$firstname = self::$listOfFirstNames[rand(0, sizeof(self::$listOfFirstNames) - 1)];
$middleName = self::$listOfMiddleNames[rand(0, sizeof(self::$listOfMiddleNames) - 1)];
$lastName = self::$listOfLastNames[rand(0, sizeof(self::$listOfLastNames) - 1)];
return "$firstname $middleName $lastName";
}
}
@@ -0,0 +1,54 @@
<?php
namespace App\Users\Clients;
use App\Users\Clients\Client as Client;
class ClientsController
{
/**
* Return a random Client list
* @param array $users
* @return array
*/
function index(Array $users = Array()): Array
{
for ($i=0; $i < rand(20, 100); $i++) {
$users[$i] = Client::generateClient($i);
}
return $users;
}
function raw(){
}
function show(Client $client): Client
{
return $client;
}
function print(Client $client): string
{
return "{$client->id} - " . $client->name;
}
function fullBuild(Client $client, Permission $permission, Config $config, bool $ignoreCache = true)
{
}
function crazyTest(Client $client, Permission $permission, Config $config, bool $ignoreCache = true): Array
{
return [$client, $permission, $config, $ignoreCache];
}
function dump(Client $client, Permission $permission, Config $config, bool $ignoreCache = true): Array
{
return [$client, $permission, $config, $ignoreCache];
}
}
+8
View File
@@ -0,0 +1,8 @@
<?php
namespace App\Users\Clients;
class Config
{
function __construct(){}
}
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace App\Users\Clients;
class Permission {
public private(set) int $id;
public private(set) string $name;
public private(set) string $displayName;
private static array $permissions = [
"user-edit" => [
"id" => 1,
"name" => "user-edit",
"displayName" => "Editar Usuário"
],
"user-delete" => [
"id" => 2,
"name" => "user-delete",
"displayName" => "Apagar Usuário"
]
];
function __construct(string $permission = ''){
if(isset(self::$permissions[$permission])){
$permission = (object) self::$permissions[$permission];
$this->id = $permission->id;
$this->name = $permission->name;
$this->displayName = $permission->displayName;
}
}
}
+24
View File
@@ -0,0 +1,24 @@
<?php
use \App\Users\Clients\ClientsController;
use Routes\RouteCollection as RouteCollection;
use App\Users\Clients\Config;
use App\Users\Clients\Client;
use App\Users\Clients\Permission;
RouteCollection::group("/users/clients", function(){
RouteCollection::get("/", "\App\Users\Clients\ClientsController@index");
RouteCollection::get("/raw", "\App\Users\Clients\ClientsController@raw");
RouteCollection::get("/[i:id]", "\App\Users\Clients\ClientsController@show");
RouteCollection::get("/print/[i:id]", "\App\Users\Clients\ClientsController@print");
//RouteCollection::get("/print/[i:id]", [ClientsController::class, "print"]);
});
RouteCollection::get("/user/simple/[i:id]/coisa/[s:slug]/[s:version]/list", function (Client $client, Permission $permission, Config $config, bool $ignoreCache = true): array{
return [$client, $permission, $config, $ignoreCache];
});
RouteCollection::get("/teste/[i:id]/coisa/[s:slug]/[s:version]/list", "\App\Users\Clients\ClientsController@crazyTest");
RouteCollection::get("/user/simple/[i:id]/coisa/[s:slug]/[s:version]/dump", [ClientsController::class, "dump"]);
+13
View File
@@ -0,0 +1,13 @@
<?php
include_once 'includes.php';
use Routes\RouteCollection as RouteCollection;
RouteCollection::error("404", function () {
http_response_code(404);
echo "Woops - Not Found";
});
RouteCollection::getInstance()->crawl(__DIR__ . "/app")->loadRoutes();
RouteCollection::getInstance()->submit();
+26
View File
@@ -0,0 +1,26 @@
<?php
include_once(__DIR__ . "/../src/Routes/Route.php");
include_once(__DIR__ . "/../src/Routes/RouteGroup.php");
include_once(__DIR__ . "/../src/Routes/HTTPCodes.php");
include_once(__DIR__ . "/../src/Routes/ObjectSpawners.php");
include_once(__DIR__ . "/../src/Routes/RouteCollection.php");
spl_autoload_register(function ($className) {
$path = explode('\\', $className);
$fileName = $path[sizeof($path) - 1];
$path[sizeof($path) - 1] = '';
$path = __DIR__ ."/". strtolower(implode(DIRECTORY_SEPARATOR, $path));
if (is_file($path . $fileName . '.php')) {
return include $path . $fileName . '.php';
}
if (is_file(strtolower($path . $fileName . '.php'))) {
return include strtolower($path . $fileName . '.php');
}
@include $path . $fileName . '.php';
});
+3
View File
@@ -0,0 +1,3 @@
<?php
include '../bootstrap.php';