You can use Swagger for document your RESTful API. Rest Daemon project use zircote/swagger-php implementation of annotations.
<?php
$generator = new \FreeElephants\RestDaemon\Integration\Swagger\RouterGenerator();
$routerConfig = $generator->getRouterConfig($directoryForScanning);
# and use as RestServer router configuration
$server = (new \FreeElephants\RestDaemon\RestServerBuilder())->buildServer($routerConfig);
$server->run();
<?php
const ROUTES_FILENAME = 'router.php';
if(file_exists(ROUTES_FILENAME)) {
$routerConfig = require ROUTES_FILENAME;
} else {
$generator = new \FreeElephants\RestDaemon\Integration\Swagger\RouterGenerator();
$routerConfig = $generator->getRouterConfig($directoryForScanning);
$output = sprintf('<?php
return %s;
', var_export($routerConfig, true));
file_put_contents(ROUTES_FILENAME, $output);
}
$server = (new \FreeElephants\RestDaemon\RestServerBuilder())->buildServer($routerConfig);
$server->run();
Use vendor/bin/rest-daemon generate:routes:swagger
to generate routing configuration from annotations in your sources.