feat(ApiAware): use this interface

master
dufraissejeremy 2 years ago
parent 78902e0502
commit a5f0581535
  1. 5
      SeacmsApi.php
  2. 17
      src/ApiAware.php

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

@ -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;
}
Loading…
Cancel
Save