decodelabs/tagged 问题修复 & 功能扩展

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

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

decodelabs/tagged

Composer 安装命令:

composer require decodelabs/tagged

包简介

PHP markup generation without the fuss

README 文档

README

PHP from Packagist Latest Version Total Downloads GitHub Workflow Status PHPStan License

PHP markup generation without the fuss.

Tagged provides a simple, powerful and beautiful way to create HTML markup without the spaghetti.

Installation

This package requires PHP 8.4 or higher.

Install via Composer:

composer require decodelabs/tagged

Usage

HTML markup

Generate markup using a simple, flexible interface.

use DecodeLabs\Tagged as Html;

echo Html::{'div.my-class#my-id'}(
    content: 'This is element content',
    title: 'This is a title'
);

...creates:

<div class="my-class" id="my-id" title="This is a title">This is element content</div>

Create individual tags without content:

use DecodeLabs\Tagged as Html;

$tag = Html::tag('div.my-class');

echo $tag->open();
echo 'Content';
echo $tag->close();

Wrap HTML strings to be used where an instance of Markup is needed:

use DecodeLabs\Tagged as Html;

$buffer = Html::raw('<span class="test">My span</span>');

Dump script data to Html:

yield Html::script(
    Html::raw(json_encode( $some_data )),
    type: 'application/json'
);

Prepare arbitrary input for Markup output:

use DecodeLabs\Tagged as Html;

$markup = Html::wrap(
    function() {
        yield Html::h1('My title');
    },
    [Html::p(['This is ', Html::strong('mixed'), ' content'])]
);

Attributes

Set attributes inline:

use DecodeLabs\Tagged as Html;

echo Html::{'div[data-attr=foo]'}('This is a div with an attribute');

Set attributes via an array:

use DecodeLabs\Tagged as Html;

echo Html::{'div'}(
    content: 'This is a div with an attribute',
    dataAttr: 'foo'
);

Nesting

You can nest elements in multiple ways:

use DecodeLabs\Tagged as Html;

// Pass in nested elements via array
echo Html::div([
    Html::{'span.inner1'}('Inner 1'),
    ' ',
    Html::{'span.inner2'}('Inner 2')
]);


// Return anything and everything via a generator
echo Html::div(function($el) {
    // $el is the root element
    $el->addClass('container');

    // Nest elements with a single call
    yield Html::{'header > h1'}('This is a header');
    yield Html::p('This is a paragraph');

    // Set attributes inline
    yield Html::{'p[data-target=open]'}('Target paragraph');

    // Generator return values are rendered too
    return Html::{'div.awesome'}('This is awesome!');
});

Time and date

Format and wrap dates and intervals

use DecodeLabs\Tagged\Time;

// Custom format
Time::format('now', 'd/m/Y', 'Europe/London');

// Locale format
// When timezone is true it is fetched from Cosmos
Time::locale('now', 'long', 'long', true);

// Locale shortcuts
Time::dateTime('tomorrow'); // medium
Time::longTime('yesterday');
Time::shortDate('yesterday');
// ...etc


// Intervals
Time::since('yesterday'); // 1 day ago
Time::until('tomorrow'); // 1 day from now
Time::sinceAbs('yesterday'); // 1 day
Time::untilAbs('yesterday'); // -1 day
Time::between('yesterday', 'tomorrow'); // 1 day

Media embeds

Normalize embed codes shared from media sites:

use DecodeLabs\Tagged\Embed\Video;

echo Video::parse('https://www.youtube.com/watch?v=RG9TMn1FJzc');

Components

Tagged also supports a higher level component abstraction allowing for more complex markup generation via the same interface. Components are called using an @name syntax:

use DecodeLabs\Tagged as Html;

echo Html::{'@list'}($iterable, 'div.container', 'div.item', function($item) {
    return Html::{'span'}($item);
});

echo Html::{'@img'}('path/to/image.jpg', 'alt text');

See the components directory for a list of available components.

Licensing

Tagged is licensed under the MIT License. See LICENSE for the full license text.

decodelabs/tagged 适用场景与选型建议

decodelabs/tagged 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.85k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2019 年 09 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「generator」 「html」 「markup」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 11.85k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 14
  • 依赖项目数: 8
  • 推荐数: 2

GitHub 信息

  • Stars: 6
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-09-10