Skip to content

Commit

Permalink
functional framework service
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsauder committed Aug 4, 2023
1 parent eab3faa commit 93a8029
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
composer.phar
/vendor/
composer.lock

# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
Expand Down
14 changes: 14 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "gcgov/framework-service-documentation",
"type": "framework-service",
"description": "Plugin that enables a route to generate OpenAPI yaml documentation at the /documentation.yaml route",
"license": "MIT",
"autoload": {
"psr-4": {
"gcgov\\framework\\services\\documentation\\": "src/"
}
},
"require": {
"php": ">=8.1"
}
}
45 changes: 45 additions & 0 deletions src/controllers/documentation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace gcgov\framework\services\documentation\controllers;

use gcgov\framework\config;
use gcgov\framework\interfaces\controller;
use gcgov\framework\models\controllerDataResponse;
use JetBrains\PhpStorm\NoReturn;

class documentation implements controller {

public function __construct() {

}


#[NoReturn]
public function yaml(): void {
$openapi = \OpenApi\Generator::scan( [ config::getRootDir() . '/app', config::getRootDir() . '/vendor/gcgov/framework/src/controllers', config::getRootDir() . '/vendor/gcgov/framework/src/exceptions', config::getRootDir() . '/vendor/gcgov/framework/src/models', config::getRootDir() . '/vendor/gcgov/framework/src/services' ], [ 'exclude' => [ 'vendor' ] ] );
header( 'Content-Type: text/x-yaml' );
echo $openapi->toYaml();
die();
}


public function routes(): controllerDataResponse {
$routes = [];
return new controllerDataResponse( $routes );
}


/**
* Processed after lifecycle is complete with this instance
*/
public static function _after(): void {
}


/**
* Processed prior to __constructor() being called
*/
public static function _before(): void {
}

}
37 changes: 37 additions & 0 deletions src/router.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace gcgov\framework\services\documentation;

use gcgov\framework\config;
use gcgov\framework\models\route;

class router
implements
\gcgov\framework\interfaces\router {

public function getRoutes(): array {
return [
new route( 'GET', config::getEnvironmentConfig()->getBasePath() . '/documentation.yaml', '\gcgov\framework\services\documentation\controllers\documentation', 'yaml', false )
];
}


public function authentication( \gcgov\framework\models\routeHandler $routeHandler ): bool {
return false;
}


/**
* Processed after lifecycle is complete with this instance
*/
public static function _after(): void {
}


/**
* Processed prior to __constructor() being called
*/
public static function _before(): void {
}

}

0 comments on commit 93a8029

Please sign in to comment.