serger / cake-utility
CakePHP 3.x Utility classes such as Inflector, String, and Hash without Cake/Core dependency
Requires
- php: >=8.0
- ext-mbstring: *
Requires (Dev)
- phpunit/phpunit: ^9
- vimeo/psalm: >=5.9.0
Suggests
- ext-ctype: To use Text::parseFileSize()
- ext-dom: To use Xml
- ext-intl: To use Text::transliterate() or Text::slug()
- ext-libxml: To use Xml
- ext-simplexml: To use Xml
- lib-ICU: To use Text::transliterate() or Text::slug()
README
CakePHP Utility Classes
This is the fork of library provides a range of utility classes of CakePHP framework but without framework core dependencies.
Why?
I like CakePHP, a powerful, beautiful and flexible PHP framework. But I can't use it with every project I work :( . So I clone this very handy toolbox, drops out any dependencies to Cake/Core to use this library separately.
Versioning strategy
- 1.x.x — PHP 5.6-7.3, receives code backports as soon as my projects runs on these PHP versions
- 2.x.x — PHP 7.4, receives code and tests backports
- 3.x.x — PHP 8.0 currently in the master branch
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
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