-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a Readme and a composer.json for the Utility namespace
- Loading branch information
Showing
3 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# 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: | ||
|
||
```php | ||
$things = [ | ||
['name' => 'Mark', 'age' => 15], | ||
['name' => 'Susan', 'age' => 30] | ||
['name' => 'Lucy', 'age' => 25] | ||
]; | ||
|
||
$bigPeople = Hash::extract('{n}[age>21].name', $things); | ||
|
||
// $bigPeople will contain ['Susan', 'Lucy'] | ||
``` | ||
|
||
Check the [official Hash class documentation](http://book.cakephp.org/3.0/en/core-utility-libraries/hash.html) | ||
|
||
### Inflector | ||
|
||
The Inflector class takes a string and can manipulate it to handle word variations | ||
such as pluralizations or camelizing. | ||
|
||
```php | ||
echo Inflector::pluralize('Apple'); // echoes Apples | ||
|
||
echo Inflector::singularize('People'); // echoes Person | ||
``` | ||
|
||
Check the [official Inflector class documentation](http://book.cakephp.org/3.0/en/core-utility-libraries/inflector.html) | ||
|
||
### String | ||
|
||
The String class includes convenience methods for creating and manipulating strings. | ||
|
||
```php | ||
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](http://book.cakephp.org/3.0/en/core-utility-libraries/string.html) | ||
|
||
### Security | ||
|
||
The security library handles basic security measures such as providing methods for hashing and encrypting data. | ||
|
||
```php | ||
$key = 'wt1U5MACWJFTXGenFoZoiLwQGrLgdbHA'; | ||
$result = Security::encrypt($value, $key); | ||
|
||
Security::decrypt($result, $key); | ||
``` | ||
|
||
Check the [official Security class documentation](http://book.cakephp.org/3.0/en/core-utility-libraries/security.html) | ||
|
||
### Xml | ||
|
||
The Xml class allows you to easily transform arrays into SimpleXMLElement or DOMDocument objects | ||
and back into arrays again | ||
|
||
```php | ||
$data = array( | ||
'post' => array( | ||
'id' => 1, | ||
'title' => 'Best post', | ||
'body' => ' ... ' | ||
) | ||
); | ||
$xml = Xml::build($data); | ||
``` | ||
|
||
Check the [official Xml class documentation](http://book.cakephp.org/3.0/en/core-utility-libraries/xml.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "cakephp/utility", | ||
"description": "CakePHP Utility classes such as Inflector, String, Hash, and Security", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "CakePHP Community", | ||
"homepage": "http://cakephp.org" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"Cake\\Utility\\": "." | ||
} | ||
}, | ||
"minimum-stability": "beta" | ||
} |