vpg / titon.utility
The Titon utility package provides convenience classes for basic tasks like validation, formatting, sanitization and more.
Installs: 8 466
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 9
Forks: 0
Open Issues: 0
Requires
- php: >=5.3.0
- ext-mbstring: *
Requires (Dev)
- ext-fileinfo: *
- ext-mcrypt: *
- ext-simplexml: *
Suggests
- ext-fileinfo: Validate file mime types with the Validate class
- ext-mcrypt: Encrypt and decrypt data with the Crypt class
- ext-simplexml: Convert XML to other file types with the Converter class
Replaces
This package is not auto-updated.
Last update: 2024-10-26 18:06:23 UTC
README
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'); // FOO
Amongst 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, serialized
Crypt
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-7890
Hash
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'); // FooBar
Number
applies calculations or evaluations on numbers.
Titon\Utility\Number::bytesTo(1024); // 1KB
Path
resolves file paths, namespaces, and class names.
Titon\Utility\Path::className('Vendor\Foo\Bar'); // Bar
Sanitize
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.
Features
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
Requirements
- PHP 5.3.0
- Multibyte
- SimpleXML (for Converter)
- Mcrypt (for Crypt)
- Fileinfo (for Validate)