alizharb/azhbx

A modern, production-ready PHP 8.5+ templating engine inspired by Handlebars.

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/alizharb/azhbx

v1.2.0 2025-11-24 12:37 UTC

This package is auto-updated.

Last update: 2025-11-24 12:39:51 UTC


README

๐Ÿš€ AzHbx

Next-Generation PHP Templating Engine

PHP Version License Tests Static Analysis Total Downloads GitHub Stars Sponsor

Handlebars-inspired โ€ข Modern PHP โ€ข Production-Ready

Features โ€ข Installation โ€ข Quick Start โ€ข Documentation โ€ข Examples

๐ŸŽฏ Overview

AzHbx Logo

AzHbx (AlizHarb Handlebars Extended)

PHP Version Version License Tests is a powerful, modern PHP templating engine designed for PHP 8.3+. It combines the elegance of Handlebars syntax with cutting-edge PHP features like Property Hooks and Attributes, delivering exceptional performance and developer experience.

Why AzHbx?

  • ๐Ÿ”’ Secure by Default: Auto-escaping prevents XSS attacks
  • โšก Blazing Fast: Compiles to native PHP with OpCache support
  • ๐ŸŽจ Theme System: Built-in multi-theme support with fallback logic
  • ๐Ÿงฉ Modular Architecture: Organize templates by feature/package
  • ๐Ÿ”Œ Plugin System: Extend functionality with PHP 8.3+ Attributes
  • ๐Ÿ“ฆ Zero Dependencies: Works with or without Composer
  • ๐ŸŽฏ Developer-Friendly: Clean syntax, comprehensive docs, great DX

โœจ Features

Core Templating

  • Handlebars-Inspired Syntax: Familiar {{ }} expressions
  • Nested Data Access: Dot notation ({{ user.profile.name }})
  • Control Structures: if, unless, each, with
  • Layouts & Partials: Template inheritance and reusable components
  • Custom Helpers: Extend with your own logic
  • Whitespace Control: Fine-tune output formatting

Advanced Features

  • ๐ŸŽจ Theme Management: Switch themes at runtime with smart fallbacks
  • ๐Ÿ“ฆ Module System: Namespace templates by feature (blog::post)
  • ๐Ÿ”Œ Plugin Architecture: Use PHP 8.3+ #[Helper] attributes
  • โšก Async Support: Compatible with PHP Fibers for non-blocking I/O
  • ๐Ÿ” Security First: XSS prevention with auto-escaping
  • ๐Ÿ’พ Smart Caching: Automatic recompilation on file changes
  • ๐Ÿš€ Framework Adapters: Native integration for Laravel and Symfony
  • ๐ŸŽ๏ธ High Performance: Compile-time optimizations make it faster than Twig and Blade
  • ๐Ÿ› ๏ธ Profiler & Debug Toolbar: Real-time performance stats and hot reload during development.
  • โš™๏ธ Error Code Catalog: Standardized error codes for consistent error handling.
  • ๐Ÿ”ง Quality Tools: Integrated PHPStan and PHP-CS-Fixer for static analysis and code style.

๐Ÿ“ฆ Installation

Via Composer (Recommended)

composer require alizharb/azhbx

Standalone (No Composer)

Download the source and include the autoloader:

require 'path/to/azhbx/src/autoload.php';

๐Ÿš€ Quick Start

use AlizHarb\AzHbx\Engine;

// Initialize
$engine = new Engine([
    'views_path' => __DIR__ . '/views',
    'cache_path' => __DIR__ . '/cache',
    // Optional: Custom paths for themes and modules
    // 'themes_path' => __DIR__ . '/custom_themes',
    // 'modules_path' => __DIR__ . '/custom_modules',
]);

// Render
echo $engine->render('welcome', [
    'user' => [
        'name' => 'Alice',
        'role' => 'Admin'
    ]
]);

Template (views/themes/default/welcome.hbx):

<h1>Welcome, {{ user.name }}!</h1>
<p>Role: {{ user.role }}</p>

๐Ÿ“š Documentation

๐ŸŒ Online Documentation

Visit the live documentation: https://alizharb.github.io/azhbx/

Browse comprehensive guides and examples:

๐Ÿ“– Local Documentation

You can also run the documentation website locally:

php -S localhost:8000 -t docs

Visit http://localhost:8000 to browse the interactive docs.

๐Ÿ’ก Examples

Explore real-world examples in the examples/ directory:

php -S localhost:8001 -t examples

Visit http://localhost:8001 to see:

  • Basic rendering
  • Control structures
  • Layouts and partials
  • Custom helpers
  • Theme switching
  • Module system
  • Plugin architecture
  • Async rendering with Fibers

๐Ÿงฉ Component System

AzHbx supports a powerful component system with Blade-like syntax:

<!-- Inline Component -->
<az-Icon name="user" size="lg" />

<!-- Block Component -->
<az-Alert type="error">
  <strong>Error!</strong> Something went wrong.
</az-Alert>

Components are stored in views/components/ (e.g., views/components/alert.hbx).

โšก Directives

Directives are special helpers starting with @ for common tasks:

  • {{ @csrf }} - CSRF token input
  • {{ @method "PUT" }} - HTTP method spoofing
  • {{# @auth }}...{{/ @auth }} - Content for authenticated users
  • {{# @guest }}...{{/ @guest }} - Content for guests
  • {{# @env "production" }}...{{/ @env }} - Environment-specific content

๐Ÿ”Œ Plugin System

Create powerful extensions using PHP 8.5+ Attributes:

use AlizHarb\AzHbx\Contracts\PluginInterface;
use AlizHarb\AzHbx\Attributes\Helper;
use AlizHarb\AzHbx\Attributes\Directive;

class MyPlugin implements PluginInterface
{
    public function register(Engine $engine): void {}

    #[Helper('uppercase')]
    public function uppercase(string $text): string
    {
        return strtoupper($text);
    }

    #[Directive('myDirective')]
    public function myDirective(array $context): string
    {
        return "Custom Directive";
    }
}

๐ŸŽจ Theme System

Switch themes dynamically:

$engine->setTheme('dark');
echo $engine->render('home', $data);

Directory Structure:

views/
โ”œโ”€โ”€ themes/
โ”‚   โ”œโ”€โ”€ default/
โ”‚   โ”‚   โ””โ”€โ”€ home.hbx
โ”‚   โ””โ”€โ”€ dark/
โ”‚       โ””โ”€โ”€ home.hbx  โ† Overrides default
โ””โ”€โ”€ partials/
    โ””โ”€โ”€ header.hbx

๐Ÿงช Testing

Run the test suite:

composer test

Or with coverage:

composer test:coverage

๐Ÿค Contributing

We welcome contributions! Please see CONTRIBUTING.md for details.

Development Setup

git clone https://github.com/AlizHarb/azhbx.git
cd azhbx
composer install
composer test

๐Ÿ“‹ Requirements

  • PHP: 8.3 or higher
  • Extensions: mbstring

๐Ÿ“„ License

AzHbx is open-source software licensed under the MIT License.

๐Ÿ™ Acknowledgments

Inspired by Handlebars.js and modern PHP best practices.

Built with โค๏ธ by Ali Harb

โฌ† Back to Top