alternatex/widespread

常用的工具组合在一起

2.1.4 2013-04-03 17:38 UTC

This package is not auto-updated.

Last update: 2024-09-28 14:02:34 UTC


README

常用的工具组合在一起

先决条件

PHP 5.3

安装

通过composer安装 composer require 'alternatex/widespread:*'

见: https://packagist.org.cn/packages/alternatex/widespread

通用

通过composer自动加载器加载依赖

<?php
// ...
require_once('vendor/autoload.php');

// ...
use Widespread\Widespread as Widespread;

?>

用例:预处理器

... see sledgehammer *

元数据提取

从文件头部提取元数据(默认为前4096字节)

<?php 

// ...
$data = Widespread::FetchMetadata(

  // path to entity
  'test/examples/members/', 

  // properties to extract
  array('UUID', 'Name', 'Repository', 'Version', 'Sort', 'Status'),

  // sort by field
  'Sort', 

  // sort ascending
  false,

  // filters to apply
  array(

    // published only
    'Status' => array(
      array('NOT', 'Published')
    ),

    // restrict by name
    'Name' => array(
      array('IN', array('Include_1', 'Include_2')),
      array('EX', array('Exclude_1'))
    ),  

    // restrict by age
    'Sort'  => array(
      array('LT', 1000), 
      array('GT', 200)
    )
  )
);

?>

模板化

收集模板和部分,并合并数据

<?php 

// ...
foreach(array('buckets', 'options', 'widgets') as $context) $$context = array(); // $buckets = $options = $widgets = array();

// fetch partials
Widespread::FetchPartials(
  $buckets, 
  $options, 
  $widgets, 
  'index.html', 
  '{{>/templates/body}}'
);

// create mustache rendering engine helper
$m = new \Mustache_Engine(array('partials' => $buckets));

// process
print $m->render($buckets['index.html'], $data);
?>

方便

收集模板和部分,并合并数据

<?php 

// ...
$data = array(
  '...',
  '...',
  '...'
);

// default access
$segment_a = &Widespread::AccessSegment($data, 'path.to.prop.where.ever');

// custom delimiter
$segment_b = &Widespread::AccessSegment($data, 'path/to/prop/where/ever', null, null, null, '/');

// ...
$segment_a = 'test';

// ...
echo $data['path']->to['prop']['where']->ever;

// ...
$segment_b = 'test2';

// ...
echo $data['path']->to['prop']['where']->ever;

?>

许可证

在两个许可证下发布:新BSD和MIT。您可以选择最适合您开发需求的许可证。

https://github.com/alternatex/widespread/blob/master/LICENSE