承接 comhon-project/template-renderer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

comhon-project/template-renderer

Composer 安装命令:

composer require comhon-project/template-renderer

包简介

PHP library that permit to render templates and permit to define which renderer to use

README 文档

README

  • Your library needs to render templates (example: email template) but you don't want to implement it ?
  • You want your template renderer to be customizable by developers that use your library ?

This library is made for that! it permit to render templates and permit to define which renderer to use. This library is generally intended for Laravel projects but you can use it even if you are not implementing a Laravel project.

There is only one renderer available by default (twig), but you can add your own by defining your own driver.

Installation

You can install the package via composer:

composer require comhon-project/template-renderer

For laravel project, you can publish the config file with:

php artisan vendor:publish --tag="template-renderer-config"

Usage

Laravel project

$rendered = Template::render(
    'Hello {{ user.name }} !!!',
    ['user' => ['name' => 'john doe']]
);

echo $rendered;
// output: Hello john doe !!!

Non Laravel project

use Comhon\TemplateRenderer\TemplateManager;

// the instantiation mechanism should be implemented in a specific place
// and called only one time (TemplateManager should be used as singleton)
$templateManager = new TemplateManager($app);

$rendered = $templateManager->render(
    'Hello {{ user.name }} !!!',
    ['user' => ['name' => 'john doe']]
);

echo $rendered;
// output: Hello john doe !!!

Adding custom renderer driver

First, you will have to define a class that implements Comhon\TemplateRenderer\Renderers\RendererInterface

<?php
use Comhon\TemplateRenderer\Renderers\RendererInterface;

class MyTemplateRenderer implements RendererInterface
{
    public function setDefaultLocale(string $locale) {}
    public function setDefaultTimezone(string $timezone) {}
    public function validate(string $template) {}
    public function render(
        string $template,
        array $replacements,
        ?string $defaultLocale = null,
        ?string $defaultTimezone = null,
        ?string $preferredTimezone = null
    ): string {}
}

Then, you will have to register your driver by calling the Template facade's extend method:
(In laravel project, you may call this function in the boot method of your AppServiceProvider)

    Template::extend('my-renderer', function ($app) {
        return new MyTemplateRenderer($app);
    });

In laravel project, you can set your renderer as the default one. To do so, modify the default_renderer value in the config file.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.

comhon-project/template-renderer 适用场景与选型建议

comhon-project/template-renderer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.44k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 11 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「template-renderer」 「comhon」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 comhon-project/template-renderer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 comhon-project/template-renderer 我们能提供哪些服务?
定制开发 / 二次开发

基于 comhon-project/template-renderer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-24