roy404/blades
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; ?>'); });
roy404/blades 适用场景与选型建议
roy404/blades 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 315 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 01 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「compiler」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 roy404/blades 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 roy404/blades 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 roy404/blades 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A token based Javascript parser/minifier designed for compressing inline scripts on the fly, written in PHP
A token based CSS Document parser and minifier written in PHP
A token based HTML document parser and minifier. Minify HTML documents including inline CSS, Javascript, and SVG's on the fly. Extract document text, attributes, and fragments. Full test suite.
Simple class that compiles Laravel Blade files
A configurable LESS compiler for Symfony projects.
Env builder is a package which collects different env files within a specified directory and compiles them into one single .env file, useful when you have different .env files laying around in different folders and you want to have one single big file that you can load with Symfony's DotEnv loader o
统计信息
- 总下载量: 315
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 14
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-01-13