The Titon utility package provides lightweight static classes for common tasks. All utilities extend a powerful macro system which permits the addition of new static methods at runtime.
use Titon\Utility\Inflector;
Inflector::macro('upperCase', function($value) {
return strtoupper($value);
});
Inflector::upperCase('foo'); // FOOAmongst the robust macro system, we can easily execute other functionality, for example.
The Converter converts one type of data to another.
Titon\Utility\Converter::toArray($xml); // Supports arrays, objects, JSON, XML, serializedCrypt encrypts and decrypts data through the mcrypt extension.
Titon\Utility\Crypt::blowfish('foobar', $salt);Format formats strings into common patterns.
Titon\Utility\Format::phone('1234567890', '(###) ###-####'); // (123) 456-7890Hash mutates or accesses data in arrays.
Titon\Utility\Hash::set($array, 'foo.bar', 'baz');Inflector rewrites strings to specific forms.
Titon\Utility\Inflector::camelCase('foo bar'); // FooBarNumber applies calculations or evaluations on numbers.
Titon\Utility\Number::bytesTo(1024); // 1KBPath resolves file paths, namespaces, and class names.
Titon\Utility\Path::className('Vendor\Foo\Bar'); // BarSanitize cleans and filters data.
Titon\Utility\Sanitize::html($data);String modifies and analyzes strings.
Titon\Utility\String::truncate($string);Time evaluates and compares dates and times.
Titon\Utility\Time::isTomorrow($time);Validate validates data with defined rules and patterns.
Can be used in combination with the Validator, which provides an object oriented approach to data validation.
Titon\Utility\Validate::ext($path, ['gif', 'png', 'jpg']);Most of the functionality found in the static classes can also be found in global functions. The list of all functions can be found in the bootstrap file within the source folder.
Converter- Convert one type to anotherCrypt- Data encryption and decryptionFormat- Data formattingHash- Object and array manipulationInflector- String and grammar formattingNumber- Number manipulationPath- File system and namespace path formattingSanitize- Data cleaning and escapingString- String manipulationTime- Date and time manipulationValidate- Data validation and filteringValidator- Schema Rule Validation
- PHP 5.3.0
- Multibyte
- SimpleXML (for Converter)
- Mcrypt (for Crypt)
- Fileinfo (for Validate)
