HTML

BEAR.Sunday can render HTML with a choice of template engines.

Choosing a Template Engine

Supported Template Engines

Feature Comparison

Feature Qiq Twig
Escaping Explicit Implicit
Syntax PHP-based Custom syntax

Syntax Comparison

PHP:

<?= $var ?>
<?= htmlspecialchars($var, ENT_QUOTES|ENT_DISALLOWED, 'utf-8') ?>
<?= htmlspecialchars(helper($var, ENT_QUOTES|ENT_DISALLOWED, 'utf-8')) ?>
<?php foreach ($users as $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 

Or

<?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. ↩