From 5175ed724c28ec0b724e00779436f9e281279720 Mon Sep 17 00:00:00 2001 From: Evgeniy Kuvshinov Date: Fri, 6 Oct 2023 01:58:33 +0500 Subject: [PATCH] update psr/container >=2.0 --- .gitignore | 3 ++- Makefile | 4 +--- composer.json | 4 ++-- src/ArrayCache.php | 4 ++-- src/Container.php | 4 ++-- src/InfiniteRecursionDetector.php | 4 ++-- src/Strategy.php | 2 +- src/Strategy/Alias.php | 2 +- src/Strategy/Autowiring.php | 4 ++-- src/Strategy/Definition.php | 2 +- src/Strategy/KeyValue.php | 4 ++-- template/container.compiler.php | 4 ++-- tests/ContainerCompiledTest.php | 3 +++ 13 files changed, 23 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 2cf7a3f..19982ea 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -composer.lock \ No newline at end of file +composer.lock +vendor \ No newline at end of file diff --git a/Makefile b/Makefile index b78c686..809e536 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,6 @@ install: composer install -test: phpcs phpstan phpunit infection clean -clean: - rm -f tests/ExampleCompiled.php +test: phpcs phpstan phpunit infection update: composer update phpcs: diff --git a/composer.json b/composer.json index 77698b9..d4fa377 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "container" ], "require": { - "psr/container": "^1.0", + "psr/container": ">=2.0", "php": ">=8.0" }, "require-dev": { @@ -25,7 +25,7 @@ } }, "provide": { - "psr/container-implementation": "^1.0" + "psr/container-implementation": "^2.0" }, "autoload-dev": { "psr-4": { diff --git a/src/ArrayCache.php b/src/ArrayCache.php index 683bca2..505e49a 100644 --- a/src/ArrayCache.php +++ b/src/ArrayCache.php @@ -16,7 +16,7 @@ public function __construct(ContainerInterface $container) $this->container = $container; } - public function get($id) + public function get(string $id) { if (!array_key_exists($id, $this->values)) { $this->values[$id] = $this->container->get($id); @@ -24,7 +24,7 @@ public function get($id) return $this->values[$id]; } - public function has($id): bool + public function has(string $id): bool { return array_key_exists($id, $this->values) || $this->container->has($id); } diff --git a/src/Container.php b/src/Container.php index 2d743a6..c3ff82e 100644 --- a/src/Container.php +++ b/src/Container.php @@ -27,12 +27,12 @@ public function __construct(array $params = [], array $alias = [], array $defini ))); } - public function get($id) + public function get(string $id) { return $this->container->get($id); } - public function has($id): bool + public function has(string $id): bool { return $this->container->has($id); } diff --git a/src/InfiniteRecursionDetector.php b/src/InfiniteRecursionDetector.php index 43e9d4c..431d4a1 100644 --- a/src/InfiniteRecursionDetector.php +++ b/src/InfiniteRecursionDetector.php @@ -20,7 +20,7 @@ public function __construct(ContainerInterface $container) $this->container = $container; } - public function get($id) + public function get(string $id) { if (in_array($id, $this->calls)) { throw new InfiniteRecursion($id, $this->calls); @@ -31,7 +31,7 @@ public function get($id) return $result; } - public function has($id): bool + public function has(string $id): bool { return $this->container->has($id); } diff --git a/src/Strategy.php b/src/Strategy.php index 3c62566..575e795 100644 --- a/src/Strategy.php +++ b/src/Strategy.php @@ -28,7 +28,7 @@ public function get($id) return $provider->get($id); } - public function has($id): bool + public function has(string $id): bool { return $this->findProvider($id) !== null; } diff --git a/src/Strategy/Alias.php b/src/Strategy/Alias.php index 55baae4..b73af95 100644 --- a/src/Strategy/Alias.php +++ b/src/Strategy/Alias.php @@ -16,7 +16,7 @@ public function __construct(array $values, ContainerInterface $container) $this->container = $container; } - public function get($id) + public function get(string $id) { $result = parent::get($id); if (is_string($result)) { diff --git a/src/Strategy/Autowiring.php b/src/Strategy/Autowiring.php index 77beb1a..7f07355 100644 --- a/src/Strategy/Autowiring.php +++ b/src/Strategy/Autowiring.php @@ -28,7 +28,7 @@ public function __construct(Reflection $reflection, ContainerInterface $containe $this->alias = $alias; } - public function get($id) + public function get(string $id) { $args = []; foreach ($this->reflection->getDependencies($id) as $dependency) { @@ -49,7 +49,7 @@ public function get($id) return new $id(...$args); } - public function has($id): bool + public function has(string $id): bool { return $this->reflection->isInstantiable($id); } diff --git a/src/Strategy/Definition.php b/src/Strategy/Definition.php index f9253cd..7c0583e 100644 --- a/src/Strategy/Definition.php +++ b/src/Strategy/Definition.php @@ -16,7 +16,7 @@ public function __construct(array $values, ContainerInterface $container) $this->container = $container; } - public function get($id) + public function get(string $id) { $result = parent::get($id); if (is_callable($result)) { diff --git a/src/Strategy/KeyValue.php b/src/Strategy/KeyValue.php index 6cfc00b..b814166 100644 --- a/src/Strategy/KeyValue.php +++ b/src/Strategy/KeyValue.php @@ -21,12 +21,12 @@ public function __construct(array $values) $this->values = $values; } - public function get($id) + public function get(string $id) { return $this->values[$id]; } - public function has($id): bool + public function has(string $id): bool { return array_key_exists($id, $this->values); } diff --git a/template/container.compiler.php b/template/container.compiler.php index 08c48cf..ac4c7f2 100644 --- a/template/container.compiler.php +++ b/template/container.compiler.php @@ -41,7 +41,7 @@ public function __construct(array $params, array $alias, array $definitions) $this->containers = ; } - public function get($name) + public function get(string $name) { if (!array_key_exists($name, $this->params)) { $this->params[$name] = match($name) { @@ -66,7 +66,7 @@ public function get($name) return $this->params[$name]; } - public function has($name) + public function has(string $name): bool { return array_key_exists($name, $this->params) diff --git a/tests/ContainerCompiledTest.php b/tests/ContainerCompiledTest.php index ac1cc3e..3729d50 100644 --- a/tests/ContainerCompiledTest.php +++ b/tests/ContainerCompiledTest.php @@ -34,6 +34,9 @@ public static function tearDownAfterClass(): void if (file_exists(__DIR__ . '/ExampleCompiled.php')) { unlink(__DIR__ . '/ExampleCompiled.php'); } + if (file_exists(__DIR__ . '/TestReflectionEnabled.php')) { + unlink(__DIR__ . '/TestReflectionEnabled.php'); + } } /**