felixdorn/tin
Composer 安装命令:
composer require felixdorn/tin
包简介
tin is a code highlighter for PHP.
README 文档
README
tin is a code highlighter for PHP (Terminal, HTML, etc.).
Installation
Requires PHP 8.3+
You can install the package via composer:
composer require felixdorn/tin
Screenshots
Yes, this comes from a terminal.
Usage
<?php use Felix\Tin\Themes\JetbrainsDark; use Felix\Tin\Tin; echo Tin::from(JetbrainsDark::class, $ansi = true)->highlight("<?php\n\necho 'Hello world';\n");
Customizing the output
You have complete control over the highlighting process. Implement
the Felix\Tin\Contracts\OutputInterface interface or implement a custom theme if
you are just looking to change the colors.
Outputs
$tin = new \Felix\Tin\Tin( new \Felix\Tin\Outputs\AnsiOutput() )
$tin = new \Felix\Tin\Tin( new \Felix\Tin\Outputs\HtmlOutput() )
Callable output is best used in combination with the ANSI or HTML output, you can think of it as a sort of decorator when you need change a small thing without creating a class.
$tin = new \Felix\Tin\Tin( new \Felix\Tin\Outputs\CallableOutput( new \Felix\Tin\Themes\OneDark(), fn (\Felix\Tin\Line $line) => $line->number % 2 ? (new \Felix\Tin\Outputs\AnsiOutput())->transformLine($line) : null ) )
Themes
Themes define the colors used by outputs. The format is r;g;b, to match the default ANSI format.
Creating a theme
You need to extend Felix\Tin\Themes\Theme and set the colors to whatever you want.
The color are RGB values separated by a ;.
use Felix\Tin\Contracts\ThemeInterface; use Felix\Tin\Enums\TokenType; class OneDark extends ThemeInterface { /** {@inheritDoc} */ public function color(TokenType $type): string { return match ($type) { TokenType::Keyword => '199;120;221', TokenType::Variable => '224;107;116', TokenType::Comment => '91;98;110', TokenType::String => '152;195;121', TokenType::Function, TokenType::NamedParameter, TokenType::Attribute => '98;174;239', TokenType::Number, TokenType::Html => '229;192;122', default => '171;178;191', }; } }
Testing
composer test
tin was created by Félix Dorn under the MIT license.
felixdorn/tin 适用场景与选型建议
felixdorn/tin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 17, 最近一次更新时间为 2021 年 11 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 felixdorn/tin 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 felixdorn/tin 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 17
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-11-01

