Skip to content

Refactor view() Helper and Standardize QtView Class Name #459

Description

@armanist

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.php to src/View/View.php and update the class declaration.
  • Search the entire codebase and replace all instances, imports, and docblocks referencing QtView or Quantum\View\QtView with the new View class. 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.php to ViewTest.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 the View instance instead of a string.
  • Rename the getView() method inside the View class to getContent() to avoid tautological calls.
  • Update layout files to use <?= view()->getContent() ?> (or alternatively, implement __toString() on the View class 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

  1. added this to the 3.0.0 milestone on Apr 21, 2026
  2. self-assigned this
    on Apr 21, 2026
  3. added 2 commits that reference this issue on Apr 21, 2026
  4. added a commit that references this issue on Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions