Page Logic - PhpGt/WebEngine GitHub Wiki
A page response is made up of a Page View, which can be seen as the HTML that makes up the presentation of the page, and optional Page Logic, which can be seen as the PHP that makes the page dynamic.
A Page Logic file acts as the point-of-entry for executing the business logic of a request. In terms of MVC architecture, Page Logic is the controller.
Adding logic to a view
A request must have a view to respond with, but the logic is completely optional. Some pages of web applications can be treated as static, so wouldn't require any PHP logic to complete the response, but when you need to manipulate the page, react to user input, and output data to the page, logic becomes necessary.
Like with Page Views, routing of Logic files is automatic and matches the URI.
File and class names
Application business logic can be autoloaded from Composer packages or the Class project directory, both using PSR-4, but Page Logic behaves slightly differently.
For Page Logic, rather than having class names and file paths mapped to PSR-4 namespaces, they are mapped to the URI that triggers them.
go
function
The // TODO: Try to keep logic files as simple as possible, deferring as much work into application classes as possible - easier to maintain and less tightly bound logic to particular URIs.
do
functions
Reacting to user input with // TODO.
// Camel case function names.
// Passing all InputData
- when passing data to other classes use opt-in with
or without
functions.
// TODO: Read more in the User input section.
Properties exposed to Page Logic
// TODO: List of all properties (document, database, etc.)
Automatic Logic Properties
// TODO: Similar to concept of autowiring in Symfony.