sugatasei / bredala-data
PHP modeling and data manipulation class
Installs: 9
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/sugatasei/bredala-data
Requires
- php: >=8.1.0
- ext-json: *
README
PHP modeling and data manipulation tools.
Data
Data is designed to be extends to help create entities, models, ...
Data implements JsonSerializable for all public non static properties.
MicroCache
Micro-caching tools. Store data only during the script execution.
use Bredala\Data\MicroCache; if (null === ($foo = MicroCache::get('foo'))) { $foo = 'bar'; MicroCache::set('foo', $foo); }
Special use : the value can be null
use Bredala\Data\MicroCache; if (null === ($nullable = MicroCache::get('nullable')) && !MicroCache::has('nullable')) { $nullable = null; MicroCache::set('nullable', $nullable); }
ArrayHelper
Extract part of array
Creates an array from another array keeping only certain keys.
use Bredala\Data\ArrayHelper; $arry = ArrayHelper::extract([ 'id' => 1, 'name' => 'John Doe', 'city' => 'London' ], ['id', 'name']);
Extract part of array
Creates an array from another array keeping only certain keys.
use Bredala\Data\ArrayHelper; $ary = ArrayHelper::extract([ 'id' => 1, 'name' => 'John Doe', 'city' => 'London' ], ['id', 'name']);
Rename keys
Rename a keys from an array
use Bredala\Data\ArrayHelper; $ary = ArrayHelper::renameKeys([ 'id' => 1, 'name' => 'John Doe', 'city' => 'London' ], [ 'id' => 'user_id' ]);
Add prefix to keys
use Bredala\Data\ArrayHelper; $ary = ArrayHelper::addPrefix([ 'id' => 1, 'name' => 'John Doe', 'city' => 'London' ], 'user_');
Remove prefix to keys
use Bredala\Data\ArrayHelper; $ary = ArrayHelper::removePrefix([ 'user_id' => 1, 'user_name' => 'John Doe', 'user_city' => 'London' ], 'user_');
Encoder/Decoder
Encoders helps to transform PHP data to storage type. Decoders helps to tranform data from storage to PHP type.
Encoders & Decoders are usefull inside adapters.
BooleanEncoderEncode/Decode 0-1 integer to/from PHP booleanDataEncoderEncode/Decode array to/fromDataobjectDataListEncoder: Encode/Decode array of array to/from array ofDataobjectsDateTimeEncoder: Encode/Decode date with string representation to/from PHP DateTime objectsJsonEncoderTimestampEncoder: Encode/Decode date with string representation to/from PHP Unix Timestamp