From c2aeb032cd04471280cf6481db7850a313967ce9 Mon Sep 17 00:00:00 2001 From: Miguel Muscat Date: Tue, 15 Sep 2020 18:32:36 +0200 Subject: [PATCH 1/6] Added recursive dependency detection Solution for #10 --- src/DelegatingContainer.php | 69 ++++++++++++++++----- test/functional/DelegatingContainerTest.php | 32 ++++++++++ 2 files changed, 84 insertions(+), 17 deletions(-) diff --git a/src/DelegatingContainer.php b/src/DelegatingContainer.php index d842019..884875a 100644 --- a/src/DelegatingContainer.php +++ b/src/DelegatingContainer.php @@ -38,25 +38,70 @@ public function __construct(ServiceProviderInterface $provider, PsrContainerInte * {@inheritDoc} */ public function get($id) + { + static $stack = []; + + if (array_key_exists($id, $stack)) { + $trace = implode(' -> ', array_keys($stack)) . ' -> ' . $id; + + throw new ContainerException( + $this->__("Circular dependency detected:\n%s", [$trace]), + 0, + null + ); + } + + $stack[$id] = true; + + try { + return $this->_createService($id); + } finally { + unset($stack[$id]); + } + } + + /** + * {@inheritDoc} + */ + public function has($id) + { + $services = $this->provider->getFactories(); + + return array_key_exists($id, $services); + } + + /** + * Creates a service, using the factory that corresponds to a specific key. + * + * @since [*next-version*] + * + * @param string $key The key of the service to be created. + * + * @return mixed The created service. + * + * @throws NotFoundException If no factory corresponds to the given $key. + * @throws ContainerException If an error occurred while creating the service. + */ + protected function _createService(string $key) { $provider = $this->provider; $services = $provider->getFactories(); - if (!array_key_exists($id, $services)) { + if (!array_key_exists($key, $services)) { throw new NotFoundException( - $this->__('Service not found for key "%1$s"', [$id]), + $this->__('Service not found for key "%1$s"', [$key]), 0, null ); } - $service = $services[$id]; + $service = $services[$key]; try { $service = $this->_invokeFactory($service); } catch (UnexpectedValueException $e) { throw new ContainerException( - $this->__('Could not create service "%1$s"', [$id]), + $this->__('Could not create service "%1$s"', [$key]), 0, $e ); @@ -64,17 +109,17 @@ public function get($id) $extensions = $provider->getExtensions(); - if (!array_key_exists($id, $extensions)) { + if (!array_key_exists($key, $extensions)) { return $service; } - $extension = $extensions[$id]; + $extension = $extensions[$key]; try { $service = $this->_invokeExtension($extension, $service); } catch (UnexpectedValueException $e) { throw new ContainerException( - $this->__('Could not extend service "%1$s"', [$id]), + $this->__('Could not extend service "%1$s"', [$key]), 0, $e ); @@ -83,16 +128,6 @@ public function get($id) return $service; } - /** - * {@inheritDoc} - */ - public function has($id) - { - $services = $this->provider->getFactories(); - - return array_key_exists($id, $services); - } - /** * Retrieves a service by invoking its factory. * diff --git a/test/functional/DelegatingContainerTest.php b/test/functional/DelegatingContainerTest.php index 275c8eb..fc60061 100644 --- a/test/functional/DelegatingContainerTest.php +++ b/test/functional/DelegatingContainerTest.php @@ -8,6 +8,7 @@ use Dhii\Container\TestHelpers\ServiceProviderMock; use Exception; use PHPUnit\Framework\TestCase; +use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; class DelegatingContainerTest extends TestCase @@ -87,4 +88,35 @@ public function testHasFalse() $this->assertFalse($result, 'Wrongly determined not having'); } } + + public function testRecursiveDetection() + { + { + $provider = ServiceProviderMock::create($this, [ + 'a' => function (ContainerInterface $c) { + return $c->get('b'); + }, + 'b' => function (ContainerInterface $c) { + return $c->get('c'); + }, + 'c' => function (ContainerInterface $c) { + return $c->get('a'); + }, + ]); + + $subject = new DelegatingContainer($provider); + } + { + try { + $subject->get('a'); + $this->fail('Expected exception to be thrown'); + } catch (ContainerExceptionInterface $exception) { + $this->assertStringContainsString( + 'a -> b -> c -> a', + $exception->getMessage(), + 'Exception message does not properly report circular dependency' + ); + } + } + } } From 780bb172bddcd8dba3944995d143c79fd7204129 Mon Sep 17 00:00:00 2001 From: Anton Ukhanev Date: Sat, 21 Sep 2024 19:16:08 +0200 Subject: [PATCH 2/6] Update lockfile --- .idea/containers.iml | 2 +- .idea/php.xml | 1 + composer.lock | 368 +++++++++++++++++++------------------------ 3 files changed, 160 insertions(+), 211 deletions(-) diff --git a/.idea/containers.iml b/.idea/containers.iml index 08d68ea..db3a2b7 100644 --- a/.idea/containers.iml +++ b/.idea/containers.iml @@ -79,4 +79,4 @@ - \ No newline at end of file + diff --git a/.idea/php.xml b/.idea/php.xml index 840938c..26aa214 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -92,6 +92,7 @@ + diff --git a/composer.lock b/composer.lock index bea93f6..cacdc74 100644 --- a/composer.lock +++ b/composer.lock @@ -313,27 +313,35 @@ "source": { "type": "git", "url": "https://github.com/composer/pcre.git", - "reference": "5b16e25a5355f1f3afdfc2f954a0a80aec4826a8" + "reference": "63aaeac21d7e775ff9bc9d45021e1745c97521c4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/pcre/zipball/5b16e25a5355f1f3afdfc2f954a0a80aec4826a8", - "reference": "5b16e25a5355f1f3afdfc2f954a0a80aec4826a8", + "url": "https://api.github.com/repos/composer/pcre/zipball/63aaeac21d7e775ff9bc9d45021e1745c97521c4", + "reference": "63aaeac21d7e775ff9bc9d45021e1745c97521c4", "shasum": "" }, "require": { "php": "^7.4 || ^8.0" }, + "conflict": { + "phpstan/phpstan": "<1.11.10" + }, "require-dev": { - "phpstan/phpstan": "^1.3", + "phpstan/phpstan": "^1.11.10", "phpstan/phpstan-strict-rules": "^1.1", - "symfony/phpunit-bridge": "^5" + "phpunit/phpunit": "^8 || ^9" }, "default-branch": true, "type": "library", "extra": { "branch-alias": { "dev-main": "3.x-dev" + }, + "phpstan": { + "includes": [ + "extension.neon" + ] } }, "autoload": { @@ -361,7 +369,7 @@ ], "support": { "issues": "https://github.com/composer/pcre/issues", - "source": "https://github.com/composer/pcre/tree/3.1.3" + "source": "https://github.com/composer/pcre/tree/3.3.1" }, "funding": [ { @@ -377,7 +385,7 @@ "type": "tidelift" } ], - "time": "2024-03-19T10:26:25+00:00" + "time": "2024-08-27T18:44:43+00:00" }, { "name": "composer/semver", @@ -385,20 +393,20 @@ "source": { "type": "git", "url": "https://github.com/composer/semver.git", - "reference": "1d09200268e7d1052ded8e5da9c73c96a63d18f5" + "reference": "4313d26ada5e0c4edfbd1dc481a92ff7bff91f12" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/semver/zipball/1d09200268e7d1052ded8e5da9c73c96a63d18f5", - "reference": "1d09200268e7d1052ded8e5da9c73c96a63d18f5", + "url": "https://api.github.com/repos/composer/semver/zipball/4313d26ada5e0c4edfbd1dc481a92ff7bff91f12", + "reference": "4313d26ada5e0c4edfbd1dc481a92ff7bff91f12", "shasum": "" }, "require": { "php": "^5.3.2 || ^7.0 || ^8.0" }, "require-dev": { - "phpstan/phpstan": "^1.4", - "symfony/phpunit-bridge": "^4.2 || ^5" + "phpstan/phpstan": "^1.11", + "symfony/phpunit-bridge": "^3 || ^7" }, "default-branch": true, "type": "library", @@ -443,7 +451,7 @@ "support": { "irc": "ircs://irc.libera.chat:6697/composer", "issues": "https://github.com/composer/semver/issues", - "source": "https://github.com/composer/semver/tree/main" + "source": "https://github.com/composer/semver/tree/3.4.3" }, "funding": [ { @@ -459,20 +467,20 @@ "type": "tidelift" } ], - "time": "2023-08-31T12:20:31+00:00" + "time": "2024-09-19T14:15:21+00:00" }, { "name": "composer/xdebug-handler", - "version": "3.0.4", + "version": "3.0.5", "source": { "type": "git", "url": "https://github.com/composer/xdebug-handler.git", - "reference": "4f988f8fdf580d53bdb2d1278fe93d1ed5462255" + "reference": "6c1925561632e83d60a44492e0b344cf48ab85ef" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/4f988f8fdf580d53bdb2d1278fe93d1ed5462255", - "reference": "4f988f8fdf580d53bdb2d1278fe93d1ed5462255", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/6c1925561632e83d60a44492e0b344cf48ab85ef", + "reference": "6c1925561632e83d60a44492e0b344cf48ab85ef", "shasum": "" }, "require": { @@ -509,7 +517,7 @@ "support": { "irc": "ircs://irc.libera.chat:6697/composer", "issues": "https://github.com/composer/xdebug-handler/issues", - "source": "https://github.com/composer/xdebug-handler/tree/3.0.4" + "source": "https://github.com/composer/xdebug-handler/tree/3.0.5" }, "funding": [ { @@ -525,7 +533,7 @@ "type": "tidelift" } ], - "time": "2024-03-26T18:29:49+00:00" + "time": "2024-05-06T16:37:16+00:00" }, { "name": "dealerdirect/phpcodesniffer-composer-installer", @@ -760,12 +768,12 @@ "source": { "type": "git", "url": "https://github.com/felixfbecker/php-language-server-protocol.git", - "reference": "ae4c490773bb0d21ca6f5e08a737506f44e175ea" + "reference": "a9e113dbc7d849e35b8776da39edaf4313b7b6c9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/felixfbecker/php-language-server-protocol/zipball/ae4c490773bb0d21ca6f5e08a737506f44e175ea", - "reference": "ae4c490773bb0d21ca6f5e08a737506f44e175ea", + "url": "https://api.github.com/repos/felixfbecker/php-language-server-protocol/zipball/a9e113dbc7d849e35b8776da39edaf4313b7b6c9", + "reference": "a9e113dbc7d849e35b8776da39edaf4313b7b6c9", "shasum": "" }, "require": { @@ -809,20 +817,20 @@ "issues": "https://github.com/felixfbecker/php-language-server-protocol/issues", "source": "https://github.com/felixfbecker/php-language-server-protocol/tree/master" }, - "time": "2022-06-19T17:15:06+00:00" + "time": "2024-04-30T00:40:11+00:00" }, { "name": "fidry/cpu-core-counter", - "version": "1.1.0", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/theofidry/cpu-core-counter.git", - "reference": "f92996c4d5c1a696a6a970e20f7c4216200fcc42" + "reference": "8520451a140d3f46ac33042715115e290cf5785f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theofidry/cpu-core-counter/zipball/f92996c4d5c1a696a6a970e20f7c4216200fcc42", - "reference": "f92996c4d5c1a696a6a970e20f7c4216200fcc42", + "url": "https://api.github.com/repos/theofidry/cpu-core-counter/zipball/8520451a140d3f46ac33042715115e290cf5785f", + "reference": "8520451a140d3f46ac33042715115e290cf5785f", "shasum": "" }, "require": { @@ -862,7 +870,7 @@ ], "support": { "issues": "https://github.com/theofidry/cpu-core-counter/issues", - "source": "https://github.com/theofidry/cpu-core-counter/tree/1.1.0" + "source": "https://github.com/theofidry/cpu-core-counter/tree/1.2.0" }, "funding": [ { @@ -870,7 +878,7 @@ "type": "github" } ], - "time": "2024-02-07T09:43:46+00:00" + "time": "2024-08-06T10:04:20+00:00" }, { "name": "gmazzap/andrew", @@ -933,12 +941,12 @@ "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "2f5294676c802a62b0549f6bc8983f14294ce369" + "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/2f5294676c802a62b0549f6bc8983f14294ce369", - "reference": "2f5294676c802a62b0549f6bc8983f14294ce369", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", + "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", "shasum": "" }, "require": { @@ -978,7 +986,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.x" + "source": "https://github.com/myclabs/DeepCopy/tree/1.12.0" }, "funding": [ { @@ -986,20 +994,20 @@ "type": "tidelift" } ], - "time": "2024-02-10T11:10:03+00:00" + "time": "2024-06-12T14:39:25+00:00" }, { "name": "netresearch/jsonmapper", - "version": "v4.4.1", + "version": "v4.5.0", "source": { "type": "git", "url": "https://github.com/cweiske/jsonmapper.git", - "reference": "132c75c7dd83e45353ebb9c6c9f591952995bbf0" + "reference": "8e76efb98ee8b6afc54687045e1b8dba55ac76e5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/cweiske/jsonmapper/zipball/132c75c7dd83e45353ebb9c6c9f591952995bbf0", - "reference": "132c75c7dd83e45353ebb9c6c9f591952995bbf0", + "url": "https://api.github.com/repos/cweiske/jsonmapper/zipball/8e76efb98ee8b6afc54687045e1b8dba55ac76e5", + "reference": "8e76efb98ee8b6afc54687045e1b8dba55ac76e5", "shasum": "" }, "require": { @@ -1035,9 +1043,9 @@ "support": { "email": "cweiske@cweiske.de", "issues": "https://github.com/cweiske/jsonmapper/issues", - "source": "https://github.com/cweiske/jsonmapper/tree/v4.4.1" + "source": "https://github.com/cweiske/jsonmapper/tree/v4.5.0" }, - "time": "2024-01-31T06:18:54+00:00" + "time": "2024-09-08T10:13:13+00:00" }, { "name": "nikic/php-parser", @@ -1045,12 +1053,12 @@ "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "4d36e9c16f4820c2ed9360bc818982f3c02a08f5" + "reference": "6de6ede1cb2fdff2837c5c92bc13263b5cb42d9e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/4d36e9c16f4820c2ed9360bc818982f3c02a08f5", - "reference": "4d36e9c16f4820c2ed9360bc818982f3c02a08f5", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/6de6ede1cb2fdff2837c5c92bc13263b5cb42d9e", + "reference": "6de6ede1cb2fdff2837c5c92bc13263b5cb42d9e", "shasum": "" }, "require": { @@ -1059,7 +1067,7 @@ }, "require-dev": { "ircmaxell/php-yacc": "^0.0.7", - "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" }, "bin": [ "bin/php-parse" @@ -1093,7 +1101,7 @@ "issues": "https://github.com/nikic/PHP-Parser/issues", "source": "https://github.com/nikic/PHP-Parser/tree/4.x" }, - "time": "2024-03-17T09:03:35+00:00" + "time": "2024-09-21T13:58:16+00:00" }, { "name": "phar-io/manifest", @@ -1438,31 +1446,31 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "3352293d9e91513d5508c415835014881b420218" + "reference": "85402a822d1ecf1db1096959413d35e1c37cf1a5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/3352293d9e91513d5508c415835014881b420218", - "reference": "3352293d9e91513d5508c415835014881b420218", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/85402a822d1ecf1db1096959413d35e1c37cf1a5", + "reference": "85402a822d1ecf1db1096959413d35e1c37cf1a5", "shasum": "" }, "require": { "ext-dom": "*", "ext-libxml": "*", "ext-xmlwriter": "*", - "nikic/php-parser": "^4.18 || ^5.0", + "nikic/php-parser": "^4.19.1 || ^5.1.0", "php": ">=7.3", - "phpunit/php-file-iterator": "^3.0.3", - "phpunit/php-text-template": "^2.0.2", - "sebastian/code-unit-reverse-lookup": "^2.0.2", - "sebastian/complexity": "^2.0", - "sebastian/environment": "^5.1.2", - "sebastian/lines-of-code": "^1.0.3", - "sebastian/version": "^3.0.1", - "theseer/tokenizer": "^1.2.0" + "phpunit/php-file-iterator": "^3.0.6", + "phpunit/php-text-template": "^2.0.4", + "sebastian/code-unit-reverse-lookup": "^2.0.3", + "sebastian/complexity": "^2.0.3", + "sebastian/environment": "^5.1.5", + "sebastian/lines-of-code": "^1.0.4", + "sebastian/version": "^3.0.2", + "theseer/tokenizer": "^1.2.3" }, "require-dev": { - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^9.6" }, "suggest": { "ext-pcov": "PHP extension that provides line coverage", @@ -1471,7 +1479,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "9.2-dev" + "dev-main": "9.2.x-dev" } }, "autoload": { @@ -1500,7 +1508,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/9.2" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.32" }, "funding": [ { @@ -1508,7 +1516,7 @@ "type": "github" } ], - "time": "2024-03-22T05:16:32+00:00" + "time": "2024-08-22T04:23:01+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1757,41 +1765,41 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "33a0610878994fc134c74c25d5276d606d49079b" + "reference": "de6abf3b6f8dd955fac3caad3af7a9504e8c2ffa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/33a0610878994fc134c74c25d5276d606d49079b", - "reference": "33a0610878994fc134c74c25d5276d606d49079b", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/de6abf3b6f8dd955fac3caad3af7a9504e8c2ffa", + "reference": "de6abf3b6f8dd955fac3caad3af7a9504e8c2ffa", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.3.1 || ^2", + "doctrine/instantiator": "^1.5.0 || ^2", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", "ext-mbstring": "*", "ext-xml": "*", "ext-xmlwriter": "*", - "myclabs/deep-copy": "^1.10.1", - "phar-io/manifest": "^2.0.3", - "phar-io/version": "^3.0.2", + "myclabs/deep-copy": "^1.12.0", + "phar-io/manifest": "^2.0.4", + "phar-io/version": "^3.2.1", "php": ">=7.3", - "phpunit/php-code-coverage": "^9.2.28", - "phpunit/php-file-iterator": "^3.0.5", + "phpunit/php-code-coverage": "^9.2.32", + "phpunit/php-file-iterator": "^3.0.6", "phpunit/php-invoker": "^3.1.1", - "phpunit/php-text-template": "^2.0.3", - "phpunit/php-timer": "^5.0.2", - "sebastian/cli-parser": "^1.0.1", - "sebastian/code-unit": "^1.0.6", + "phpunit/php-text-template": "^2.0.4", + "phpunit/php-timer": "^5.0.3", + "sebastian/cli-parser": "^1.0.2", + "sebastian/code-unit": "^1.0.8", "sebastian/comparator": "^4.0.8", - "sebastian/diff": "^4.0.3", - "sebastian/environment": "^5.1.3", - "sebastian/exporter": "^4.0.5", - "sebastian/global-state": "^5.0.1", - "sebastian/object-enumerator": "^4.0.3", - "sebastian/resource-operations": "^3.0.3", - "sebastian/type": "^3.2", + "sebastian/diff": "^4.0.6", + "sebastian/environment": "^5.1.5", + "sebastian/exporter": "^4.0.6", + "sebastian/global-state": "^5.0.7", + "sebastian/object-enumerator": "^4.0.4", + "sebastian/resource-operations": "^3.0.4", + "sebastian/type": "^3.2.1", "sebastian/version": "^3.0.2" }, "suggest": { @@ -1852,7 +1860,7 @@ "type": "tidelift" } ], - "time": "2024-04-20T06:05:08+00:00" + "time": "2024-09-19T10:50:18+00:00" }, { "name": "psr/cache", @@ -3099,12 +3107,12 @@ "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "9a0c2546ea2fa7aac19881da7b655cc5f022bc10" + "reference": "92c8ef54357ea09d93f8efa043d7c9c0a71ae094" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/9a0c2546ea2fa7aac19881da7b655cc5f022bc10", - "reference": "9a0c2546ea2fa7aac19881da7b655cc5f022bc10", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/92c8ef54357ea09d93f8efa043d7c9c0a71ae094", + "reference": "92c8ef54357ea09d93f8efa043d7c9c0a71ae094", "shasum": "" }, "require": { @@ -3172,7 +3180,7 @@ "type": "open_collective" } ], - "time": "2024-04-24T15:14:01+00:00" + "time": "2024-09-18T16:46:38+00:00" }, { "name": "symfony/console", @@ -3180,12 +3188,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "f3e591c48688a0cfa1a3296205926c05e84b22b1" + "reference": "5b5a0aa66e3296e303e22490f90f521551835a83" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/f3e591c48688a0cfa1a3296205926c05e84b22b1", - "reference": "f3e591c48688a0cfa1a3296205926c05e84b22b1", + "url": "https://api.github.com/repos/symfony/console/zipball/5b5a0aa66e3296e303e22490f90f521551835a83", + "reference": "5b5a0aa66e3296e303e22490f90f521551835a83", "shasum": "" }, "require": { @@ -3271,7 +3279,7 @@ "type": "tidelift" } ], - "time": "2024-04-18T08:26:06+00:00" + "time": "2024-09-20T07:56:40+00:00" }, { "name": "symfony/deprecation-contracts", @@ -3279,12 +3287,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "80d075412b557d41002320b96a096ca65aa2c98d" + "reference": "d36279a5a4bc7f3ca2c412839f10d7c0aa2c1a02" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/80d075412b557d41002320b96a096ca65aa2c98d", - "reference": "80d075412b557d41002320b96a096ca65aa2c98d", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/d36279a5a4bc7f3ca2c412839f10d7c0aa2c1a02", + "reference": "d36279a5a4bc7f3ca2c412839f10d7c0aa2c1a02", "shasum": "" }, "require": { @@ -3338,7 +3346,7 @@ "type": "tidelift" } ], - "time": "2023-01-24T14:02:46+00:00" + "time": "2024-04-18T08:26:06+00:00" }, { "name": "symfony/filesystem", @@ -3346,19 +3354,21 @@ "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "e6edd875d5d39b03de51f3c3951148cfa79a4d12" + "reference": "76c3818964e9d32be3862c9318ae3ba9aa280ddc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/e6edd875d5d39b03de51f3c3951148cfa79a4d12", - "reference": "e6edd875d5d39b03de51f3c3951148cfa79a4d12", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/76c3818964e9d32be3862c9318ae3ba9aa280ddc", + "reference": "76c3818964e9d32be3862c9318ae3ba9aa280ddc", "shasum": "" }, "require": { "php": ">=7.2.5", "symfony/polyfill-ctype": "~1.8", "symfony/polyfill-mbstring": "~1.8", - "symfony/polyfill-php80": "^1.16", + "symfony/polyfill-php80": "^1.16" + }, + "require-dev": { "symfony/process": "^5.4|^6.4" }, "type": "library", @@ -3403,7 +3413,7 @@ "type": "tidelift" } ], - "time": "2024-04-18T08:26:06+00:00" + "time": "2024-09-16T14:52:48+00:00" }, { "name": "symfony/polyfill-ctype", @@ -3411,16 +3421,16 @@ "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "c9e59dec962d38cf2e0e4c61c4a1a1312f4dd7fe" + "reference": "a3cc8b044a6ea513310cbd48ef7333b384945638" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/c9e59dec962d38cf2e0e4c61c4a1a1312f4dd7fe", - "reference": "c9e59dec962d38cf2e0e4c61c4a1a1312f4dd7fe", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/a3cc8b044a6ea513310cbd48ef7333b384945638", + "reference": "a3cc8b044a6ea513310cbd48ef7333b384945638", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "provide": { "ext-ctype": "*" @@ -3467,7 +3477,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/1.x" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.31.0" }, "funding": [ { @@ -3483,7 +3493,7 @@ "type": "tidelift" } ], - "time": "2024-04-19T06:31:17+00:00" + "time": "2024-09-09T11:45:10+00:00" }, { "name": "symfony/polyfill-intl-grapheme", @@ -3491,16 +3501,16 @@ "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-grapheme.git", - "reference": "0a1df740cbb01859ce1bac85b0ad58ffe02f69b6" + "reference": "b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/0a1df740cbb01859ce1bac85b0ad58ffe02f69b6", - "reference": "0a1df740cbb01859ce1bac85b0ad58ffe02f69b6", + "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe", + "reference": "b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "suggest": { "ext-intl": "For best performance" @@ -3546,7 +3556,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/1.x" + "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.31.0" }, "funding": [ { @@ -3562,7 +3572,7 @@ "type": "tidelift" } ], - "time": "2024-04-19T06:31:17+00:00" + "time": "2024-09-09T11:45:10+00:00" }, { "name": "symfony/polyfill-intl-normalizer", @@ -3570,16 +3580,16 @@ "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", - "reference": "2a090dc3db090fcb35cc7329d18a07f281f15d79" + "reference": "3833d7255cc303546435cb650316bff708a1c75c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/2a090dc3db090fcb35cc7329d18a07f281f15d79", - "reference": "2a090dc3db090fcb35cc7329d18a07f281f15d79", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/3833d7255cc303546435cb650316bff708a1c75c", + "reference": "3833d7255cc303546435cb650316bff708a1c75c", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "suggest": { "ext-intl": "For best performance" @@ -3628,7 +3638,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/1.x" + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.31.0" }, "funding": [ { @@ -3644,7 +3654,7 @@ "type": "tidelift" } ], - "time": "2024-04-19T06:31:17+00:00" + "time": "2024-09-09T11:45:10+00:00" }, { "name": "symfony/polyfill-mbstring", @@ -3652,16 +3662,16 @@ "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "e642fbe7a7b73cdb05460555289a9057bfd6ead6" + "reference": "2369cb908b33d7b7518cce042615de430142497f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/e642fbe7a7b73cdb05460555289a9057bfd6ead6", - "reference": "e642fbe7a7b73cdb05460555289a9057bfd6ead6", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/2369cb908b33d7b7518cce042615de430142497f", + "reference": "2369cb908b33d7b7518cce042615de430142497f", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "provide": { "ext-mbstring": "*" @@ -3725,7 +3735,7 @@ "type": "tidelift" } ], - "time": "2024-04-19T06:31:17+00:00" + "time": "2024-09-10T14:38:51+00:00" }, { "name": "symfony/polyfill-php73", @@ -3733,16 +3743,16 @@ "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php73.git", - "reference": "bca7fd9c46ef734d27d59dae1b71ce4f4ff70b03" + "reference": "0f68c03565dcaaf25a890667542e8bd75fe7e5bb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/bca7fd9c46ef734d27d59dae1b71ce4f4ff70b03", - "reference": "bca7fd9c46ef734d27d59dae1b71ce4f4ff70b03", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/0f68c03565dcaaf25a890667542e8bd75fe7e5bb", + "reference": "0f68c03565dcaaf25a890667542e8bd75fe7e5bb", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "default-branch": true, "type": "library", @@ -3786,7 +3796,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php73/tree/1.x" + "source": "https://github.com/symfony/polyfill-php73/tree/v1.31.0" }, "funding": [ { @@ -3802,7 +3812,7 @@ "type": "tidelift" } ], - "time": "2024-04-19T06:31:17+00:00" + "time": "2024-09-09T11:45:10+00:00" }, { "name": "symfony/polyfill-php80", @@ -3810,16 +3820,16 @@ "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "7d191eb4022901cd3d91a816ec5464ca3a08a8aa" + "reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/7d191eb4022901cd3d91a816ec5464ca3a08a8aa", - "reference": "7d191eb4022901cd3d91a816ec5464ca3a08a8aa", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/60328e362d4c2c802a54fcbf04f9d3fb892b4cf8", + "reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "default-branch": true, "type": "library", @@ -3867,7 +3877,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/1.x" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.31.0" }, "funding": [ { @@ -3883,69 +3893,7 @@ "type": "tidelift" } ], - "time": "2024-04-19T06:31:17+00:00" - }, - { - "name": "symfony/process", - "version": "5.4.x-dev", - "source": { - "type": "git", - "url": "https://github.com/symfony/process.git", - "reference": "85a554acd7c28522241faf2e97b9541247a0d3d5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/85a554acd7c28522241faf2e97b9541247a0d3d5", - "reference": "85a554acd7c28522241faf2e97b9541247a0d3d5", - "shasum": "" - }, - "require": { - "php": ">=7.2.5", - "symfony/polyfill-php80": "^1.16" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\Process\\": "" - }, - "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": "Executes commands in sub-processes", - "homepage": "https://symfony.com", - "support": { - "source": "https://github.com/symfony/process/tree/5.4" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2024-04-18T08:26:06+00:00" + "time": "2024-09-09T11:45:10+00:00" }, { "name": "symfony/service-contracts", @@ -3953,12 +3901,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "a2329596ddc8fd568900e3fc76cba42489ecc7f3" + "reference": "351fb560172c6972ffa169f4ffaea6d58a9de33b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/a2329596ddc8fd568900e3fc76cba42489ecc7f3", - "reference": "a2329596ddc8fd568900e3fc76cba42489ecc7f3", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/351fb560172c6972ffa169f4ffaea6d58a9de33b", + "reference": "351fb560172c6972ffa169f4ffaea6d58a9de33b", "shasum": "" }, "require": { @@ -4028,7 +3976,7 @@ "type": "tidelift" } ], - "time": "2023-04-21T15:04:16+00:00" + "time": "2024-04-18T08:26:06+00:00" }, { "name": "symfony/string", @@ -4036,12 +3984,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "495e71bae5862308051b9e63cc3e34078eed83ef" + "reference": "832caa16b6d9aac6bf11747315225f5aba384c24" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/495e71bae5862308051b9e63cc3e34078eed83ef", - "reference": "495e71bae5862308051b9e63cc3e34078eed83ef", + "url": "https://api.github.com/repos/symfony/string/zipball/832caa16b6d9aac6bf11747315225f5aba384c24", + "reference": "832caa16b6d9aac6bf11747315225f5aba384c24", "shasum": "" }, "require": { @@ -4114,7 +4062,7 @@ "type": "tidelift" } ], - "time": "2024-04-18T08:26:06+00:00" + "time": "2024-09-20T07:56:40+00:00" }, { "name": "theseer/tokenizer", @@ -4172,12 +4120,12 @@ "source": { "type": "git", "url": "https://github.com/vimeo/psalm.git", - "reference": "7d6c88e88a55cf04af4d6932cfb906d15ac2fe23" + "reference": "d747f6500b38ac4f7dfc5edbcae6e4b637d7add0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vimeo/psalm/zipball/7d6c88e88a55cf04af4d6932cfb906d15ac2fe23", - "reference": "7d6c88e88a55cf04af4d6932cfb906d15ac2fe23", + "url": "https://api.github.com/repos/vimeo/psalm/zipball/d747f6500b38ac4f7dfc5edbcae6e4b637d7add0", + "reference": "d747f6500b38ac4f7dfc5edbcae6e4b637d7add0", "shasum": "" }, "require": { @@ -4198,7 +4146,7 @@ "felixfbecker/language-server-protocol": "^1.5.2", "fidry/cpu-core-counter": "^0.4.1 || ^0.5.1 || ^1.0.0", "netresearch/jsonmapper": "^1.0 || ^2.0 || ^3.0 || ^4.0", - "nikic/php-parser": "^4.16", + "nikic/php-parser": "^4.17", "php": "^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0", "sebastian/diff": "^4.0 || ^5.0 || ^6.0", "spatie/array-to-xml": "^2.17.0 || ^3.0", @@ -4275,7 +4223,7 @@ "issues": "https://github.com/vimeo/psalm/issues", "source": "https://github.com/vimeo/psalm" }, - "time": "2024-04-06T18:17:07+00:00" + "time": "2024-09-08T18:53:08+00:00" }, { "name": "webmozart/assert", From f1ad7b22863489e0e3896d0f8ab62c5c6dd17877 Mon Sep 17 00:00:00 2001 From: Anton Ukhanev Date: Sat, 21 Sep 2024 19:29:53 +0200 Subject: [PATCH 3/6] PHPCS will now target PHP 7.4 - the minimal required verson --- phpcs.xml.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 4c805eb..70cc8d1 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -7,6 +7,7 @@ + From 135b08cbe6033d1b0176e9f4dbfa3bf864e7d856 Mon Sep 17 00:00:00 2001 From: Anton Ukhanev Date: Sat, 21 Sep 2024 19:30:28 +0200 Subject: [PATCH 4/6] PHPCS will now target PHP 7.4 - the minimal required version --- src/DelegatingContainer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DelegatingContainer.php b/src/DelegatingContainer.php index 5de9c52..2690f1d 100644 --- a/src/DelegatingContainer.php +++ b/src/DelegatingContainer.php @@ -54,7 +54,7 @@ public function get($id) $stack[$id] = true; try { - return $this->_createService($id); + return $this->createService($id); } finally { unset($stack[$id]); } @@ -83,7 +83,7 @@ public function has($id) * @throws NotFoundException If no factory corresponds to the given $key. * @throws ContainerException If an error occurred while creating the service. */ - protected function _createService(string $key) + protected function createService(string $key) { $provider = $this->provider; $services = $provider->getFactories(); From 414e3d13a429e6425a0bc3eac85b356134ba05a3 Mon Sep 17 00:00:00 2001 From: Anton Ukhanev Date: Sat, 21 Sep 2024 19:40:41 +0200 Subject: [PATCH 5/6] Update config --- .idea/php-test-framework.xml | 4 ++-- .idea/php.xml | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.idea/php-test-framework.xml b/.idea/php-test-framework.xml index a44b231..f4518dc 100644 --- a/.idea/php-test-framework.xml +++ b/.idea/php-test-framework.xml @@ -5,10 +5,10 @@ - + - \ No newline at end of file + diff --git a/.idea/php.xml b/.idea/php.xml index 26aa214..d0fd0fe 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -92,7 +92,6 @@ - @@ -227,8 +226,8 @@ - + From 92c5bfd023bf80c99721c2c62733c9f15a939eb2 Mon Sep 17 00:00:00 2001 From: Anton Ukhanev Date: Sat, 21 Sep 2024 19:58:57 +0200 Subject: [PATCH 6/6] Resolution stack now instance-specific This prevents other unrelated delegating containers from manipulating the stack. --- src/DelegatingContainer.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/DelegatingContainer.php b/src/DelegatingContainer.php index 2690f1d..fa5da2c 100644 --- a/src/DelegatingContainer.php +++ b/src/DelegatingContainer.php @@ -26,6 +26,12 @@ class DelegatingContainer implements ContainerInterface */ protected $parent; + /** + * Keys represent the list of service names accessed recursively, in order of access + * @var array + */ + protected $stack = []; + /** */ public function __construct(ServiceProviderInterface $provider, PsrContainerInterface $parent = null) @@ -39,10 +45,8 @@ public function __construct(ServiceProviderInterface $provider, PsrContainerInte */ public function get($id) { - static $stack = []; - - if (array_key_exists($id, $stack)) { - $trace = implode(' -> ', array_keys($stack)) . ' -> ' . $id; + if (array_key_exists($id, $this->stack)) { + $trace = implode(' -> ', array_keys($this->stack)) . ' -> ' . $id; throw new ContainerException( $this->__("Circular dependency detected:\n%s", [$trace]), @@ -51,12 +55,12 @@ public function get($id) ); } - $stack[$id] = true; + $this->stack[$id] = true; try { return $this->createService($id); } finally { - unset($stack[$id]); + unset($this->stack[$id]); } }