diff --git a/app/dependencies.php b/app/dependencies.php index 4c0086b8..411a193d 100644 --- a/app/dependencies.php +++ b/app/dependencies.php @@ -16,12 +16,12 @@ use Courier\Serializer\IgBinarySerializer; use Courier\Transport\AmqpTransport; use DI\ContainerBuilder; +use League\Config\ConfigurationInterface; use Monolog\Handler\StreamHandler; use Monolog\Logger; use Monolog\Processor\UidProcessor; use Nyholm\Dsn\DsnParser; use Nyholm\Psr7\Factory\Psr17Factory; -use PackageHealth\PHP\Application\Settings\SettingsInterface; use Psr\Cache\CacheItemPoolInterface; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; @@ -34,6 +34,7 @@ use Symfony\Component\Cache\Adapter\ApcuAdapter; use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\Cache\Adapter\ChainAdapter; +use Symfony\Component\Cache\Adapter\NullAdapter; use Symfony\Component\Cache\Adapter\RedisAdapter; use function DI\autowire; @@ -48,10 +49,11 @@ ); }, Bus::class => function (ContainerInterface $container): Bus { - $settings = $container->get(SettingsInterface::class); + /** @var \League\Config\ConfigurationInterface */ + $config = $container->get(ConfigurationInterface::class); - $amqp = AmqpTransport::fromDsn($settings->getString('queue.dsn')); - $amqp->setPrefetchCount($settings->getInt('queue.prefetch', 25)); + $amqp = AmqpTransport::fromDsn($config->get('queue.dsn')); + $amqp->setPrefetchCount((int)$config->get('queue.prefetch')); return new Bus( new SimpleRouter(), @@ -59,11 +61,16 @@ ); }, CacheItemPoolInterface::class => function (ContainerInterface $container): CacheItemPoolInterface { - $settings = $container->get(SettingsInterface::class); + /** @var \League\Config\ConfigurationInterface */ + $config = $container->get(ConfigurationInterface::class); - // disables cache by using a black hole driver - if ($settings->has('cache') === false || $settings->getBool('cache.enabled', false) === false) { - return new ArrayAdapter( + // disables cache by using a null adapter + if ((bool)$config->get('cache.enabled') === false) { + return new NullAdapter(); + } + + $adapters = [ + new ArrayAdapter( // the default lifetime (in seconds) for cache items that do not define their // own lifetime, with a value 0 causing items to be stored indefinitely (i.e. // until the current PHP process finishes) @@ -79,20 +86,16 @@ // the maximum number of items that can be stored in the cache. When the limit // is reached, cache follows the LRU model (least recently used items are deleted) maxItems: 0 - ); - } - - $adapters = [ - new ArrayAdapter() + ) ]; - if ($settings->has('cache.apcu') && $settings->getBool('cache.apcu.enabled', false)) { + if ((bool)$config->get('cache.apcu.enabled') === true) { $adapters[] = new ApcuAdapter(); } - if ($settings->has('cache.redis') && $settings->getBool('cache.redis.enabled', false)) { + if ((bool)$config->get('cache.redis.enabled') === true) { $adapters[] = new RedisAdapter( - RedisAdapter::createConnection($settings->getString('cache.redis.dsn')) + RedisAdapter::createConnection($config->get('cache.redis.dsn')) ); } @@ -112,24 +115,26 @@ return $consumer; }, LoggerInterface::class => function (ContainerInterface $container): LoggerInterface { - $settings = $container->get(SettingsInterface::class); + /** @var \League\Config\ConfigurationInterface */ + $config = $container->get(ConfigurationInterface::class); - $logger = new Logger($settings->getString('logger.name')); + $logger = new Logger('app'); $processor = new UidProcessor(); $logger->pushProcessor($processor); $handler = new StreamHandler( - $settings->getString('logger.path'), - $settings->getString('logger.level') + $config->get('logging.path'), + $config->get('logging.level') ); $logger->pushHandler($handler); return $logger; }, PDO::class => function (ContainerInterface $container): PDO { - $settings = $container->get(SettingsInterface::class); - $dsn = DsnParser::parse($settings->getString('db.dsn')); + /** @var \League\Config\ConfigurationInterface */ + $config = $container->get(ConfigurationInterface::class); + $dsn = DsnParser::parse($config->get('db.dsn')); return new PDO( sprintf( diff --git a/app/repositories.php b/app/repositories.php index d202eeb3..5f3e5b6d 100644 --- a/app/repositories.php +++ b/app/repositories.php @@ -2,7 +2,6 @@ declare(strict_types = 1); use DI\ContainerBuilder; -use PackageHealth\PHP\Application\Settings\SettingsInterface; use PackageHealth\PHP\Domain\Dependency\DependencyRepositoryInterface; use PackageHealth\PHP\Domain\Package\PackageRepositoryInterface; use PackageHealth\PHP\Domain\Preference\PreferenceRepositoryInterface; @@ -18,6 +17,7 @@ use PackageHealth\PHP\Infrastructure\Persistence\Stats\PdoStatsRepository; use PackageHealth\PHP\Infrastructure\Persistence\Version\CachedVersionRepository; use PackageHealth\PHP\Infrastructure\Persistence\Version\PdoVersionRepository; +use League\Config\ConfigurationInterface; use Psr\Cache\CacheItemPoolInterface; use Psr\Container\ContainerInterface; use function DI\autowire; @@ -28,9 +28,10 @@ // Dependency PdoDependencyRepository::class => autowire(PdoDependencyRepository::class), DependencyRepositoryInterface::class => static function (ContainerInterface $container): DependencyRepositoryInterface { - $settings = $container->get(SettingsInterface::class); + /** @var \League\Config\ConfigurationInterface */ + $config = $container->get(ConfigurationInterface::class); - if ($settings->has('cache') === false || $settings->getBool('cache.enabled', false) === false) { + if ((bool)$config->get('cache.enabled') === false) { return $container->get(PdoDependencyRepository::class); } @@ -42,9 +43,10 @@ // Package PdoPackageRepository::class => autowire(PdoPackageRepository::class), PackageRepositoryInterface::class => static function (ContainerInterface $container): PackageRepositoryInterface { - $settings = $container->get(SettingsInterface::class); + /** @var \League\Config\ConfigurationInterface */ + $config = $container->get(ConfigurationInterface::class); - if ($settings->has('cache') === false || $settings->getBool('cache.enabled', false) === false) { + if ((bool)$config->get('cache.enabled') === false) { return $container->get(PdoPackageRepository::class); } @@ -56,9 +58,10 @@ // Preference PdoPreferenceRepository::class => autowire(PdoPreferenceRepository::class), PreferenceRepositoryInterface::class => static function (ContainerInterface $container): PreferenceRepositoryInterface { - $settings = $container->get(SettingsInterface::class); + /** @var \League\Config\ConfigurationInterface */ + $config = $container->get(ConfigurationInterface::class); - if ($settings->has('cache') === false || $settings->getBool('cache.enabled', false) === false) { + if ((bool)$config->get('cache.enabled') === false) { return $container->get(PdoPreferenceRepository::class); } @@ -70,9 +73,10 @@ // Stats PdoStatsRepository::class => autowire(PdoStatsRepository::class), StatsRepositoryInterface::class => static function (ContainerInterface $container): StatsRepositoryInterface { - $settings = $container->get(SettingsInterface::class); + /** @var \League\Config\ConfigurationInterface */ + $config = $container->get(ConfigurationInterface::class); - if ($settings->has('cache') === false || $settings->getBool('cache.enabled', false) === false) { + if ((bool)$config->get('cache.enabled') === false) { return $container->get(PdoStatsRepository::class); } @@ -84,9 +88,10 @@ // Version PdoVersionRepository::class => autowire(PdoVersionRepository::class), VersionRepositoryInterface::class => static function (ContainerInterface $container): VersionRepositoryInterface { - $settings = $container->get(SettingsInterface::class); + /** @var \League\Config\ConfigurationInterface */ + $config = $container->get(ConfigurationInterface::class); - if ($settings->has('cache') === false || $settings->getBool('cache.enabled', false) === false) { + if ((bool)$config->get('cache.enabled') === false) { return $container->get(PdoVersionRepository::class); } diff --git a/app/settings.php b/app/settings.php index 197eecda..d9e31914 100644 --- a/app/settings.php +++ b/app/settings.php @@ -2,19 +2,81 @@ declare(strict_types = 1); use DI\ContainerBuilder; -use PackageHealth\PHP\Application\Settings\Settings; -use PackageHealth\PHP\Application\Settings\SettingsInterface; +use League\Config\Configuration; +use League\Config\ConfigurationInterface; +use Nette\Schema\Expect; use Psr\Log\LogLevel; return static function (ContainerBuilder $containerBuilder): void { // Global Settings Object $containerBuilder->addDefinitions( [ - SettingsInterface::class => static function (): SettingsInterface { - return new Settings( + ConfigurationInterface::class => static function (): ConfigurationInterface { + // config schema + $config = new Configuration( + [ + 'cache' => Expect::structure( + [ + 'enabled' => Expect::bool(false), + 'apcu' => Expect::structure( + [ + 'enabled' => Expect::bool(false) + ] + ), + 'redis' => Expect::structure( + [ + 'enabled' => Expect::bool(false), + 'dsn' => Expect::string('redis://localhost:6379') + ] + ) + ] + ), + 'db' => Expect::structure( + [ + 'dsn' => Expect::string('pgsql://postgres@localhost:5432/postgres') + ] + ), + 'logging' => Expect::structure( + [ + 'enabled' => Expect::bool(false), + 'level' => Expect::string(LogLevel::INFO), + 'path' => Expect::string()->assert( + static function (string $file): bool { + return $file === 'php://stdout' || is_writeable(dirname($file)); + } + ) + ] + ), + 'queue' => Expect::structure( + [ + 'dsn' => Expect::string('amqp://guest:guest@localhost:5672/'), + 'prefetch' => Expect::int(100) + ] + ), + 'slim' => Expect::structure( + [ + // Returns a detailed HTML page with error details and + // a stack trace. Should be disabled in production. + 'displayErrorDetails' => Expect::bool(false), + // Whether to display errors on the internal PHP log or not. + 'logErrors' => Expect::bool(true), + // If true, display full errors with message and stack trace on the PHP log. + // If false, display only "Slim Application Error" on the PHP log. + // Doesn't do anything when "logErrors" is false. + 'logErrorDetails' => Expect::bool(true) + ] + ) + ] + ); + + // actual values + $config->merge( [ 'cache' => [ 'enabled' => PHP_SAPI !== 'cli', + 'apcu' => [ + 'enabled' => extension_loaded('apcu') === true && apcu_enabled() && PHP_SAPI === 'fpm-fcgi' + ], 'redis' => [ 'enabled' => extension_loaded('redis') === true, 'dsn' => sprintf( @@ -46,16 +108,25 @@ ), 'prefetch' => 100 ], - 'displayErrorDetails' => (isset($_ENV['PHP_ENV']) === false || $_ENV['PHP_ENV'] === 'dev'), - 'logError' => true, - 'logErrorDetails' => true, - 'logger' => [ - 'name' => 'slim-app', - 'path' => isset($_ENV['DOCKER']) ? 'php://stdout' : __DIR__ . '/../logs/app.log', - 'level' => isset($_ENV['PHP_ENV']) === false || $_ENV['PHP_ENV'] === 'dev' ? LogLevel::DEBUG : LogLevel::INFO + 'logging' => [ + 'path' => ( + isset($_ENV['DOCKER']) === true + ? 'php://stdout' + : dirname(__DIR__) . '/application.log' + ), + 'level' => ( + $_ENV['PHP_ENV'] === 'prod' + ? LogLevel::INFO + : LogLevel::DEBUG + ) + ], + 'slim' => [ + 'displayErrorDetails' => (isset($_ENV['PHP_ENV']) === false || $_ENV['PHP_ENV'] === 'dev') ] ] ); + + return $config->reader(); } ] ); diff --git a/composer.json b/composer.json index 905c16c1..478edcdf 100644 --- a/composer.json +++ b/composer.json @@ -51,6 +51,7 @@ "courier/transport-amqp": "dev-legacy", "flavioheleno/kolekto": "dev-main", "kriswallsmith/buzz": "^1.2", + "league/config": "^1.2", "middlewares/minifier": "^2.0", "middlewares/trailing-slash": "^2.0", "monolog/monolog": "^3.2", diff --git a/composer.lock b/composer.lock index aca249f8..0583491a 100644 --- a/composer.lock +++ b/composer.lock @@ -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": "c11bf059e7547cb29aaa3b3eb8460b67", + "content-hash": "5863fd26f1dfe15306a41eb3229fc508", "packages": [ { "name": "badges/poser", @@ -809,6 +809,81 @@ }, "time": "2023-05-08T13:17:05+00:00" }, + { + "name": "dflydev/dot-access-data", + "version": "v3.0.2", + "source": { + "type": "git", + "url": "https://github.com/dflydev/dflydev-dot-access-data.git", + "reference": "f41715465d65213d644d3141a6a93081be5d3549" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/dflydev/dflydev-dot-access-data/zipball/f41715465d65213d644d3141a6a93081be5d3549", + "reference": "f41715465d65213d644d3141a6a93081be5d3549", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^0.12.42", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.3", + "scrutinizer/ocular": "1.6.0", + "squizlabs/php_codesniffer": "^3.5", + "vimeo/psalm": "^4.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Dflydev\\DotAccessData\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Dragonfly Development Inc.", + "email": "info@dflydev.com", + "homepage": "http://dflydev.com" + }, + { + "name": "Beau Simensen", + "email": "beau@dflydev.com", + "homepage": "http://beausimensen.com" + }, + { + "name": "Carlos Frutos", + "email": "carlos@kiwing.it", + "homepage": "https://github.com/cfrutos" + }, + { + "name": "Colin O'Dell", + "email": "colinodell@gmail.com", + "homepage": "https://www.colinodell.com" + } + ], + "description": "Given a deep data structure, access data by dot notation.", + "homepage": "https://github.com/dflydev/dflydev-dot-access-data", + "keywords": [ + "access", + "data", + "dot", + "notation" + ], + "support": { + "issues": "https://github.com/dflydev/dflydev-dot-access-data/issues", + "source": "https://github.com/dflydev/dflydev-dot-access-data/tree/v3.0.2" + }, + "time": "2022-10-27T11:44:00+00:00" + }, { "name": "flavioheleno/kolekto", "version": "dev-main", @@ -1103,6 +1178,88 @@ }, "time": "2023-07-14T13:56:28+00:00" }, + { + "name": "league/config", + "version": "v1.2.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/config.git", + "reference": "754b3604fb2984c71f4af4a9cbe7b57f346ec1f3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/config/zipball/754b3604fb2984c71f4af4a9cbe7b57f346ec1f3", + "reference": "754b3604fb2984c71f4af4a9cbe7b57f346ec1f3", + "shasum": "" + }, + "require": { + "dflydev/dot-access-data": "^3.0.1", + "nette/schema": "^1.2", + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.8.2", + "phpunit/phpunit": "^9.5.5", + "scrutinizer/ocular": "^1.8.1", + "unleashedtech/php-coding-standard": "^3.1", + "vimeo/psalm": "^4.7.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.2-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Config\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Colin O'Dell", + "email": "colinodell@gmail.com", + "homepage": "https://www.colinodell.com", + "role": "Lead Developer" + } + ], + "description": "Define configuration arrays with strict schemas and access values with dot notation", + "homepage": "https://config.thephpleague.com", + "keywords": [ + "array", + "config", + "configuration", + "dot", + "dot-access", + "nested", + "schema" + ], + "support": { + "docs": "https://config.thephpleague.com/", + "issues": "https://github.com/thephpleague/config/issues", + "rss": "https://github.com/thephpleague/config/releases.atom", + "source": "https://github.com/thephpleague/config" + }, + "funding": [ + { + "url": "https://www.colinodell.com/sponsor", + "type": "custom" + }, + { + "url": "https://www.paypal.me/colinpodell/10.00", + "type": "custom" + }, + { + "url": "https://github.com/colinodell", + "type": "github" + } + ], + "time": "2022-12-11T20:36:23+00:00" + }, { "name": "matthiasmullie/minify", "version": "1.3.71", @@ -1542,6 +1699,155 @@ ], "time": "2023-06-21T08:46:11+00:00" }, + { + "name": "nette/schema", + "version": "v1.2.4", + "source": { + "type": "git", + "url": "https://github.com/nette/schema.git", + "reference": "c9ff517a53903b3d4e29ec547fb20feecb05b8ab" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nette/schema/zipball/c9ff517a53903b3d4e29ec547fb20feecb05b8ab", + "reference": "c9ff517a53903b3d4e29ec547fb20feecb05b8ab", + "shasum": "" + }, + "require": { + "nette/utils": "^2.5.7 || ^3.1.5 || ^4.0", + "php": "7.1 - 8.3" + }, + "require-dev": { + "nette/tester": "^2.3 || ^2.4", + "phpstan/phpstan-nette": "^1.0", + "tracy/tracy": "^2.7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause", + "GPL-2.0-only", + "GPL-3.0-only" + ], + "authors": [ + { + "name": "David Grudl", + "homepage": "https://davidgrudl.com" + }, + { + "name": "Nette Community", + "homepage": "https://nette.org/contributors" + } + ], + "description": "📐 Nette Schema: validating data structures against a given Schema.", + "homepage": "https://nette.org", + "keywords": [ + "config", + "nette" + ], + "support": { + "issues": "https://github.com/nette/schema/issues", + "source": "https://github.com/nette/schema/tree/v1.2.4" + }, + "time": "2023-08-05T18:56:25+00:00" + }, + { + "name": "nette/utils", + "version": "v4.0.1", + "source": { + "type": "git", + "url": "https://github.com/nette/utils.git", + "reference": "9124157137da01b1f5a5a22d6486cb975f26db7e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nette/utils/zipball/9124157137da01b1f5a5a22d6486cb975f26db7e", + "reference": "9124157137da01b1f5a5a22d6486cb975f26db7e", + "shasum": "" + }, + "require": { + "php": ">=8.0 <8.4" + }, + "conflict": { + "nette/finder": "<3", + "nette/schema": "<1.2.2" + }, + "require-dev": { + "jetbrains/phpstorm-attributes": "dev-master", + "nette/tester": "^2.5", + "phpstan/phpstan": "^1.0", + "tracy/tracy": "^2.9" + }, + "suggest": { + "ext-gd": "to use Image", + "ext-iconv": "to use Strings::webalize(), toAscii(), chr() and reverse()", + "ext-intl": "to use Strings::webalize(), toAscii(), normalize() and compare()", + "ext-json": "to use Nette\\Utils\\Json", + "ext-mbstring": "to use Strings::lower() etc...", + "ext-tokenizer": "to use Nette\\Utils\\Reflection::getUseStatements()", + "ext-xml": "to use Strings::length() etc. when mbstring is not available" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause", + "GPL-2.0-only", + "GPL-3.0-only" + ], + "authors": [ + { + "name": "David Grudl", + "homepage": "https://davidgrudl.com" + }, + { + "name": "Nette Community", + "homepage": "https://nette.org/contributors" + } + ], + "description": "🛠 Nette Utils: lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.", + "homepage": "https://nette.org", + "keywords": [ + "array", + "core", + "datetime", + "images", + "json", + "nette", + "paginator", + "password", + "slugify", + "string", + "unicode", + "utf-8", + "utility", + "validation" + ], + "support": { + "issues": "https://github.com/nette/utils/issues", + "source": "https://github.com/nette/utils/tree/v4.0.1" + }, + "time": "2023-07-30T15:42:21+00:00" + }, { "name": "nikic/fast-route", "version": "v1.3.0", @@ -1851,16 +2157,16 @@ }, { "name": "php-di/invoker", - "version": "2.3.3", + "version": "2.3.4", "source": { "type": "git", "url": "https://github.com/PHP-DI/Invoker.git", - "reference": "cd6d9f267d1a3474bdddf1be1da079f01b942786" + "reference": "33234b32dafa8eb69202f950a1fc92055ed76a86" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-DI/Invoker/zipball/cd6d9f267d1a3474bdddf1be1da079f01b942786", - "reference": "cd6d9f267d1a3474bdddf1be1da079f01b942786", + "url": "https://api.github.com/repos/PHP-DI/Invoker/zipball/33234b32dafa8eb69202f950a1fc92055ed76a86", + "reference": "33234b32dafa8eb69202f950a1fc92055ed76a86", "shasum": "" }, "require": { @@ -1894,7 +2200,7 @@ ], "support": { "issues": "https://github.com/PHP-DI/Invoker/issues", - "source": "https://github.com/PHP-DI/Invoker/tree/2.3.3" + "source": "https://github.com/PHP-DI/Invoker/tree/2.3.4" }, "funding": [ { @@ -1902,7 +2208,7 @@ "type": "github" } ], - "time": "2021-12-13T09:22:56+00:00" + "time": "2023-09-08T09:24:21+00:00" }, { "name": "php-di/php-di", @@ -7015,16 +7321,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.23.1", + "version": "1.24.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "846ae76eef31c6d7790fac9bc399ecee45160b26" + "reference": "3510b0a6274cc42f7219367cb3abfc123ffa09d6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/846ae76eef31c6d7790fac9bc399ecee45160b26", - "reference": "846ae76eef31c6d7790fac9bc399ecee45160b26", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/3510b0a6274cc42f7219367cb3abfc123ffa09d6", + "reference": "3510b0a6274cc42f7219367cb3abfc123ffa09d6", "shasum": "" }, "require": { @@ -7056,22 +7362,22 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.23.1" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.0" }, - "time": "2023-08-03T16:32:59+00:00" + "time": "2023-09-07T20:46:32+00:00" }, { "name": "phpstan/phpstan", - "version": "1.10.32", + "version": "1.10.33", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "c47e47d3ab03137c0e121e77c4d2cb58672f6d44" + "reference": "03b1cf9f814ba0863c4e9affea49a4d1ed9a2ed1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/c47e47d3ab03137c0e121e77c4d2cb58672f6d44", - "reference": "c47e47d3ab03137c0e121e77c4d2cb58672f6d44", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/03b1cf9f814ba0863c4e9affea49a4d1ed9a2ed1", + "reference": "03b1cf9f814ba0863c4e9affea49a4d1ed9a2ed1", "shasum": "" }, "require": { @@ -7120,20 +7426,20 @@ "type": "tidelift" } ], - "time": "2023-08-24T21:54:50+00:00" + "time": "2023-09-04T12:20:53+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "10.1.3", + "version": "10.1.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "be1fe461fdc917de2a29a452ccf2657d325b443d" + "reference": "cd59bb34756a16ca8253ce9b2909039c227fff71" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/be1fe461fdc917de2a29a452ccf2657d325b443d", - "reference": "be1fe461fdc917de2a29a452ccf2657d325b443d", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/cd59bb34756a16ca8253ce9b2909039c227fff71", + "reference": "cd59bb34756a16ca8253ce9b2909039c227fff71", "shasum": "" }, "require": { @@ -7190,7 +7496,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.3" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.4" }, "funding": [ { @@ -7198,7 +7504,7 @@ "type": "github" } ], - "time": "2023-07-26T13:45:28+00:00" + "time": "2023-08-31T14:04:38+00:00" }, { "name": "phpunit/php-file-iterator", @@ -7326,16 +7632,16 @@ }, { "name": "phpunit/php-text-template", - "version": "3.0.0", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "9f3d3709577a527025f55bcf0f7ab8052c8bb37d" + "reference": "0c7b06ff49e3d5072f057eb1fa59258bf287a748" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/9f3d3709577a527025f55bcf0f7ab8052c8bb37d", - "reference": "9f3d3709577a527025f55bcf0f7ab8052c8bb37d", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/0c7b06ff49e3d5072f057eb1fa59258bf287a748", + "reference": "0c7b06ff49e3d5072f057eb1fa59258bf287a748", "shasum": "" }, "require": { @@ -7373,7 +7679,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-text-template/issues", - "source": "https://github.com/sebastianbergmann/php-text-template/tree/3.0.0" + "security": "https://github.com/sebastianbergmann/php-text-template/security/policy", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/3.0.1" }, "funding": [ { @@ -7381,20 +7688,20 @@ "type": "github" } ], - "time": "2023-02-03T06:56:46+00:00" + "time": "2023-08-31T14:07:24+00:00" }, { "name": "phpunit/phpunit", - "version": "10.3.2", + "version": "10.3.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "0dafb1175c366dd274eaa9a625e914451506bcd1" + "reference": "241ed4dd0db1c096984e62d414c4e1ac8d5dbff4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/0dafb1175c366dd274eaa9a625e914451506bcd1", - "reference": "0dafb1175c366dd274eaa9a625e914451506bcd1", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/241ed4dd0db1c096984e62d414c4e1ac8d5dbff4", + "reference": "241ed4dd0db1c096984e62d414c4e1ac8d5dbff4", "shasum": "" }, "require": { @@ -7466,7 +7773,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/10.3.2" + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.3.3" }, "funding": [ { @@ -7482,7 +7789,7 @@ "type": "tidelift" } ], - "time": "2023-08-15T05:34:23+00:00" + "time": "2023-09-05T04:34:51+00:00" }, { "name": "psy/psysh", @@ -7566,12 +7873,12 @@ "source": { "type": "git", "url": "https://github.com/Roave/SecurityAdvisories.git", - "reference": "3a677ef3f90ef5ac5280ee470272a162878f3998" + "reference": "244ae4d2e7c97fd65c23c34990f4e98571fd4729" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/3a677ef3f90ef5ac5280ee470272a162878f3998", - "reference": "3a677ef3f90ef5ac5280ee470272a162878f3998", + "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/244ae4d2e7c97fd65c23c34990f4e98571fd4729", + "reference": "244ae4d2e7c97fd65c23c34990f4e98571fd4729", "shasum": "" }, "conflict": { @@ -7628,7 +7935,7 @@ "brotkrueml/schema": "<1.13.1|>=2,<2.5.1", "brotkrueml/typo3-matomo-integration": "<1.3.2", "buddypress/buddypress": "<7.2.1", - "bugsnag/bugsnag-laravel": ">=2,<2.0.2", + "bugsnag/bugsnag-laravel": "<2.0.2", "bytefury/crater": "<6.0.2", "cachethq/cachet": "<2.5.1", "cakephp/cakephp": "<3.10.3|>=4,<4.0.10|>=4.1,<4.1.4|>=4.2,<4.2.12|>=4.3,<4.3.11|>=4.4,<4.4.10", @@ -7682,7 +7989,7 @@ "doctrine/orm": ">=2,<2.4.8|>=2.5,<2.5.1|>=2.8.3,<2.8.4", "dolibarr/dolibarr": "<17.0.1", "dompdf/dompdf": "<2.0.2|==2.0.2", - "drupal/core": ">=7,<7.96|>=8,<9.4.14|>=9.5,<9.5.8|>=10,<10.0.8", + "drupal/core": "<9.4.14|>=9.5,<9.5.8|>=10,<10.0.8", "drupal/drupal": ">=6,<6.38|>=7,<7.80|>=8,<8.9.16|>=9,<9.1.12|>=9.2,<9.2.4", "dweeves/magmi": "<=0.7.24", "ecodev/newsletter": "<=4", @@ -7814,7 +8121,7 @@ "kimai/kimai": "<1.1", "kitodo/presentation": "<3.2.3|>=3.3,<3.3.4", "klaviyo/magento2-extension": ">=1,<3", - "knplabs/knp-snappy": "<1.4.2", + "knplabs/knp-snappy": "<=1.4.2", "kohana/core": "<3.3.3", "krayin/laravel-crm": "<1.2.2", "kreait/firebase-php": ">=3.2,<3.8.1", @@ -8071,6 +8378,7 @@ "symfony/serializer": ">=2,<2.0.11|>=4.1,<4.4.35|>=5,<5.3.12", "symfony/symfony": "<4.4.50|>=5,<5.4.20|>=6,<6.0.20|>=6.1,<6.1.12|>=6.2,<6.2.6", "symfony/translation": ">=2,<2.0.17", + "symfony/ux-autocomplete": "<2.11.2", "symfony/validator": ">=2,<2.0.24|>=2.1,<2.1.12|>=2.2,<2.2.5|>=2.3,<2.3.3", "symfony/var-exporter": ">=4.2,<4.2.12|>=4.3,<4.3.8", "symfony/web-profiler-bundle": ">=2,<2.3.19|>=2.4,<2.4.9|>=2.5,<2.5.4", @@ -8112,6 +8420,7 @@ "typo3/swiftmailer": ">=4.1,<4.1.99|>=5.4,<5.4.5", "typo3fluid/fluid": ">=2,<2.0.8|>=2.1,<2.1.7|>=2.2,<2.2.4|>=2.3,<2.3.7|>=2.4,<2.4.4|>=2.5,<2.5.11|>=2.6,<2.6.10", "ua-parser/uap-php": "<3.8", + "uasoft-indonesia/badaso": "<=2.9.7", "unisharp/laravel-filemanager": "<=2.5.1", "userfrosting/userfrosting": ">=0.3.1,<4.6.3", "usmanhalalit/pixie": "<1.0.3|>=2,<2.0.2", @@ -8223,7 +8532,7 @@ "type": "tidelift" } ], - "time": "2023-08-30T22:04:36+00:00" + "time": "2023-09-11T14:04:42+00:00" }, { "name": "sanmai/later", @@ -8783,16 +9092,16 @@ }, { "name": "sebastian/exporter", - "version": "5.0.0", + "version": "5.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "f3ec4bf931c0b31e5b413f5b4fc970a7d03338c0" + "reference": "32ff03d078fed1279c4ec9a407d08c5e9febb480" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/f3ec4bf931c0b31e5b413f5b4fc970a7d03338c0", - "reference": "f3ec4bf931c0b31e5b413f5b4fc970a7d03338c0", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/32ff03d078fed1279c4ec9a407d08c5e9febb480", + "reference": "32ff03d078fed1279c4ec9a407d08c5e9febb480", "shasum": "" }, "require": { @@ -8848,7 +9157,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/exporter/issues", - "source": "https://github.com/sebastianbergmann/exporter/tree/5.0.0" + "security": "https://github.com/sebastianbergmann/exporter/security/policy", + "source": "https://github.com/sebastianbergmann/exporter/tree/5.0.1" }, "funding": [ { @@ -8856,7 +9166,7 @@ "type": "github" } ], - "time": "2023-02-03T07:06:49+00:00" + "time": "2023-09-08T04:46:58+00:00" }, { "name": "sebastian/global-state", @@ -9835,5 +10145,5 @@ "composer-runtime-api": "^2" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/public/index.php b/public/index.php index d2bde9d1..32295187 100644 --- a/public/index.php +++ b/public/index.php @@ -6,7 +6,7 @@ use PackageHealth\PHP\Application\Handler\HttpErrorHandler; use PackageHealth\PHP\Application\Handler\ShutdownHandler; use PackageHealth\PHP\Application\ResponseEmitter\ResponseEmitter; -use PackageHealth\PHP\Application\Settings\SettingsInterface; +use League\Config\ConfigurationInterface; use Slim\Factory\AppFactory; use Slim\Factory\ServerRequestCreatorFactory; @@ -82,10 +82,10 @@ $routeCollector->setCacheFile(__DIR__ . '/../var/cache/routes.cache'); } -/** @var SettingsInterface $settings */ -$settings = $container->get(SettingsInterface::class); +/** @var \League\Config\ConfigurationInterface $settings */ +$config = $container->get(ConfigurationInterface::class); -$displayErrorDetails = $settings->getBool('displayErrorDetails'); +$displayErrorDetails = (bool)$config->get('slim.displayErrorDetails'); // Create Request object from globals $serverRequestCreator = ServerRequestCreatorFactory::create(); @@ -107,8 +107,8 @@ // Add Error Middleware $errorMiddleware = $app->addErrorMiddleware( $displayErrorDetails, - $settings->getBool('logError'), - $settings->getBool('logErrorDetails') + (bool)$config->get('slim.logErrors'), + (bool)$config->get('slim.logErrorDetails') ); $errorMiddleware->setDefaultErrorHandler($errorHandler); diff --git a/src/Application/Settings/Settings.php b/src/Application/Settings/Settings.php deleted file mode 100644 index 08311bca..00000000 --- a/src/Application/Settings/Settings.php +++ /dev/null @@ -1,143 +0,0 @@ - - */ - private array $config = []; - /** - * @var array - */ - private array $envVar = []; - - private function getPathEntry(string $entry) { - $path = explode('.', $entry); - $walk = $this->config; - while (count($path)) { - $item = array_shift($path); - if (isset($walk[$item]) === false) { - return null; - } - - $walk = $walk[$item]; - } - - return $walk; - } - - private function getPathValue(string $entry) { - $value = $this->getPathEntry($entry); - if ($value === null || is_array($value)) { - return null; - } - - return $value; - } - - private function normalize(string $entry): string { - return str_replace(['-', '.'], '_', strtoupper($entry)); - } - - public static function fromJson(string $path): self { - $content = file_get_contents($path); - if ($content === false) { - throw new InvalidArgumentException( - sprintf( - 'Failed to read content from "%s"', - $path - ) - ); - } - - return new self( - json_decode( - $content, - true, - 512, - JSON_THROW_ON_ERROR - ) - ); - } - - public function __construct(array $config) { - if (empty($config)) { - $this->envVar = array_merge($_ENV, $_SERVER, getenv()); - - return; - } - - $this->config = $config; - } - - public function has(string $entry): bool { - $value = $this->getPathEntry($entry); - if ($value === null) { - $varName = $this->normalize($entry); - - return isset($this->envVar[$varName]); - } - - return true; - } - - public function getString(string $entry, string $default = ''): string { - $value = $this->getPathValue($entry); - if ($value === null) { - $varName = $this->normalize($entry); - if (isset($this->envVar[$varName])) { - return (string)$this->envVar[$varName]; - } - - return $default; - } - - return (string)$value; - } - - public function getInt(string $entry, int $default = 0): int { - $value = $this->getPathValue($entry); - if ($value === null) { - $varName = $this->normalize($entry); - if (isset($this->envVar[$varName])) { - return (int)$this->envVar[$varName]; - } - - return $default; - } - - return (int)$value; - } - - public function getFloat(string $entry, float $default = 0.0): float { - $value = $this->getPathValue($entry); - if ($value === null) { - $varName = $this->normalize($entry); - if (isset($this->envVar[$varName])) { - return (float)$this->envVar[$varName]; - } - - return $default; - } - - return (float)$value; - } - - public function getBool(string $entry, bool $default = false): bool { - $value = $this->getPathValue($entry); - if ($value === null) { - $varName = $this->normalize($entry); - if (isset($this->envVar[$varName])) { - return (bool)$this->envVar[$varName]; - } - - return $default; - } - - return (bool)$value; - } -} diff --git a/src/Application/Settings/SettingsInterface.php b/src/Application/Settings/SettingsInterface.php deleted file mode 100644 index 5592f67e..00000000 --- a/src/Application/Settings/SettingsInterface.php +++ /dev/null @@ -1,16 +0,0 @@ -