Skip to content

Commit

Permalink
🔨 APP #270 melhorando exemplo
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinaldo Araujo Barreto Junior committed Jul 6, 2022
1 parent 6b301f7 commit 425f457
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions appexemplo_v2.0/api/routes2.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;

use api_controllers\SysinfoAPI;

/**
* Instantiate App
*
Expand Down Expand Up @@ -32,14 +34,34 @@
$errorMiddleware = $app->addErrorMiddleware(true, true, true);


$urlChamada = $_SERVER["REQUEST_URI"];
$urlChamada = ServerHelper::getRequestUri(true);
$urlChamada = explode('api/', $urlChamada);
$urlChamada = $urlChamada[0];
$urlChamada = $urlChamada.'api/';
// Define app routes
$app->get($urlChamada, function (Request $request, Response $response, $args) {
$msg = "Hello, mundo";
$app->get($urlChamada, function (Request $request, Response $response, $args) use ($app) {
$url = \ServerHelper::getFullServerName();
$routes = $app->getRouteCollector()->getRoutes();
$routesArray = array();
foreach ($routes as $route) {
$routeArray = array();
$routeArray['id'] = $route->getIdentifier();
$routeArray['name']= $route->getName();
$routeArray['url'] = $url.$route->getPattern();
$routesArray[] = $routeArray;
}
$msg = array( 'info'=> SysinfoAPI::info()
, 'endpoints'=>array( 'qtd'=> \CountHelper::count($routesArray)
,'result'=>$routesArray
)
);

$msgJson = json_encode($msg);
$response->getBody()->write( $msgJson );
return $response->withHeader('Content-Type', 'application/json');
});

$app->get($urlChamada.'sysinfo', SysinfoAPI::class . ':getInfo');

// Run app
$app->run();

0 comments on commit 425f457

Please sign in to comment.