定制 mistralys/mailcode 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

mistralys/mailcode

Composer 安装命令:

composer require mistralys/mailcode

包简介

Mailcode syntax parsing library for PHP

README 文档

README

A backend-agnostic preprocessor command language for email templates.

What Is Mailcode?

Email template systems often lock you into a specific backend preprocessor — Velocity, HubL, or whatever your mailing platform speaks. Mailcode frees you from that. Authors write in one readable, verbose syntax, and the library translates it into whatever the backend requires. Your email editor becomes portable across platforms without rewriting a single template.

Features

  • One syntax, multiple backends — Write once, translate to Apache Velocity or Hubspot HubL automatically.
  • Self-documenting templates — Commands read like sentences ({if variable: $STATUS == "premium"}), making reviews easy for non-developers.
  • Rich command set — Variables, conditionals (16 subtypes), loops, date/number/price formatting, phone formatting, URL encoding, snippets, and more.
  • Safeguard system — Protect Mailcode commands while you process surrounding HTML/text freely, then restore them intact.
  • Programmatic command creation — Build commands in PHP via a fluent factory API, not just by parsing strings.
  • Syntax highlighting — Render commands with CSS-styled HTML for visual editors.
  • Validation built in — Parse results include detailed error reporting; no silent failures.

Requirements

  • PHP >= 8.4
  • Composer
  • ext-json

Quick Start

composer require mistralys/mailcode
use Mailcode\Mailcode;
use AppUtils\FileHelper\FolderInfo;

// Required: set a cache folder for class discovery
Mailcode::setCacheFolder(FolderInfo::factory('/path/to/cache'));

// Parse a string containing Mailcode commands
$collection = Mailcode::create()->parseString('{showvar: $CUSTOMER.NAME}');

// Safeguard commands during text processing
$safeguard = Mailcode::create()->createSafeguard($htmlContent);
$safe = $safeguard->makeSafe();
// ... process the text freely ...
$result = $safeguard->makeWhole($safe);

// Translate to Apache Velocity
$velocity = Mailcode::create()->createTranslator()->createApacheVelocity();
$output = $velocity->translateSafeguard($safeguard);

Syntax at a Glance

Hello {showvar: $CUSTOMER.FIRSTNAME}, your order is ready.

Ordered on: {showdate: $ORDER.DATE "d.m.Y"}
Total: {showprice: $ORDER.TOTAL}

{if variable: $CUSTOMER.STATUS == "premium"}
    You have free shipping on this order.
{end}

{for: $PRODUCT in: $USER_LIST_PRODUCTS}
- {showvar: $PRODUCT.NAME}: {showprice: $PRODUCT.PRICE}
{end}

Supported Commands

Category Commands
Display {showvar}, {showdate}, {shownumber}, {showprice}, {showsnippet}, {showencoded}, {showphone}, {showurl}
Variables {setvar} (string, arithmetic, list counting)
Conditionals {if}, {elseif}, {else}, {end} — 16 subtypes (variable, contains, empty, list-contains, begins-with, bigger-than, etc.)
Loops {for}, {break}
Formatting {mono}, {code}
Meta {comment}

Translation Targets

Syntax Coverage
Apache Velocity Full — all commands translated
Hubspot HubL Partial — {break} and {showsnippet} not supported

Learn More

Resource Description
Usage Guide Full syntax reference, all commands, encoding, safeguarding, and translation examples
Apache Velocity Translation Velocity-specific translation details and configuration
HubL Translation Hubspot HubL translation support and limitations
Changelog Version history and breaking changes

License

MIT — Sebastian Mordziol / Mistralys

mistralys/mailcode 适用场景与选型建议

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

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

围绕 mistralys/mailcode 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-02-24