Use config library for dotenv adapter

This commit is contained in:
Matej Bačo
2025-11-18 16:35:02 +01:00
parent e6039cf65e
commit ce2f2d0ebc
4 changed files with 84 additions and 74 deletions
+14 -12
View File
@@ -17,7 +17,9 @@ use Appwrite\Vcs\Comment;
use Swoole\Coroutine\WaitGroup;
use Utopia\App;
use Utopia\CLI\Console;
use Utopia\Config\Adapters\PHP as ConfigPHP;
use Utopia\Config\Config;
use Utopia\Config\Exceptions\Parse;
use Utopia\Database\Database;
use Utopia\Database\DateTime;
use Utopia\Database\Document;
@@ -978,14 +980,14 @@ App::post('/v1/vcs/github/installations/:installationId/detections')
$contentResponse = $github->getRepositoryContent($owner, $repositoryName, \rtrim($providerRootDirectory, '/') . '/' . $file);
$envFile = $contentResponse['content'] ?? '';
$envLines = \explode("\n", $envFile);
foreach ($envLines as $line) {
$parts = \explode('=', $line, 2);
$envName = \trim($parts[0] ?? '');
$envValue = \trim($parts[1] ?? '');
if (!empty($envName)) {
$configAdapter = new ConfigPHP();
try {
$envObject = $configAdapter->parse($envFile);
foreach ($envObject as $envName => $envValue) {
$envs[$envName] = $envValue;
}
} catch (Parse $err) {
// Silence error, so rest of endpoint can return
}
} finally {
$wg->done();
@@ -1192,14 +1194,14 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories')
$contentResponse = $github->getRepositoryContent($repo['organization'], $repo['name'], $file);
$envFile = $contentResponse['content'] ?? '';
$envLines = \explode("\n", $envFile);
foreach ($envLines as $line) {
$parts = \explode('=', $line, 2);
$envName = \trim($parts[0] ?? '');
$envValue = \trim($parts[1] ?? '');
if (!empty($envName)) {
$configAdapter = new ConfigPHP();
try {
$envObject = $configAdapter->parse($envFile);
foreach ($envObject as $envName => $envValue) {
$envs[$envName] = $envValue;
}
} catch (Parse) {
// Silence error, so rest of endpoint can return
}
} finally {
$wg->done();
+39 -36
View File
@@ -1,42 +1,45 @@
<?php
use Utopia\Config\Adapters\PHP;
use Utopia\Config\Config;
require_once __DIR__ . '/../config/storage/resource_limits.php';
Config::load('template-runtimes', __DIR__ . '/../config/template-runtimes.php');
Config::load('events', __DIR__ . '/../config/events.php');
Config::load('auth', __DIR__ . '/../config/auth.php');
Config::load('apis', __DIR__ . '/../config/apis.php'); // List of APIs
Config::load('errors', __DIR__ . '/../config/errors.php');
Config::load('oAuthProviders', __DIR__ . '/../config/oAuthProviders.php');
Config::load('platforms', __DIR__ . '/../config/platforms.php');
Config::load('console', __DIR__ . '/../config/console.php');
Config::load('collections', __DIR__ . '/../config/collections.php');
Config::load('frameworks', __DIR__ . '/../config/frameworks.php');
Config::load('runtimes', __DIR__ . '/../config/runtimes.php');
Config::load('runtimes-v2', __DIR__ . '/../config/runtimes-v2.php');
Config::load('usage', __DIR__ . '/../config/usage.php');
Config::load('roles', __DIR__ . '/../config/roles.php'); // User roles and scopes
Config::load('scopes', __DIR__ . '/../config/scopes.php'); // User roles and scopes
Config::load('services', __DIR__ . '/../config/services.php'); // List of services
Config::load('variables', __DIR__ . '/../config/variables.php'); // List of env variables
Config::load('regions', __DIR__ . '/../config/regions.php'); // List of available regions
Config::load('avatar-browsers', __DIR__ . '/../config/avatars/browsers.php');
Config::load('avatar-credit-cards', __DIR__ . '/../config/avatars/credit-cards.php');
Config::load('avatar-flags', __DIR__ . '/../config/avatars/flags.php');
Config::load('locale-codes', __DIR__ . '/../config/locale/codes.php');
Config::load('locale-currencies', __DIR__ . '/../config/locale/currencies.php');
Config::load('locale-eu', __DIR__ . '/../config/locale/eu.php');
Config::load('locale-languages', __DIR__ . '/../config/locale/languages.php');
Config::load('locale-phones', __DIR__ . '/../config/locale/phones.php');
Config::load('locale-countries', __DIR__ . '/../config/locale/countries.php');
Config::load('locale-continents', __DIR__ . '/../config/locale/continents.php');
Config::load('locale-templates', __DIR__ . '/../config/locale/templates.php');
Config::load('storage-logos', __DIR__ . '/../config/storage/logos.php');
Config::load('storage-mimes', __DIR__ . '/../config/storage/mimes.php');
Config::load('storage-inputs', __DIR__ . '/../config/storage/inputs.php');
Config::load('storage-outputs', __DIR__ . '/../config/storage/outputs.php');
Config::load('specifications', __DIR__ . '/../config/specifications.php');
Config::load('templates-function', __DIR__ . '/../config/templates/function.php');
Config::load('templates-site', __DIR__ . '/../config/templates/site.php');
$configAdapter = new PHP();
Config::load('template-runtimes', __DIR__ . '/../config/template-runtimes.php', new PHP());
Config::load('events', __DIR__ . '/../config/events.php', new PHP());
Config::load('auth', __DIR__ . '/../config/auth.php', new PHP());
Config::load('apis', __DIR__ . '/../config/apis.php', new PHP()); // List of APIs
Config::load('errors', __DIR__ . '/../config/errors.php', new PHP());
Config::load('oAuthProviders', __DIR__ . '/../config/oAuthProviders.php', new PHP());
Config::load('platforms', __DIR__ . '/../config/platforms.php', new PHP());
Config::load('console', __DIR__ . '/../config/console.php', new PHP());
Config::load('collections', __DIR__ . '/../config/collections.php', new PHP());
Config::load('frameworks', __DIR__ . '/../config/frameworks.php', new PHP());
Config::load('runtimes', __DIR__ . '/../config/runtimes.php', new PHP());
Config::load('runtimes-v2', __DIR__ . '/../config/runtimes-v2.php', new PHP());
Config::load('usage', __DIR__ . '/../config/usage.php', new PHP());
Config::load('roles', __DIR__ . '/../config/roles.php', new PHP()); // User roles and scopes
Config::load('scopes', __DIR__ . '/../config/scopes.php', new PHP()); // User roles and scopes
Config::load('services', __DIR__ . '/../config/services.php', new PHP()); // List of services
Config::load('variables', __DIR__ . '/../config/variables.php', new PHP()); // List of env variables
Config::load('regions', __DIR__ . '/../config/regions.php', new PHP()); // List of available regions
Config::load('avatar-browsers', __DIR__ . '/../config/avatars/browsers.php', new PHP());
Config::load('avatar-credit-cards', __DIR__ . '/../config/avatars/credit-cards.php', new PHP());
Config::load('avatar-flags', __DIR__ . '/../config/avatars/flags.php', new PHP());
Config::load('locale-codes', __DIR__ . '/../config/locale/codes.php', new PHP());
Config::load('locale-currencies', __DIR__ . '/../config/locale/currencies.php', new PHP());
Config::load('locale-eu', __DIR__ . '/../config/locale/eu.php', new PHP());
Config::load('locale-languages', __DIR__ . '/../config/locale/languages.php', new PHP());
Config::load('locale-phones', __DIR__ . '/../config/locale/phones.php', new PHP());
Config::load('locale-countries', __DIR__ . '/../config/locale/countries.php', new PHP());
Config::load('locale-continents', __DIR__ . '/../config/locale/continents.php', new PHP());
Config::load('locale-templates', __DIR__ . '/../config/locale/templates.php', new PHP());
Config::load('storage-logos', __DIR__ . '/../config/storage/logos.php', new PHP());
Config::load('storage-mimes', __DIR__ . '/../config/storage/mimes.php', new PHP());
Config::load('storage-inputs', __DIR__ . '/../config/storage/inputs.php', new PHP());
Config::load('storage-outputs', __DIR__ . '/../config/storage/outputs.php', new PHP());
Config::load('specifications', __DIR__ . '/../config/specifications.php', new PHP());
Config::load('templates-function', __DIR__ . '/../config/templates/function.php', new PHP());
Config::load('templates-site', __DIR__ . '/../config/templates/site.php', new PHP());
+1 -1
View File
@@ -50,7 +50,7 @@
"utopia-php/audit": "1.*",
"utopia-php/cache": "0.13.*",
"utopia-php/cli": "0.15.*",
"utopia-php/config": "0.2.*",
"utopia-php/config": "dev-feat-config-adapters as 1.0.0",
"utopia-php/database": "4.*",
"utopia-php/detector": "0.2.*",
"utopia-php/domains": "0.9.*",
Generated
+30 -25
View File
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "3b502f78f5e31f2ea7b4c69e3301283a",
"content-hash": "1042498bc589543427184b001fef3a1e",
"packages": [
{
"name": "adhocore/jwt",
@@ -3745,24 +3745,26 @@
},
{
"name": "utopia-php/config",
"version": "0.2.2",
"version": "dev-feat-config-adapters",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/config.git",
"reference": "a3d7bc0312d7150d5e04b1362dc34b2b136908cc"
"reference": "02232da489a94576be0d8fb63c326003ccb6e337"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/config/zipball/a3d7bc0312d7150d5e04b1362dc34b2b136908cc",
"reference": "a3d7bc0312d7150d5e04b1362dc34b2b136908cc",
"url": "https://api.github.com/repos/utopia-php/config/zipball/02232da489a94576be0d8fb63c326003ccb6e337",
"reference": "02232da489a94576be0d8fb63c326003ccb6e337",
"shasum": ""
},
"require": {
"php": ">=7.3"
"ext-yaml": "*",
"php": ">=8.1"
},
"require-dev": {
"phpunit/phpunit": "^9.3",
"vimeo/psalm": "4.0.1"
"laravel/pint": "1.2.*",
"phpstan/phpstan": "^2.0",
"phpunit/phpunit": "^9.3"
},
"type": "library",
"autoload": {
@@ -3774,12 +3776,6 @@
"license": [
"MIT"
],
"authors": [
{
"name": "Eldad Fux",
"email": "eldad@appwrite.io"
}
],
"description": "A simple Config library to managing application config variables",
"keywords": [
"config",
@@ -3790,9 +3786,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/config/issues",
"source": "https://github.com/utopia-php/config/tree/0.2.2"
"source": "https://github.com/utopia-php/config/tree/feat-config-adapters"
},
"time": "2020-10-24T09:49:09+00:00"
"time": "2025-11-18T14:59:26+00:00"
},
{
"name": "utopia-php/console",
@@ -4212,16 +4208,16 @@
},
{
"name": "utopia-php/framework",
"version": "0.33.29",
"version": "0.33.30",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/http.git",
"reference": "6e63939fdb33b847f92839499cd6e8df626c278d"
"reference": "07cf699a7c47bd1a03b4da1812f1719a66b3c924"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/http/zipball/6e63939fdb33b847f92839499cd6e8df626c278d",
"reference": "6e63939fdb33b847f92839499cd6e8df626c278d",
"url": "https://api.github.com/repos/utopia-php/http/zipball/07cf699a7c47bd1a03b4da1812f1719a66b3c924",
"reference": "07cf699a7c47bd1a03b4da1812f1719a66b3c924",
"shasum": ""
},
"require": {
@@ -4253,9 +4249,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/http/issues",
"source": "https://github.com/utopia-php/http/tree/0.33.29"
"source": "https://github.com/utopia-php/http/tree/0.33.30"
},
"time": "2025-11-14T06:33:29+00:00"
"time": "2025-11-18T12:18:00+00:00"
},
{
"name": "utopia-php/image",
@@ -8895,9 +8891,18 @@
"time": "2024-03-07T20:33:40+00:00"
}
],
"aliases": [],
"aliases": [
{
"package": "utopia-php/config",
"version": "dev-feat-config-adapters",
"alias": "1.0.0",
"alias_normalized": "1.0.0.0"
}
],
"minimum-stability": "stable",
"stability-flags": {},
"stability-flags": {
"utopia-php/config": 20
},
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
@@ -8921,5 +8926,5 @@
"platform-overrides": {
"php": "8.3"
},
"plugin-api-version": "2.6.0"
"plugin-api-version": "2.3.0"
}