prologue/支持

Prologue 支持是 Illuminate 支持的扩展

v1.1.1 2015-02-07 14:40 UTC

This package is auto-updated.

Last update: 2024-08-29 00:05:19 UTC


README

Latest Stable Version Total Downloads Build Status

此包现已废弃。不会有进一步的开发或错误修复。

Prologue 支持是 Illuminate 支持的扩展。它为您提供了额外的辅助功能。

Cristian Tabacitu 维护

目录

安装

您可以通过 Composer 为您的项目安装 Prologue 支持包。

在您的 composer.json 中要求此包。

"prologue/support": "dev-master"

运行 composer 安装或更新包。

$ composer update

使用

收集

Prologue 支持中的 Collection.php 类附带一些附加功能。

filterBy($key, $value)

用于筛选具有特定键值的记录。

$data = array(
	array('name' => 'foo', 'age' => 21),
	array('name' => 'bar', 'age' => 20),
	array('name' => 'baz', 'age' => 9),
);

$collection = new Prologue\Support\Collection($data);

// Will return only records with an age of 20.
$items = $collection->filterBy('age', 20)->all();

orderBy($key, $direction)

用于按给定键对记录进行排序。

$data = array(
	array('name' => 'foo', 'age' => 21),
	array('name' => 'bar', 'age' => 20),
	array('name' => 'baz', 'age' => 9),
);

$collection = new Prologue\Support\Collection($data);

// Will order the records by its age in ascending order.
$items = $collection->orderBy('age')->all();

您也可以按降序排序。

$items = $collection->orderBy('age', 'desc')->all();

MessageBag

Prologue 支持中的 MessageBag 类提供了将数组或其他 MessageBag 作为消息添加的能力。

$bag = new Prologue\Support\MessageBag;
$bag->add('error', array(
	'email' => 'Incorrect email address',
	'url'   => 'Incorrect url',
));
$messages = $bag->get('error'); 

现在 $messages 等于

array(
	array(
		'email' => 'Incorrect email address',
		'url'   => 'Incorrect url',
	)
);

看?其中一条消息是我们添加的数组。

同样适用于 Illuminate\Support\MessageBag 的实例。

$bag->add('error', new Illuminate\Support\MessageBag);

辅助函数

is_true($value)

确定一个值是否为真。

$result = is_true(true) // true
$result = is_true(null) // false

is_false($value)

确定一个值是否为假。

$result = is_false(false) // true
$result = is_false(null) // false

last_key(array $value)

从数组中获取最后一个键。

$data = array('foo' => 'bar', 'baz' => 'foz');
$result = last_key($data); // 'baz'

变更日志

您可以在这里查看此包的变更日志。

许可

Prologue 支持根据 MIT 许可证 许可。