承接 rookie0/twig-infer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

rookie0/twig-infer

最新稳定版本:v1.0.0

Composer 安装命令:

composer require rookie0/twig-infer

包简介

Twig template variables infer

README 文档

README

Infer twig template variables.

$template = <<<TPL
{{ a_variable }}
{{ foo.bar }}
{{ attribute(foo, 'data-foo') }}

{{ name|striptags|title }}

{% if post.status is not constant('Post::PUBLISHED') %}
    {{ list|join(', ') }}
{% endif %}

{% for item in navigation %}
    {{ item.href }} - {{ item.caption }}
{% endfor %}

{% for user in users %}
    {{ user.username|e }}

    {% for role in user.roles %}
        {{ role.name }} - {{ role.slug }}

        {% for perm in role.permissions %}
            {{ perm.method }} - {{ perm.path }}
        {% endfor %}
    {% endfor %}

    {% for action in actions %}
        {{ action.url }} - {{ action.name }}
    {% endfor %}
{% endfor %}
TPL;

$twig  = new Environment(new ArrayLoader(['template' => $template]));
$infer = new Infer($twig);

$vars = $infer->variables('template');

// dump $vars
[
    "a_variable" => [],
    "foo"        => [
        "bar"      => [],
        "data-foo" => [],
    ],
    "name"       => [],
    "post"       => [
        "status" => [],
    ],
    "list"       => [],
    "navigation" => [
        [
            "href"    => [],
            "caption" => [],
        ],
    ],
    "users"      => [
        [
            "username" => [],
            "roles"    => [
                [
                    "name"        => [],
                    "slug"        => [],
                    "permissions" => [
                        [
                            "method" => [],
                            "path"   => [],
                        ],
                    ],
                ],
            ],
        ],
    ],
    "actions"    => [
        [
            "url"  => [],
            "name" => [],
        ],
    ],
]

The output array keys are the template variables, and the value show the variable structure and usage:

  • Empty array meaning simple variable just to display
  • Associative array meaning array or object to display the keys or properties
  • Numeric array meaning an array to loop

Installation

composer require rookie0/twig-infer

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-01-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固