Skip to content

<f-my-component attribute="value" /> support#710

Draft
fadrian06 wants to merge 21 commits into
masterfrom
580-view-class-steroids
Draft

<f-my-component attribute="value" /> support#710
fadrian06 wants to merge 21 commits into
masterfrom
580-view-class-steroids

Conversation

@fadrian06

Copy link
Copy Markdown
Contributor

This pull request introduces significant enhancements to the View template system, most notably adding support for component-based templates (including class and functional components with props, styles, and scripts), refactoring and modernizing the View class, and improving the test suite for better coverage and maintainability.

Component System and Template Rendering Enhancements:

  • Introduced a new Component abstract class in flight/template/Component.php, enabling templates to be defined as PHP classes with html(), css(), and js() methods for encapsulated markup, styles, and scripts.
  • Updated the View class to support rendering components: detects when a template returns a Component instance or a callable, and renders their output accordingly. Also adds support for parsing and rendering custom component tags (e.g., <f-my-component />) with props, and recursively renders subcomponents.

Refactoring and Modernization of the View Class:

  • Refactored the View class for clarity and modern PHP practices: improved docblocks, replaced deprecated or verbose code with concise alternatives, used strict types, and streamlined variable handling. [1] [2] [3] [4] [5]
  • Changed how variables are set and cleared, improved path normalization, and made error handling more consistent with modern PHP. [1] [2] [3]

Testing Improvements:

  • Updated and expanded the test suite in tests/ViewTest.php to use self::assert* methods for consistency, added new tests for component rendering (including class, functional, and nested components, as well as components with props, styles, and scripts), and improved test data providers. [1] [2]
  • Refactored existing tests for clarity and maintainability, including utility methods for removing line endings and indentation to make output comparisons robust. [1] [2] [3]

Other Improvements:

  • Updated copyright and license annotations in View.php for accuracy and modern links.
  • Minor config improvements: broadened .editorconfig rule for test views and updated the author's homepage in composer.json. [1] [2]

These changes collectively modernize the template system, introduce a flexible component architecture, and ensure robust, maintainable testing.

References:
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

@fadrian06 fadrian06 self-assigned this Jun 25, 2026
@fadrian06 fadrian06 linked an issue Jun 25, 2026 that may be closed by this pull request
@fadrian06 fadrian06 added the refactor Code optimization, improved readability or simplify framework structure label Jun 25, 2026
@n0nag0n

n0nag0n commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

So I think this is ok minus the one change, but you probably should add to the Flight docs for the docs related to this change. The other thing that I don't know right now is if this will break for people using the current view class. There might be some future issues related to this you should be prepared to fix if they get surfaced.

@fadrian06

fadrian06 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

don't worry, I am testing this is personal apps and it works as expected, both old and new syntax...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Feature refactor Code optimization, improved readability or simplify framework structure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

View class steroids 🙌🏽

2 participants