Download the PHP package makinacorpus/php-layout without Composer
On this page you can find all versions of the php package makinacorpus/php-layout. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package php-layout
PHP basic layout API
Object representation of a display layout, based upon CSS basic functionnality:
- all items are always stacked vertically in containers;
- a container can be a column set, case in which each column contains itself another container which will stack items vertically.
Once you understood this basic principle, you can use the API.
Leaf items (non container) are represented by an interface, with very few methods to implement, and a handler service, whose basic features are:
- preload all items at once;
- render a set of items at once.
You probably understood it now, this was tailored for rendering speed on more complex frameworks that are already able to provide support for preloading and pre-rendering objects (for example, Drupal).
Please note this is, as of today, rather a playground than an API you could use, but it worth the short of trying.
Before going deeper
You should be aware the goal of this API is to, in a near future, be integrated into page composition tools, and its API to be hidden behind user friendly UI for contributing. Don't be afraid of the concrete code example below, it only shows how it works, but won't be revelant for concrete use cases of this API.
Complete example
For the sake of simplicity, we are going to use the unit test example to explain the layout we want to display, here is an HTML reprensentation of what the bootstrap grid we want:
Which, for the sake of comprehensibility, would display as such (yes I am sorry this is basic copy/paste of the comment lying in the unit test):
Creating a layout
And the associated PHP code for creating the container tree:
Render the layout
Before initializing the type handlers, we will first create the containers type handlers: containers are the basis of the grid and are responsible for the vertical and horizontal layout management.
Now that we have our top-level container, we need to instanciate the various type handlers:
Then render it:
Which should give you for the $string
the HTML representation we did show
before.
Why should it render fast?
When you ask for rendering, two very important things are done:
-
the whole container tree is recursively traversed, and all leaf items are referenced in a flat index;
- for each item type, all items are preloaded then rendered in one call.
Because containers do not represent anything related to the database or any business object either, you don't have anything to preload nor very complex in their rendering: they are rendered in the end in their inter-dependency order.