From bcf19da796d84e42cc0b6aef4fbf5ba461b5ddd8 Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Thu, 29 Oct 2026 11:03:56 +0300 Subject: [PATCH] =?UTF-8?q?Container:=20set()=20=D0=B4=D0=BE=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B2=D0=BE=D0=B3=D0=BE=20=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D1=89=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2=D0=B0=D0=B6=D0=BD=D0=B5?= =?UTF-8?q?=D0=B5=20=D1=80=D0=B5=D0=B5=D1=81=D1=82=D1=80=D0=B0;=20=D1=8F?= =?UTF-8?q?=D0=B4=D1=80=D0=BE=201.5.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/CHANGELOG.md | 3 +++ framework/.checksums.json | 2 +- framework/Support/Container.php | 7 +++++++ framework/VERSION | 2 +- tests/ContainerTest.php | 12 ++++++++++++ 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 36bd625..a9a85e1 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -6,6 +6,9 @@ не бесплатна, нужно что-то доделать руками на стороне проекта. Подробности механизма — `docs/CORE_UPDATES.md`. +## 1.5.2 +- Container: объект из set() до первого обращения не затирается привязками config/services.php + ## 1.5.1 - Model\Query::pluck() отдаёт значения, а не падает на моделях: Builder::rows(), pluck() строится на нём diff --git a/framework/.checksums.json b/framework/.checksums.json index f3db36f..adc1406 100644 --- a/framework/.checksums.json +++ b/framework/.checksums.json @@ -161,7 +161,7 @@ "framework/Support/Audit.php": "8eb4cae91532dac0b1a4ecc5b217344fefa1a4850ea1bf555403dc4e5e357ce3", "framework/Support/ClientIp.php": "d530cba12c255c6f802e94de261caf9284d93f09f420f7d9026a1e39665adc4b", "framework/Support/Config.php": "d15aa129a903ad36a39629fcc6db4c2b7596de0d93ab75a73c4524925daab58b", - "framework/Support/Container.php": "a4626e3790045b0d236f03115afbce824bd242df1f1637e43af3227802647ca1", + "framework/Support/Container.php": "7df714fa60589775130816aebbeeaede537620683bcc8f283653ad291b4bb057", "framework/Support/CronExpression.php": "90041c2479c8247cfedcb273ef7747466106814bce5ad3a4fbc695f1a99648f6", "framework/Support/Csv.php": "f83e208eb702f3247a278846ce0e3e698d187e987036fc9c880bbe7bb139e026", "framework/Support/Diagnostics.php": "9ba20e5e27ceca8adfb137bcb12e8b18c4af4e2de2ea6e4785114b0aa78105cb", diff --git a/framework/Support/Container.php b/framework/Support/Container.php index 6836b11..53cd960 100644 --- a/framework/Support/Container.php +++ b/framework/Support/Container.php @@ -325,6 +325,13 @@ final class Container /** @var array{bind?: array, singleton?: array} $services */ $services = (array) require $file; + // Положенное через set() до первого обращения (тест подставил + // подделку) важнее реестра: bind() сбросил бы готовый объект, + // и в тест вместо подделки приехала бы настоящая реализация + foreach (['bind', 'singleton'] as $kind) { + $services[$kind] = array_diff_key((array) ($services[$kind] ?? []), $this->shared); + } + $this->register($services); } } diff --git a/framework/VERSION b/framework/VERSION index 26ca594..4cda8f1 100644 --- a/framework/VERSION +++ b/framework/VERSION @@ -1 +1 @@ -1.5.1 +1.5.2 diff --git a/tests/ContainerTest.php b/tests/ContainerTest.php index 6a16689..cc06c01 100644 --- a/tests/ContainerTest.php +++ b/tests/ContainerTest.php @@ -130,3 +130,15 @@ test('контейнер: реестр services.php разбирается', fun assertSame('локальное', $container->make(ContainerTestStorage::class)->name()); assertTrue($container->make(Logger::class) === $container->make(Logger::class)); }); + +test('контейнер: set() до первого обращения не затирается реестром services.php', function (): void { + $container = new Container(); + $fake = new ContainerTestLocal(); + + // В config/services.php NoteLimiter привязан к ConfigNoteLimiter; привязки + // читаются лениво — уже после этого set() + $container->set(App\Contracts\NoteLimiter::class, $fake); + + assertSame($fake, $container->make(App\Contracts\NoteLimiter::class)); + assertTrue($container->make(App\Services\ConfigNoteLimiter::class) instanceof App\Services\ConfigNoteLimiter, 'остальной реестр на месте'); +});