tourze/text-manage-bundle
最新稳定版本:1.0.0
Composer 安装命令:
composer require tourze/text-manage-bundle
包简介
文本格式化管理
README 文档
README
TextManageBundle 是一个轻量级的 Symfony Bundle,提供文本格式化和处理的功能。
功能
- 纯文本处理
- Markdown 格式化
- Twig 模板解析
安装
composer require tourze/text-manage-bundle
在 config/bundles.php 中注册 Bundle:
return [ // ... Tourze\TextManageBundle\TextManageBundle::class => ['all' => true], ];
使用方法
基本用法
use Tourze\TextManageBundle\Service\TextFormatter; class MyService { public function __construct( private readonly TextFormatter $textFormatter ) { } public function process(): string { // 基本文本处理 return $this->textFormatter->formatText('Hello World'); } }
Twig 语法处理
// 传入参数解析 Twig 语法 $params = ['name' => 'John']; $text = 'Hello {{ name }}!'; $result = $textFormatter->formatText($text, $params); // 返回 "Hello John!" // 复杂 Twig 语法 $params = ['items' => ['apple', 'banana', 'orange']]; $text = '{% for item in items %}{{ item }}{% if not loop.last %}, {% endif %}{% endfor %}'; $result = $textFormatter->formatText($text, $params); // 返回 "apple, banana, orange"
Markdown 处理
// Markdown 格式化 $text = '# Title\n\n**Bold text**'; $result = $textFormatter->formatText($text); // 返回纯文本,移除 HTML 标签
装饰器模式
本包使用装饰器模式实现了文本格式化处理的链式调用:
PlainFormatter- 基本文本处理MarkdownFormatter- Markdown 格式化(装饰 TextFormatter)TwigFormatter- Twig 模板解析(装饰 TextFormatter)
单元测试
./vendor/bin/phpunit packages/text-manage-bundle/tests
License
MIT
统计信息
- 总下载量: 2.72k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 7
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-19