Implement Trakt config loading from JSON file with ENV fallback

This commit is contained in:
Dan Jones 2025-11-16 22:52:07 -06:00
commit f19afc41f0
3 changed files with 180 additions and 11 deletions

View file

@ -37,7 +37,8 @@
"laravel-zero/framework": "^10.0", "laravel-zero/framework": "^10.0",
"nunomaduro/termwind": "^1.3", "nunomaduro/termwind": "^1.3",
"php-ffmpeg/php-ffmpeg": "^1.0", "php-ffmpeg/php-ffmpeg": "^1.0",
"spatie/laravel-data": "^2.0" "spatie/laravel-data": "^2.0",
"xdg/base-directory": "^1.2"
}, },
"require-dev": { "require-dev": {
"fakerphp/faker": "^1.9.1", "fakerphp/faker": "^1.9.1",

160
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "9ebd8521e376754effa9bc94f7afbc9e", "content-hash": "dbc82eba2362bad2cc7266710afb0827",
"packages": [ "packages": [
{ {
"name": "brick/math", "name": "brick/math",
@ -5166,6 +5166,76 @@
], ],
"time": "2024-09-25T14:21:43+00:00" "time": "2024-09-25T14:21:43+00:00"
}, },
{
"name": "symfony/filesystem",
"version": "v6.4.24",
"source": {
"type": "git",
"url": "https://github.com/symfony/filesystem.git",
"reference": "75ae2edb7cdcc0c53766c30b0a2512b8df574bd8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/filesystem/zipball/75ae2edb7cdcc0c53766c30b0a2512b8df574bd8",
"reference": "75ae2edb7cdcc0c53766c30b0a2512b8df574bd8",
"shasum": ""
},
"require": {
"php": ">=8.1",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-mbstring": "~1.8"
},
"require-dev": {
"symfony/process": "^5.4|^6.4|^7.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\Filesystem\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Provides basic utilities for the filesystem",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/filesystem/tree/v6.4.24"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://github.com/nicolas-grekas",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2025-07-10T08:14:14+00:00"
},
{ {
"name": "symfony/finder", "name": "symfony/finder",
"version": "v6.4.24", "version": "v6.4.24",
@ -6907,6 +6977,94 @@
"source": "https://github.com/webmozarts/assert/tree/1.12.0" "source": "https://github.com/webmozarts/assert/tree/1.12.0"
}, },
"time": "2025-10-20T12:43:39+00:00" "time": "2025-10-20T12:43:39+00:00"
},
{
"name": "xdg/base-directory",
"version": "1.2",
"source": {
"type": "git",
"url": "https://github.com/php-xdg/base-directory.git",
"reference": "7a91de4c387e9e0d31b8ab6aa564dc85f546b381"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-xdg/base-directory/zipball/7a91de4c387e9e0d31b8ab6aa564dc85f546b381",
"reference": "7a91de4c387e9e0d31b8ab6aa564dc85f546b381",
"shasum": ""
},
"require": {
"php": ">=8.1",
"symfony/filesystem": "^5.4||^6.0",
"xdg/environment": "^2.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Xdg\\BaseDirectory\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "ju1ius",
"email": "jules.bernable@gmail.com"
}
],
"description": "Implementation of the XDG Base Directory Specification",
"support": {
"issues": "https://github.com/php-xdg/base-directory/issues",
"source": "https://github.com/php-xdg/base-directory/tree/1.2"
},
"time": "2023-03-02T08:43:12+00:00"
},
{
"name": "xdg/environment",
"version": "2.1",
"source": {
"type": "git",
"url": "https://github.com/php-xdg/environment.git",
"reference": "d626d63e902150bbf326756e4b78eea461fd7c12"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-xdg/environment/zipball/d626d63e902150bbf326756e4b78eea461fd7c12",
"reference": "d626d63e902150bbf326756e4b78eea461fd7c12",
"shasum": ""
},
"require": {
"php": ">=8.1"
},
"type": "library",
"autoload": {
"psr-4": {
"Xdg\\Environment\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "ju1ius",
"email": "jules.bernable@gmail.com"
}
],
"description": "An abstraction layer over environment variables.",
"keywords": [
"environment",
"environment-variables",
"freedesktop",
"xdg"
],
"support": {
"issues": "https://github.com/php-xdg/environment/issues",
"source": "https://github.com/php-xdg/environment/tree/2.1"
},
"time": "2023-03-13T19:24:46+00:00"
} }
], ],
"packages-dev": [ "packages-dev": [

View file

@ -1,11 +1,21 @@
<?php <?php
return [ use Xdg\BaseDirectory\XdgBaseDirectory as Xdg;
'app_id' => env('TRAKT_APP_ID'), use Illuminate\Support\Arr;
'app_secret' => env('TRAKT_APP_secret'),
'redirect_uri' => env('TRAKT_REDIRECT_URI', 'urn:ietf:wg:oauth:2.0:oob'), $data = [];
'login' => [
'device' => json_decode(env('TRAKT_DEVICE_RESP', '{}}'), true), $xdg = Xdg::fromEnvironment();
'oauth' => json_decode(env('TRAKT_OAUTH_RESP', '{}}'), true), $path = $xdg->findDataPath("trakt/data.json", file_exists(...));
], if (file_exists($path)) {
]; $data = json_decode(file_get_contents($path), true);
}
$data = Arr::add($data, 'app_id', env('TRAKT_APP_ID'));
$data = Arr::add($data, 'app_secret', env('TRAKT_APP_SECRET'));
$data = Arr::add($data, 'redirect_uri', env('TRAKT_REDIRECT_URI', 'urn:ietf:wg:oauth:2.0:oob'));
$data['login'] = $data['login'] ?? [];
$data['login'] = Arr::add($data['login'], 'device', json_decode(env('TRAKT_DEVICE_RESP', '{}'), true));
$data['login'] = Arr::add($data['login'], 'oauth', json_decode(env('TRAKT_OAUTH_RESP', '{}'), true));
return $data;