PHP-CSS-Parser icon indicating copy to clipboard operation
PHP-CSS-Parser copied to clipboard

Dependency loop `OutputFormat`/`OutputFormatter`

Open oliverklee opened this issue 1 year ago • 3 comments

Both have references to an instance of each other. Dependencies should go only one way, though, and loops are a really bad thing.

oliverklee avatar Feb 10 '25 08:02 oliverklee

We're talking about class dependencies, rather than object dependencies. A linked-list in C++ (before stdlib) would have loops in the objects, but they would all be of the same class.

As I understand, OutputFormat is where the settings are, and OutputFormatter is the worker. So OutputFormatter should have a reference to OutputFormat, but there shouldn't be a need for one the other way.

JakeQZ avatar Feb 11 '25 01:02 JakeQZ

We would need to change the various render methods to take an OutputFormatter argument instead of an OutputFormat. To begin with, they would need to be able to accept either, with the latter deprecated. I'm assuming there's already an easy means for users to create an OutputFormatter from an OutputFormat. If we tread this path, it means we can't mark OutputFormatter as @internal. Thoughts welcome...

JakeQZ avatar Feb 11 '25 02:02 JakeQZ

I've proposed a path forward in #907.

oliverklee avatar Feb 11 '25 11:02 oliverklee