定制 selene-framework/matisse 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

selene-framework/matisse

最新稳定版本:0.4.3

Composer 安装命令:

composer require selene-framework/matisse

包简介

A component-based template engine for PHP web applications

README 文档

README

What is Matisse?

Matisse is a component-based template engine for PHP web applications.

Like any other template engine, Matisse generates an HTML document by combining a source (template) document with data from your domain model.

Unlike most other PHP template engines, which deal with HTML markup with embedded commands written on some DSL, Matisse works with components, which are parametrised, composable and reusable units of rendering logic and markup that are written as XML tags.

The source template is an HTML text file where, besides common HTML tags (always lower cased), special tags beginning with a capital letter specify dynamic components.

Example of a Matisse template:

<h1>Some HTML text</h1>
<form>
    <Input name="field1" value="{{ myVar }}"/>
    <Repeat for="{{ !myData }}">
        <Header><ul></Header>
        <li>Item {{ name }}</li>
        <Footer></ul></Footer>
        <NoData>The are no items.</NoData>
    </Repeat>
</form>

On the example above, notice how the <ul> tag is only closed inside the <Footer> tag, seemingly violating the correct HTML tag nesting structure of the template. In reality, the template is perfectly valid and so is the generated HTML output. This happens because, for Matisse, all HTML tags are simply raw text, without any special meaning. All text lying between component tags (those beginning with a capital letter) is converted into as few as possible Text components.

So, the real DOM (as parsed by Matisse) for the example above is:

<Text/>
<Input/>
<Repeat>
    <Header/>
    <Text/>
    <Footer/>
    <NoData/>
</Repeat>
<Text/>

Each component tag is converted into an instance of a corresponding PHP class. When the template is rendered, each component instance is responsible for generating an HTML representation of that component, together with optional (embedded or external) javascript code and stylesheet references or embedded CSS styles.

When writing templates, HTML markup should be written in HTML 5 syntax, component tags must be written in XML syntax. This means attribute values must be always enclosed in quotes, and tags must always be closed, even if the tag has no content (you can use the self-closing tag syntax: <Component/>).

Components can also be defined with pure markup via template files, without any PHP code. Those templates are conceptually similar to parametric macros.

Macro components insert their markup into the host template and then they disappear, leaving just the generated markup (which may contain additional components). When the template is cached to disk for future reuse, all macro components are gone, so the cached template is more performant than the original one.

A more advanced example of a Matisse template, which defines a macro component that implements a customisable panel:

<Template name="Form" defaultParam="content">
  <Param name="type" type="text" default="box-solid box-default"/>
  <Param name="title" type="text"/>
  <Param name="content" type="source"/>
  <Param name="footer" type="source"/>

  <div class="form box {{ @type }}">
    <If the="{{ @title }}" isSet>
      <div class="box-header with-border">
        <h3 class="box-title">{{ @title }}</h3>
      </div>
    </If>
    <div class="box-body">
      {{ @content }}
    </div>
    <If the="{{ @footer }}" isSet>
      <div class="box-footer">
        {{ @footer }}
      </div>
    </If>
  </div>
</Template>

You can then create instances of this component like this:

<Form type="box-info" title="My title">
  <h1>Welcome</h1>
  <p>Some text here...</p>
  <Footer>
    {{ footerText }}
  </Footer>
</Form>

When parsed the template will undergo macro expansion and will be converted to it's final form:

<div class="form box box-info">
  <If the="My title" isSet>
    <div class="box-header with-border">
      <h3 class="box-title">My title</h3>
    </div>
  </If>
  <div class="box-body">
    <h1>Welcome</h1>
    <p>Some text here...</p>
  </div>
  <If the="{{ footerText }}" isSet>
    <div class="box-footer">
      {{ footerText }}
    </div>
  </If>
</div>

If the following view model is defined:

[
  'footerText' => 'Some footer text...'
]

When rendered, the template will generate the following HTML markup:

<div class="form box box-info">
  <div class="box-header with-border">
    <h3 class="box-title">My title</h3>
  </div>
  <div class="box-body">
    <h1>Welcome</h1>
    <p>Some text here...</p>
  </div>
  <div class="box-footer">
    Some footer text...
  </div>
</div>

More documentation

This was just a very short introduction to the Matisse template engine. Matisse provides many more advanced features for you to use on your templates.

Matisse is already quite functional and it's being used right now on several projects at our company.

We are sorry for the current lack of documentation. We are working on it, but we are also continually improving, not only Matisse, but also the containing ecosystem comprised by the Selene framework and its modules.

If you are interested on knowing more about Matisse, check this Readme from time to time to see if there are any news.

License

The Selene Framework is open-source software licensed under the MIT license.

Selene Framework - Copyright © Impactwave, Lda.

selene-framework/matisse 适用场景与选型建议

selene-framework/matisse 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 191 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 04 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 selene-framework/matisse 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-04-25