This commit is contained in:
Oh
2025-09-04 14:47:18 +02:00
parent a0d4bf6f91
commit d89ea02f00
9 changed files with 67 additions and 58 deletions

View File

@@ -3,7 +3,7 @@
declare(strict_types=1); declare(strict_types=1);
use App\Application\Settings\SettingsInterface; use App\Application\Settings\SettingsInterface;
use App\Service\OpenWeatherClient; use Ohrionmartin\Weather\Service\OpenWeatherClient;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use DI\ContainerBuilder; use DI\ContainerBuilder;
use Monolog\Handler\StreamHandler; use Monolog\Handler\StreamHandler;

View File

@@ -3,7 +3,7 @@
declare(strict_types=1); declare(strict_types=1);
use App\Domain\User\UserRepository; use App\Domain\User\UserRepository;
use App\Infrastructure\Persistence\User\InMemoryUserRepository; use Ohrionmartin\Weather\Infrastructure\Persistence\User\InMemoryUserRepository;
use DI\ContainerBuilder; use DI\ContainerBuilder;
return function (ContainerBuilder $containerBuilder) { return function (ContainerBuilder $containerBuilder) {

View File

@@ -4,7 +4,7 @@ declare(strict_types=1);
use App\Application\Actions\User\ListUsersAction; use App\Application\Actions\User\ListUsersAction;
use App\Application\Actions\User\ViewUserAction; use App\Application\Actions\User\ViewUserAction;
use App\Application\Actions\Weather\GetWeatherAction; use Ohrionmartin\Weather\Application\Actions\Weather\GetWeatherAction;
use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\App; use Slim\App;

View File

@@ -1,63 +1,26 @@
{ {
"name": "slim/slim-skeleton", "name": "ohrionmartin/weather",
"description": "A Slim Framework skeleton application for rapid development", "description": "Reusable Slim components for fetching weather via OpenWeather One Call API 3.0",
"keywords": [ "type": "library",
"microframework",
"rest",
"router",
"psr7"
],
"homepage": "http://github.com/slimphp/Slim-Skeleton",
"license": "MIT", "license": "MIT",
"autoload": {
"psr-4": {
"Ohrionmartin\\Weather\\": "src/"
}
},
"authors": [ "authors": [
{ {
"name": "Josh Lockhart", "name": "Oh Martin",
"email": "info@joshlockhart.com", "email": "oh@nampharm.com.na"
"homepage": "http://www.joshlockhart.com/"
},
{
"name": "Pierre Berube",
"email": "pierre@lgse.com",
"homepage": "http://www.lgse.com/"
} }
], ],
"minimum-stability": "stable",
"require": { "require": {
"php": "^7.4 || ^8.0", "ext-json": "*"
"ext-json": "*",
"guzzlehttp/guzzle": "^7",
"monolog/monolog": "^2.8",
"php-di/php-di": "^6.4",
"slim/psr7": "^1.5",
"slim/slim": "^4.10",
"vlucas/phpdotenv": "^5.6"
},
"require-dev": {
"jangregor/phpstan-prophecy": "^1.0.0",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/extension-installer": "^1.2.0",
"phpstan/phpstan": "^1.8",
"phpunit/phpunit": "^9.5.26",
"squizlabs/php_codesniffer": "^3.7"
}, },
"config": { "config": {
"allow-plugins": { "allow-plugins": {
"phpstan/extension-installer": true "phpstan/extension-installer": false
},
"process-timeout": 0,
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
} }
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"start": "php -S localhost:8080 -t public",
"test": "phpunit"
} }
} }

View File

@@ -2,9 +2,9 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Application\Actions\Weather; namespace Ohrionmartin\Weather\Application\Actions\Weather;
use App\Service\OpenWeatherClient; use Ohrionmartin\Weather\Service\OpenWeatherClient;
use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ServerRequestInterface as Request;

View File

@@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Infrastructure\Persistence\User; namespace Ohrionmartin\Weather\Infrastructure\Persistence\User;
use App\Domain\User\User; use App\Domain\User\User;
use App\Domain\User\UserNotFoundException; use App\Domain\User\UserNotFoundException;

View File

@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace Ohrionmartin\Weather\Infrastructure\Provider;
use Ohrionmartin\Weather\Application\Actions\Weather\GetWeatherAction;
use Ohrionmartin\Weather\Service\OpenWeatherClient;
use DI\ContainerBuilder;
use GuzzleHttp\Client;
use Psr\Container\ContainerInterface;
use Slim\App;
final class SlimWeatherProvider
{
public static function register(ContainerBuilder $cb): void
{
$cb->addDefinitions([
Client::class => function () {
return new Client([
'headers' => [
'Accept' => 'application/json',
'User-Agent' => 'Slim-Weather/1.0',
],
]);
},
OpenWeatherClient::class => function (ContainerInterface $c) {
$apiKey = $_ENV['OPENWEATHER_API_KEY'] ?? $_SERVER['OPENWEATHER_API_KEY'] ?? '';
$baseUrl = 'https://api.openweathermap.org/data/3.0';
if ($apiKey === '') {
throw new \RuntimeException('OPENWEATHER_API_KEY is not configured');
}
return new OpenWeatherClient($c->get(Client::class), $apiKey, $baseUrl);
},
]);
}
public static function routes(App $app): void
{
// Expose a ready-to-use endpoint for consumers (optional)
$app->get('/weather', GetWeatherAction::class);
}
}

View File

@@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Service; namespace Ohrionmartin\Weather\Service;
use GuzzleHttp\ClientInterface; use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\GuzzleException;

View File

@@ -6,7 +6,7 @@ namespace Tests\Infrastructure\Persistence\User;
use App\Domain\User\User; use App\Domain\User\User;
use App\Domain\User\UserNotFoundException; use App\Domain\User\UserNotFoundException;
use App\Infrastructure\Persistence\User\InMemoryUserRepository; use Ohrionmartin\Weather\Infrastructure\Persistence\User\InMemoryUserRepository;
use Tests\TestCase; use Tests\TestCase;
class InMemoryUserRepositoryTest extends TestCase class InMemoryUserRepositoryTest extends TestCase