elliephp / zap
A minimal, fast routing component for ElliePHP API framework based on FastRoute and PSR-7/PSR-15 standards
1.0.0
2026-04-20 12:03 UTC
Requires
- php: ^8.4
- elliephp/support: ^1.0
- nikic/fast-route: ^1.3
- nyholm/psr7: ^1.8
- psr/container: ^2.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- giorgiosironi/eris: ^1.0
- phpunit/phpunit: ^11.0
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 withchildren.
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 configuredescaper{!! $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). Usesrc={$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.