roy404/blades 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

roy404/blades

最新稳定版本:1.7.9

Composer 安装命令:

composer require roy404/blades

包简介

A PHP library that provides Blade-like templating functionality, enabling seamless integration of Blade syntax and components.

README 文档

README

This library allows you to integrate Blade-like templating functionality into your PHP application. It enables the use of Blade syntax and components, offering a familiar and powerful templating engine for your project.

Installation

To get started, install the bundle via Composer:

composer require roy404/blades

Blades Feature Documentation

Blades is a PHP library designed to provide Blade-inspired templating capabilities. With this library, you can use Blade syntax and custom directives in your PHP applications, facilitating a smooth transition for developers. The library enhances your templating workflow with custom methods and functionalities that mimic Blade's behavior while offering additional flexibility for use outside the Laravel ecosystem.

Blade Custom Methods Usage Guide

This guide helps you understand when and how to use the compile, loadDirectives, and load methods in your project.

🧩 1. loadDirectives()

🔍 What It Does

  • Loads all directive definition files from a given directory.
  • Each directive file should define logic extending the compiler.

✅ When To Use

  • You need to register your own custom directives.
  • You want to make sure directives are available before calling compile().

Note: You usually don’t need to call this manually — compile() will automatically invoke it if no directives are loaded.

🧪 Example

Blade::loadDirectives(__DIR__ . '/directives');

🧩 2. compile()

🔍 What It Does

  • Compiles raw template content (as a string).
  • Applies all registered compiler instances and directives.
  • Returns the final compiled output as a string.

✅ When To Use

  • You want to render template content stored in a variable or database.
  • You need to manually post-process or store the compiled output.

🧪 Example

$content = '<div>Hello, {{ $name }}!</div>';
echo Blade::compile($content, ['name' => 'Robroy Canales']);

🧩 3. load()

🔍 What It Does

  • Loads and compiles a .php (or template) file.
  • Renders it directly with the provided variables.

✅ When To Use

  • You have a physical file you want to render.
  • You want to output the view directly (e.g. from a controller or route handler).

🧪 Example

Blade::load(__DIR__ . '/views/profile.php', ['user' => $user]);

🛠️ 4. build()

🔍 What It Does

  • Initializes a new Blade engine instance using a custom compiler (implementing ViewsInterface).
  • Returns the instance for chaining, such as registering custom directives.

✅ When To Use

  • You want to register custom directives to extend the template engine.
  • You are implementing your own logic inside a compiler class (like a plugin).

🧪 Example

Blade::build(new Loops)->register(function (Blade $blade) {
	// Add @break directive
	$blade->directive('break', fn() => '<?php break; ?>');

	// Add @continue directive
	$blade->directive('continue', fn() => '<?php continue; ?>');
});

统计信息

  • 总下载量: 315
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-13