Add a class-based component() helper for reusable view components
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 42/100
Direzione di ricerca
Inizia leggendo src/View/Helpers/view.php e src/View/View.php per capire come funzionano partial() e il rendering delle view, quindi esamina i file HtmlAdapter.php e TwigAdapter.php. Definisci il contratto minimo per helper, costruttore e rendering, il comportamento del rendering annidato e il rilevamento dei cicli nello stack attivo. Il lavoro è completato quando i criteri di accettazione sono coperti da test per rendering, parametri, annidamento e rilevamento della ricorsione, mentre partial() rimane disponibile.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
Add a first version of view components to Quantum through a class-based helper:
component('ComponentName', array $params = [])
This should provide a more structured alternative to partial() for reusable view fragments with their own class logic and rendering behavior.
Why
Quantum already has:
partial()
which is useful for simple reusable view fragments, but it is only a direct partial render/include mechanism.
A component system should support a more sophisticated approach where a reusable view fragment is backed by a class that can:
- accept params
- prepare internal state in
__construct() - render its own partial through
render()
This is the first step toward a broader component model inspired by frameworks such as Vue, React, Angular, Laravel Blade components, and similar PHP approaches, without introducing tag parsing yet.
Goal
Introduce a minimal component runtime for Quantum that allows views to render reusable class-backed components through a helper call.
Proposed Direction
Add a helper such as:
component('Alert', [
'type' => 'error',
'message' => 'Something went wrong',
]);
The helper should:
- resolve the component class
- instantiate it with the provided params
- call its
render()method - return the rendered string output
First version scope
This first version should stay intentionally minimal.
It should support:
- a class-based component model
- constructor-based param handling
- string rendering through
render()
It should not yet include:
- XHTML parsing
<x-...>tag syntax- slot support
- anonymous/file-only components
- advanced component templating syntax
Those can come later.
Component contract
The first version should keep the component API small.
A likely minimal shape is:
__construct(array $params = [])render(): string
This allows the component class to normalize params and render its own partial or output.
Rendering behavior
A component should typically render through the existing view/partial rendering system, rather than bypassing it.
That keeps the feature aligned with Quantum’s current view architecture and allows the helper to work with the existing rendering model.
Nesting behavior
Components should be allowed to render other components.
That means:
- component nesting is supported
- normal repeated component usage is allowed
However, circular component rendering must be detected and blocked.
Examples that must fail:
- component
ArendersA - component
ArendersB, andBrendersA
This first version should include circular-render detection through an active render stack.
It does not need a configurable max-depth setting in the first version.
Why this version first
The long-term direction may include an XHTML renderer that parses tags like:
<x-alert><x-post-card>
But that should be treated as a later version.
The first version should establish the component class contract and helper-based runtime first, so future XHTML parsing can build on the same component model instead of introducing a second one.
Acceptance Criteria
- a global/helper-level
component()API exists - the helper resolves and instantiates component classes
- params can be passed into component constructors as an array
- component classes return rendered output through
render(): string - components can render other components
- circular component rendering is detected and blocked
partial()remains available for simpler use cases- tests cover basic rendering, param passing, nesting, and circular recursion detection
Notes
Relevant code:
src/View/Helpers/view.phpsrc/View/View.phpsrc/Renderer/Adapters/HtmlAdapter.phpsrc/Renderer/Adapters/TwigAdapter.php
This ticket is the minimal component-runtime foundation and should come before any XHTML or <x-...> parsing work.
- Lingua principale
- PHP
- Stelle
- 36
- Fork
- 22
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di quantum-php/framework
-
routing testing
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
quantum-php/framework#547 ·
-
view
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
quantum-php/framework#542 ·
-
enhancement http
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
quantum-php/framework#565 · 1 commento ·
-
Add explicit @version special route token support for API major versioning within a single moduleApertarouting
Difficoltà 5/5 Più di una settimana Idoneità per principianti 45/100
quantum-php/framework#550 ·
-
lang routing
Difficoltà 5/5 Più di una settimana Idoneità per principianti 45/100
quantum-php/framework#549 ·
Tutte le issue di quantum-php/framework
Issue simili
-
Update the one-click "GTM4WP" Delay JS exclusion so that it also works with a custom data layer nameAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
[Feature]: Remove Kanboard Discourse forum link from README.md and CONTRIBUTING.md, or moderate itAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
bug Localization
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
solana-foundation/pay-kit#341 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
cline/cline#14560 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno