tourze / text-manage-bundle
文本格式化管理
Installs: 2 719
Dependents: 7
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/text-manage-bundle
Requires
- league/commonmark: ^2.6.1
- monolog/monolog: ^3.1
- psr/log: ^3|^2|^1
- symfony/config: ^7.3
- symfony/dependency-injection: ^7.3
- symfony/form: ^7.3
- symfony/framework-bundle: ^7.3
- symfony/http-kernel: ^7.3
- symfony/property-access: ^7.3
- symfony/twig-bundle: ^7.3
- symfony/yaml: ^7.3
- tourze/bundle-dependency: 1.*
- tourze/symfony-dependency-service-loader: 1.0.*
- twig/twig: ^3.21
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
- tourze/phpunit-symfony-kernel-test: 1.0.*
- tourze/phpunit-symfony-unit-test: 1.*
This package is auto-updated.
Last update: 2026-02-19 09:47:47 UTC
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