Repository navigation
Description
Refactor view() Helper to Service Locator and Rename QtView
Description
This issue outlines two important refactoring steps for the Quantum\View package to align with the framework's modernized naming conventions and utility patterns:
1. Rename QtView to View
Currently, the main class handling views is named QtView (src/View/QtView.php). The Qt prefix is an outdated convention across the codebase (e.g., we have Config, App, Debugger, not QtConfig or QtApp).
Tasks:
- Rename
src/View/QtView.phptosrc/View/View.phpand update the class declaration. - Search the entire codebase and replace all instances, imports, and docblocks referencing
QtVieworQuantum\View\QtViewwith the newViewclass. This includes (but is not limited to):ViewFactory::get()return types and mixin annotations.- Generative stubs like
src/Module/Templates/DemoWeb/src/Controllers/BaseController.php.tpl.
- Rename the test class
tests/Unit/View/QtViewTest.phptoViewTest.php. - Thoroughly audit and update all unit test files (
ViewTest.php,ViewFactoryTest.php,ViewHelperTest.php) to ensure they test against the new class name and helper behaviors.
2. Standardize the view() helper method
Currently, the view() helper located in src/View/Helpers/view.php immediately calls ->getView() on the factory instance:
function view(): ?string
{
return ViewFactory::get()->getView();
}This violates the structural consistency established by other framework helpers like config(), session(), request(), which behave as service locators and return the core class instance.
By immediately dumping the view boundary string, the helper strips developers of the ability to fluently chain View methods dynamically such as view()->setLayout(), view()->setParam(), or view()->render(...).
Tasks:
- Modify
view()to return theViewinstance instead of a string. - Rename the
getView()method inside theViewclass togetContent()to avoid tautological calls. - Update layout files to use
<?= view()->getContent() ?>(or alternatively, implement__toString()on theViewclass so<?= view() ?>still works elegantly). - Update corresponding unit tests in
ViewHelperTest.
Proposed Change for view()
function view(): View
{
// Fetches the factory's resolved instance, keeping it acting as a true Service Locator
return ViewFactory::get();
}
Activity
[quantum-php#459] Avoid duplicate debugbar() lookup in WebAppTrait::l…
[#459] Refactor view() helper to service locator and rename QtView to…
Merge pull request #464 from armanist/issue/459-refactor-view-helper