add initial solution (made with copilot)

This commit is contained in:
2026-07-13 12:05:43 +02:00
commit 250ee892dc
25 changed files with 860 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
<?php
// bootstrap.php
// Posizione consigliata: project_root/bootstrap.php
require_once __DIR__ . '/vendor/autoload.php';
use Core\Container;
use Core\Config;
use Core\RateLimiter\RateLimiterInterface;
use Core\RateLimiter\FileRateLimiter;
use Core\RateLimiter\InMemoryRateLimiter;
use Psr\Log\LoggerInterface;
use Core\LoggerFactory;
use Services\ExternalApiService;
$container = new Container();
// Rate limiter driver configurabile via config or env: 'file' or 'memory'
$rlDriver = Config::get('rate_limiter_driver', 'file');
if ($rlDriver === 'memory') {
$container->singleton(RateLimiterInterface::class, function($c) {
$requests = (int) \Core\Config::get('rate_limit_requests', 100);
$window = (int) \Core\Config::get('rate_limit_window_seconds', 60);
return new InMemoryRateLimiter($requests, $window);
});
} else {
$container->singleton(RateLimiterInterface::class, function($c) {
$dir = Config::get('rate_limit_storage_dir', sys_get_temp_dir() . '/api_rate_limit');
return new FileRateLimiter($dir);
});
}
// Logger binding as PSR LoggerInterface
$container->singleton(LoggerInterface::class, function($c) {
// LoggerFactory::create returns a Monolog\Logger instance
return LoggerFactory::create(Config::get('log_ident', 'api'));
});
// External API service binding
$container->singleton(ExternalApiService::class, function($c) {
return new ExternalApiService();
});
// If you have other services, bind them here, for example:
// $container->singleton(SomeService::class, function($c) {
// return new SomeService($c->make(LoggerInterface::class), ...);
// });
return $container;