A minimal, fast routing component for ElliePHP API framework based on FastRoute and PSR-7/PSR-15 standards

Maintainers

Package info

github.com/ElliePHP/ZapEngine

Homepage

Issues

pkg:composer/elliephp/zap

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

1.0.0 2026-04-20 12:03 UTC

This package is not auto-updated.

Last update: 2026-04-22 11:29:07 UTC


README

A compiler-based templating engine for microframeworks.

  • Fast: templates compile to cached PHP (no runtime parsing; OPcache-friendly).
  • Safe by default: { $expr } is escaped, raw output is explicit via {!! $expr !!}.
  • Blade-like ergonomics: @if, @foreach, file-based components, layouts with children.

Install

composer require elliephp/zap

Quickstart

Folder layout

your-app/
  views/
    home.view
  components/
    Layout.php
    Layout.view
    PostCard.php
    PostCard.view
  cache/

Bootstrap

use ElliePHP\Components\View\Engine;

$engine = Engine::bootstrap([
    'views_path' => __DIR__ . '/views',
    'components_path' => __DIR__ . '/components',
    'cache_path' => __DIR__ . '/cache',
    'debug' => true,
    'escaper' => static fn($v) => htmlspecialchars((string)$v, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'),
]);

Render a view

views/home.view:

<Layout title="Home">
    <h1>Hello { $user->name }</h1>

    @if ($user)
        <PostCard post={$post} />
    @else
        <GuestBanner />
    @endif

    @foreach ($posts as $post)
        <PostCard post={$post} />
    @endforeach
</Layout>
$html = $engine->render('home', [
    'user' => $user,
    'posts' => $posts,
    'post' => $post,
]);

Template cheatsheet

Output (escaped vs raw)

  • { $expr } escapes via your configured escaper
  • {!! $expr !!} outputs raw HTML

Control flow

  • @if (...) / @elseif (...) / @else / @endif
  • @foreach (...) / @endforeach
  • @break, @continue

Components

  • Lowercase tags are HTML (<div>, <a>, <img />)
  • PascalCase tags are components (<Layout>, <PostCard />)
  • Props: post={$post} (expression), title="Home" (string), disabled (boolean)

Common patterns

Layouts + children

Children are passed as a prop named children (already-rendered HTML).

components/Layout.view:

<div class="layout">
    <header>{ $title }</header>
    <main>{!! $children !!}</main>
</div>

Component class + template

components/PostCard.php:

use ElliePHP\Components\View\Component\Component;

final class PostCard extends Component
{
    public function __construct(public mixed $post) {}
}

components/PostCard.view:

<article>
    <h2>{ $post->title }</h2>
</article>

Gotchas (read this once)

  • Void HTML tags: write them as self-closing /> (example: <img ... />)
  • JS/CSS with {}: inline JS/CSS containing lots of {} can be mis-tokenized; prefer external assets for complex scripts/styles
  • Attribute expressions: don’t write src="{ $url }" (that’s a literal string). Use src={$url}.

Examples

  • CLI example:
php examples/basic/run.php
  • Browser example:
php -S 127.0.0.1:8000 -t examples/browser/public

Nerd docs

If you want the compiler pipeline, AST nodes, caching contracts, source maps, and extension points, see docs/TECHNICAL.md.