HTML

The following template engines are available for HTML representation.

Twig vs Qiq

Twig was first released in 2009 and has a large user base. Qiq is a new template engine released in 2021.

Twig uses implicit escaping by default and has custom syntax for control structures. In contrast, Qiq requires explicit escaping and uses PHP syntax as the base template language. Twig has a large codebase and rich features, while Qiq is compact and simple. (Using pure PHP syntax in Qiq makes it IDE and static analysis-friendly, although it may be redundant.)

Syntax Comparison

PHP

<?= htmlspecialchars($var, ENT_QUOTES|ENT_DISALLOWED, 'utf-8') ?>
<?= htmlspecialchars(helper($var, ENT_QUOTES|ENT_DISALLOWED, 'utf-8')) ?>
<?php foreach ($users => $user): ?>
 * <?= $user->name; ?>
<?php endforeach; ?>

Twig

{{ var | raw }}
{{ var }}
{{ var | helper }}
{% for user in users %}
  * {{ user.name }}
{% endfor %}

Qiq

{{% var }}
{{h $var }}
{{h helper($var) }}
{{ foreach($users => $user) }}
  * {{h $user->name }}
{{ endforeach }}

{{ var }} // Not displayed 
<?php /** @var Template $this */ ?>
<?= $this->h($var) ?>

Renderer

The renderer, bound to RenderInterface and injected into the ResourceObject, generates the representation of the resource. The resource itself is agnostic about its representation.

Since the renderer is injected per resource, it is possible to use multiple template engines simultaneously.

Halo UI for Development

During development, you can render a UI element called Halo 1 around the rendered resource. Halo provides information about the resource’s state, representation, and applied interceptors. It also provides links to open the corresponding resource class or resource template in PHPStorm.

Halo displays resource state

  • Halo Home (Border and Tools Display)
  • Resource State
  • Resource Representation
  • Profile

You can try a demo of Halo in the demo.

Performance Monitoring

Halo also displays performance information about the resource, including execution time, memory usage, and a link to the profiler.

Halo displays performance

Installation

To enable profiling, you need to install xhprof, which helps identify performance bottlenecks.

pecl install xhprof
// Also add 'extension=xhprof.so' to your php.ini file

To visualize and graphically display call graphs, you need to install graphviz. Example: Call Graph Demo

// macOS
brew install graphviz

// Windows
// Download and install the installer from the graphviz website

// Linux (Ubuntu)
sudo apt-get install graphviz

In your application, create a Dev context module and install the HaloModule.

class DevModule extends AbstractModule
{
    protected function configure(): void
    {
        $this->install(new HaloModule($this));
    }
}

  1. The name is derived from a similar feature in the Seaside framework for Smalltalk.