israelfl/cakephp-ifl-custom-utility

CakePHP 实用类,如 Inflector、String、Hash 和 Security

1.0.2 2017-04-10 07:22 UTC

This package is auto-updated.

Last update: 2024-09-12 22:00:55 UTC


README

Total Downloads License

CakePHP 实用类

这个库提供了一组在 CakePHP 框架中使用的实用类

工具箱里有什么?

Hash

一个 Hash(类似于 PHP 数组)类,能够使用直观的 DSL 提取数据

$things = [
    ['name' => 'Mark', 'age' => 15],
    ['name' => 'Susan', 'age' => 30],
    ['name' => 'Lucy', 'age' => 25]
];

$bigPeople = Hash::extract($things, '{n}[age>21].name');

// $bigPeople will contain ['Susan', 'Lucy']

查看 官方 Hash 类文档

Inflector

Inflector 类接收一个字符串,并可以对其进行操作以处理诸如复数化或驼峰化之类的单词变体。

echo Inflector::pluralize('Apple'); // echoes Apples

echo Inflector::singularize('People'); // echoes Person

查看 官方 Inflector 类文档

Text

Text 类包括创建和操作字符串的便捷方法。

Text::insert(
    'My name is :name and I am :age years old.',
    ['name' => 'Bob', 'age' => '65']
);
// Returns: "My name is Bob and I am 65 years old."

$text = 'This is the song that never ends.';
$result = Text::wrap($text, 22);

// Returns
This is the song
that never ends.

查看 官方 Text 类文档

安全

安全库处理基本安全措施,如提供哈希和加密数据的函数。

$key = 'wt1U5MACWJFTXGenFoZoiLwQGrLgdbHA';
$result = Security::encrypt($value, $key);

Security::decrypt($result, $key);

查看 官方 Security 类文档

Xml

Xml 类允许您轻松地将数组转换为 SimpleXMLElement 或 DOMDocument 对象,反之亦然。

$data = [
    'post' => [
        'id' => 1,
        'title' => 'Best post',
        'body' => ' ... '
    ]
];
$xml = Xml::build($data);

查看 官方 Xml 类文档