ADmad 44e8cd69de Code cleanup courtesy scrutinizer-ci. 10 years ago
..
Crypto 615707e57f Use mb_* throughout crypto classes. 11 years ago
Exception be845a3a01 Run phpcbf for PSR2 CS fixers 11 years ago
Hash.php 44e8cd69de Code cleanup courtesy scrutinizer-ci. 10 years ago
Inflector.php 934ad43915 Port changes from #6723 to 3.0 10 years ago
MergeVariablesTrait.php dee3130a4b fix psr2 cs 11 years ago
README.md ef3d792b25 Update README.md 11 years ago
Security.php 5c4d1d788b Merge pull request #6141 from cakephp/josegonzalez-patch-2 11 years ago
Text.php 1e2d1b8dc5 Fix multibyte issues in Text::tokenize() 10 years ago
Xml.php 44e8cd69de Code cleanup courtesy scrutinizer-ci. 10 years ago
bootstrap.php 3b600d7197 Avoid side effects in Inflector.php 11 years ago
composer.json 4a0955dbcc Convert indentation to spaces for composer.json files 11 years ago

README.md

CakePHP Utility Classes

This library provides a range of utility classes that are used throughout the CakePHP framework

What's in the toolbox?

Hash

A Hash (as in PHP arrays) class, capable of extracting data using an intuitive 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']

Check the official Hash class documentation

Inflector

The Inflector class takes a string and can manipulate it to handle word variations such as pluralizations or camelizing.

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

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

Check the official Inflector class documentation

Text

The Text class includes convenience methods for creating and manipulating strings.

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.

Check the official Text class documentation

Security

The security library handles basic security measures such as providing methods for hashing and encrypting data.

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

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

Check the official Security class documentation

Xml

The Xml class allows you to easily transform arrays into SimpleXMLElement or DOMDocument objects and back into arrays again

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

Check the official Xml class documentation