yuanqing/interpolate 问题修复 & 功能扩展

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

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

yuanqing/interpolate

最新稳定版本:v1.2.1

Composer 安装命令:

composer require yuanqing/interpolate

包简介

Simple string interpolation in PHP.

README 文档

README

A small PHP package for interpolating values from an array into a template string.

Think of it as a lightweight alternative to Mustache:

use yuanqing\Interpolate\Interpolate;

$i = new Interpolate;
$tmpl = '{{ foo.bar }}, {{ foo.baz }}!';
$data = array(
  'foo' => array(
    'bar' => 'Hello',
    'baz' => 'World'
  )
);
$i->render($tmpl, $data); #=> 'Hello, World!'

Usage

  1. Tags are enclosed in double braces.

  2. Straight-up substitution; there are no conditional blocks, sections and so forth.

  3. Tags can reference nested values in the multidimensional array (as in the example above).

  4. A value to be interpolated can be a scalar, an object that implements __toString(), or a callback that returns a string:

    $i = new Interpolate;
    $tmpl = '{{ baz }}';
    $data = array(
      'foo' => 'Hello',
      'bar' => 'World',
      'baz' => function($data) {
        return sprintf('%s, %s!', $data['foo'], $data['bar']);
      }
    );
    $i->render($tmpl, $data); #=> 'Hello, World!'

    Note that the first argument of the callback is the $data array.

  5. If a value for a tag is not found, the tag will be replaced with an empty string.

The two examples in this README may be found in the examples.php file.

Requirements

Interpolate.php requires at least PHP 5.3, or HHVM.

Installation

Install with Composer

  1. Install Composer.

  2. Install the Interpolate.php Composer package:

    $ composer require yuanqing/interpolate ~1.2
  3. In your PHP, require the Composer autoloader:

    require_once __DIR__ . '/vendor/autoload.php';

Install manually

  1. Clone this repository:

    $ git clone https://github.com/yuanqing/interpolate

    Or just grab the zip.

  2. In your PHP, require Interpolate.php:

    require_once __DIR__ . '/src/Interpolate.php';

Testing

You need PHPUnit to run the tests:

$ git clone https://github.com/yuanqing/interpolate
$ cd interpolate
$ phpunit

License

MIT license

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-07-10