tourze/text-manage-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

tourze/text-manage-bundle

最新稳定版本:1.0.0

Composer 安装命令:

composer require tourze/text-manage-bundle

包简介

文本格式化管理

README 文档

README

English | 中文

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 标签

装饰器模式

本包使用装饰器模式实现了文本格式化处理的链式调用:

  1. PlainFormatter - 基本文本处理
  2. MarkdownFormatter - Markdown 格式化(装饰 TextFormatter)
  3. TwigFormatter - Twig 模板解析(装饰 TextFormatter)

单元测试

./vendor/bin/phpunit packages/text-manage-bundle/tests

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-19