cleaniquecoders/placeholdify
Composer 安装命令:
composer require cleaniquecoders/placeholdify
包简介
A powerful and extendable placeholder replacement engine for Laravel templates with context mapping, custom formatters, and fluent API
README 文档
README
A powerful and extendable placeholder replacement engine for Laravel that makes working with dynamic templates a breeze. Perfect for generating letters, invoices, certificates, emails, and any document that requires dynamic content injection.
Features
- 🎯 Context-Aware - Register reusable context mappings for your models
- 🎨 Custom Formatters - Built-in formatters for dates, currency, numbers, and easy custom formatter registration
- ⚡ Lazy Evaluation - Defer expensive operations until needed
- 🔧 Template Modifiers - Support inline formatting like
{amount|currency:USD}or{name|upper} - 🧩 Extendable - Easily create dedicated context classes for different document types
- 💬 Fluent API - Chainable methods for clean, readable code
- 🛡️ Safe Defaults - Built-in fallback values and error handling
- 📦 Zero Dependencies - Works with plain Laravel, no extra packages required
Installation
composer require cleaniquecoders/placeholdify
Optionally, publish the config file:
php artisan vendor:publish --tag=placeholdify-config
Quick Start
Simple Replacement
use CleaniqueCoders\Placeholdify\PlaceholderHandler; $template = "Hello {name}, your order #{orderNo} totaling {amount} has been confirmed."; $content = PlaceholderHandler::process($template, [ 'name' => 'John Doe', 'orderNo' => '12345', 'amount' => '$99.99' ]); // Output: "Hello John Doe, your order #12345 totaling $99.99 has been confirmed."
Fluent API
$handler = new PlaceholderHandler(); $content = $handler ->add('name', $user->name) ->addDate('today', now(), 'F j, Y') ->addFormatted('total', 1234.56, 'currency', 'MYR') ->replace($template);
Using Contexts
// Register context once $handler->registerContextMapping('user', [ 'name' => 'name', 'email' => 'email', 'role' => fn($user) => $user->roles->pluck('name')->join(', '), ]); // Use anywhere $content = $handler ->useContext('user', $user, 'customer') ->replace('Hello {customer.name}, your role is {customer.role}');
Template Modifiers
$template = "Student: {name|upper}, Amount: {fee|currency:MYR}, Date: {created_at|date:d/m/Y}"; $content = $handler ->add('name', 'john doe') ->add('fee', 150.50) ->add('created_at', now()) ->replaceWithModifiers($template); // Output: "Student: JOHN DOE, Amount: MYR 150.50, Date: 16/10/2025"
Template Classes
Create dedicated template classes for complex scenarios:
use CleaniqueCoders\Placeholdify\PlaceholdifyBase; class InvoiceTemplate extends PlaceholdifyBase { protected function configure(): void { $this->handler->setFallback('N/A'); } public function build($invoice): PlaceholderHandler { return $this->handler ->add('invoice_no', $invoice->invoice_number) ->addFormatted('total', $invoice->total, 'currency', 'MYR') ->addDate('invoice_date', $invoice->created_at, 'd/m/Y') ->useContext('customer', $invoice->customer, 'customer'); } } // Usage $template = new InvoiceTemplate(); $content = $template->generate($invoice, $templateContent);
Documentation
For comprehensive documentation, examples, and advanced usage:
- 📖 Complete Documentation - Full documentation index
- 🚀 Basic Usage - Learn the fundamentals
- 🎨 Formatters - Built-in and custom formatters
- 🔄 Context System - Reusable model mappings
- ⚡ Advanced Features - Lazy evaluation, conditionals, and more
- 🏗️ Template Classes - Organize your template logic
- ⚙️ Configuration - Customize default behavior
- 🛠️ Artisan Commands - Command-line tools
- 🌍 Real World Examples - Complete implementation examples
- 📚 API Reference - Complete method documentation
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
cleaniquecoders/placeholdify 适用场景与选型建议
cleaniquecoders/placeholdify 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 4, 最近一次更新时间为 2025 年 10 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「Cleanique Coders」 「placeholdify」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cleaniquecoders/placeholdify 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cleaniquecoders/placeholdify 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cleaniquecoders/placeholdify 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provide organization related app
Spatie Media Library Manager
Effortlessly manage your Laravel API versions with flexible, header-based versioning control.
Alfabank REST API integration
AppPulse provide a comprehensive, easy-to-use monitoring tool with uptime tracking, SSL certificate checks, and customisable notifications.
Define, sign, dispatch and log outgoing webhooks in Laravel with retries, HMAC signatures, and an optional Livewire + Flux admin UI.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-16