feat(ApiAware): use this interface

This commit is contained in:
Jérémy Dufraisse 2023-02-27 11:07:21 +01:00
parent 78902e0502
commit a5f0581535
2 changed files with 20 additions and 2 deletions

View File

@ -2,6 +2,7 @@
// SPDX-License-Identifier: EUPL-1.2
// Authors: see README.md
use SeaCMS\Api\ApiAware;
use SeaCMS\Api\BadMethodException;
use SeaCMS\Api\JsonResponse;
use SeaCMS\Api\NotFoundRouteException;
@ -9,7 +10,7 @@ use SeaCMS\Api\NotFoundRouteException;
/**
* An api plugin for Pico 3.
*/
class SeacmsApi extends AbstractPicoPlugin
class SeacmsApi extends AbstractPicoPlugin implements ApiAware
{
/**
* Pico API version.
@ -67,7 +68,7 @@ class SeacmsApi extends AbstractPicoPlugin
{
$this->routesOnPageRendered = [];
foreach($plugins as $plugin){
if (method_exists($plugin,'registerOnPageRenderedApiRoutes')){
if ($plugin instanceof ApiAware){
$routes = $plugin->registerOnPageRenderedApiRoutes();
if (is_array($routes)){
foreach($routes as $route => $methodName){

17
src/ApiAware.php Normal file
View File

@ -0,0 +1,17 @@
<?php
// SPDX-License-Identifier: EUPL-1.2
// Authors: see README.md
namespace SeaCMS\Api;
/**
* Response for http response
*/
interface ApiAware
{
/**
* return api routes
* @return array
*/
public function registerOnPageRenderedApiRoutes():array;
}