Вход на сайт

Просмотр новости

Найдите то, что Вас интересует

Using a static flag to prevent setting twice

Дата публикации: 24-09-2026 10:32:00

No apologies needed. It is a personal project, but I am keen to get it right.
It initially started from a tutorial, but as you can see from the following file structures, mine on the right, I didn’t stick to the brief. It has been a fun exercise and I’ve learnt a lot in the process.
Anyway back to the task in hand.
It does feel like a lot of creating and passing viewers around unnecessarily. Could it not pass the class name or something?
I am doing a bit research into it. Last night I was reading up on the registry pattern, but I think that might be more use for making my Session class available to the views e.g.
<div> e($session->getMessage('message'))</div>
As mentioned Claude had discussed doing these setup bindings in the container.
Just having a quick peek at laravels container Container.php
I asked Claude to step back and look at the overall architecture. I felt the suggested solutions were just sticking plasters. I asked how do Symphony or Laravel handle this situation.
This is quite long text, but this was the feedback
Stepping back, I think there are two genuinely separate concerns that have been tangled into one, and that tangling is why every fix has felt like a patch rather than a solution.
…
Concern 2: every controller repeating Response $response, ViewerInterface $viewer in its own constructor.
This is the bigger smell, and it’s what’s actually driving the ErrorController-vs-Dispatcher ordering problem. Right now, any framework-wide thing a controller needs has to be re-declared, by hand, in every single controller’s constructor — and if you forget one (like HomeController did), you get an uninitialized-property crash. That’s not really a DI failure, it’s a missing piece of the DI container: a way to say “whenever anything that is a Controller gets built, regardless of who asked for it, also wire these framework services onto it.”
Tried-and-tested containers have exactly this hook. Laravel’s container has resolving()/afterResolving() — register a callback once, and it fires after every resolution of a given class/interface, no matter which code path triggered it (a normal controller dispatch, an error handler resolving ErrorController directly, a test, a console command). Symfony’s service definitions support a calls: list for the same purpose — setter injection applied uniformly by the container itself, not by whichever call site happens to remember to do it.
That’s the piece your Container (src/Framework/Container.php) doesn’t have yet. Right now the only place setter-style wiring can happen is Dispatcher::dispatch(), which is exactly why ErrorController — resolved by ErrorHandler, independent of Dispatcher — fell through the cracks. If Container::resolve() itself supported “after building an instance of X, run this callback on it,” you’d register one rule (e.g. “anything that’s a Controller gets setResponse/setViewer called on it”) in Services.php, and it would apply identically whether the controller came from Dispatcher, ErrorHandler, or anywhere else you resolve one from in the future. No more duplicating Response/ViewerInterface in every controller’s own constructor at all — those stay purely for each controller’s actual business dependencies (Listings, ListingsFormRequest, HttpErrorMessages).
That’s the structural fix I’d point you at: a small resolving(string $type, callable $callback) hook on Container, used once, rather than another round of patching individual controllers or Dispatcher. Worth having a go at designing that hook yourself — it’s a nice small piece of container design in its own right.
I’m looking at the laravel hooks options, which as far as I gather is an Observer pattern of sorts

Схожие новости

#Наименование новостиТональностьИнформативностьДата публикации
1splitstack/invariants024.2903-08-2026
2EIP Editing Office Hour (EIP + ERC ) Meeting #108, July 28, 2026018.3227-07-2026
3 Comment on resolve_pattern_blocks() by Rodrigo Vieira Eufrasio da Silva 010.6514-08-2026
4Rearchitecting for Drupal 8; a DrupalCon Session09.5815-02-2018
5Blog: gRPC-Rust Client API Evolution (pt. 1/2)011.5429-05-2026
6“Scrum didn’t work for us.”08.130-07-2026
7Trivial anti-crawler with Caddy08.4223-06-2026
8Вайбкодю, потихоньку0502-07-2026
9Incremental Delivery and the Need for Speed015.114-07-2026
10How should I handle daily puzzle resets across different timezones in PHP?010.1623-09-2026

Классификация: . Схожих патентов: 0. Схожих новостей: 10. Тональность: 0. Информативность: 14.14. Источник: www.sitepoint.com.