Bryan Crowe caa55f7015 Fix coding standards 11 years ago
..
Exception 95aa41f278 Utility\Error -> Utility\Exception 11 years ago
Hash.php 72a892af36 Use new style arrays and add a helper method. 11 years ago
Inflector.php f8ba7da2d8 Change default replacement for Inflector::slug(). 11 years ago
MergeVariablesTrait.php d52ae87485 Fix license docblocks for phpdoc format 12 years ago
README.md 54a87e06ba fix code + link on Utility/Readme.md 11 years ago
Security.php e45abe3449 Fix CS errors and use correct exceptions 11 years ago
String.php caa55f7015 Fix coding standards 11 years ago
Xml.php 651f396b12 Working on removing the dependency from Core in Utility 11 years ago
composer.json 9869e50ec7 Adding a Readme and a composer.json for the Utility namespace 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

String

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

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

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

// Returns
This is the song
that never ends.

Check the official String 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 = array(
    'post' => array(
        'id' => 1,
        'title' => 'Best post',
        'body' => ' ... '
    )
);
$xml = Xml::build($data);

Check the official Xml class documentation