refactor(rest-api): move rest api's enabled flag to the RestApi config

This commit is contained in:
Yassine Doghri 2022-06-29 16:19:22 +00:00
parent 68777dd54c
commit 3b73c67250
6 changed files with 15 additions and 9 deletions

View File

@ -42,7 +42,7 @@ cache.handler="file"
# cache.redis.port=6379
# cache.redis.database=0
#REST API configuration
#--------------------------------------------------------------------
# 0/1 Disabled/Enabled
REST_API_ENABLED=1
# REST API configuration
#--------------------------------------------------------------------
# restapi.enabled=true

View File

@ -1,14 +1,20 @@
<?php
declare(strict_types=1);
namespace Modules\Api\Rest\V1\Config;
use CodeIgniter\Config\BaseConfig;
class Api extends BaseConfig
class RestApi extends BaseConfig
{
/**
* Flag to enable or disable the Rest API.
*
* Disabled by default.
*/
public bool $enabled = false;
/**
* --------------------------------------------------------------------------
* Rest API gateway

View File

@ -7,7 +7,7 @@ namespace Modules\Api\Rest\V1\Config;
$routes = service('routes');
$routes->group(
config('Api')
config('RestApi')
->gateway . 'podcasts',
[
'namespace' => 'Modules\Api\Rest\V1\Controllers',

View File

@ -13,7 +13,7 @@ class ApiFilter implements FilterInterface
{
public function before(RequestInterface $request, $arguments = null): void
{
if (! getenv('REST_API_ENABLED')) {
if (! config('RestApi')->enabled) {
throw PageNotFoundException::forPageNotFound();
}
}

View File

@ -51,6 +51,6 @@
<env name="database.tests.password" value="castopod"/>
<env name="database.tests.DBDriver" value="MySQLi"/>
<env name="database.tests.DBPrefix" value="tests_"/>
<env name="REST_API_ENABLED" value="1"/>
<env name="restapi.enabled" value="true"/>
</php>
</phpunit>

View File

@ -55,7 +55,7 @@ class PodcastTest extends CIUnitTestCase
$this->podcast = FakeSinglePodcastApiSeeder::podcast();
$this->podcast['created_at'] = [];
$this->podcast['updated_at'] = [];
$this->podcastApiUrl = config('Api')
$this->podcastApiUrl = config('RestApi')
->gateway;
}