Download the PHP package smoren/type-tools without Composer
On this page you can find all versions of the php package smoren/type-tools. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download smoren/type-tools
More information about smoren/type-tools
Files in smoren/type-tools
Package type-tools
Short Description Helpers for different operations with PHP data types
License MIT
Informations about the package type-tools
PHP Type Tools
Helpers for different operations with PHP data types, variables and containers.
How to install to your project
Quick Reference
Unique Extractor
Method | Description | Code Snippet |
---|---|---|
getString |
Returns unique string of the given variable | UniqueExtractor::getString($var, $strict) |
getHash |
Returns unique md5 hash string of the given variable | UniqueExtractor::getHash($var, $strict) |
Object Type Caster
Method | Description | Code Snippet |
---|---|---|
cast |
Cast object to another relative type | ObjectTypeCaster::cast($sourceObject, $destinationClass) |
Object Access
Method | Description | Code Snippet |
---|---|---|
getPropertyValue |
Returns value of the object property | ObjectAccess::getPropertyValue($object, $propertyName) |
setPropertyValue |
Sets value of the object property | ObjectAccess::setPropertyValue($object, $propertyName, $value) |
hasReadableProperty |
Returns true if object has readable property by name or by getter | ObjectAccess::hasReadableProperty($object, $propertyName) |
hasWritableProperty |
Returns true if object has writable property by name or by getter | ObjectAccess::hasWritableProperty($object, $propertyName) |
hasPublicProperty |
Returns true if object has public property | ObjectAccess::hasPublicProperty($object, $propertyName) |
hasPublicMethod |
Returns true if object has public method | ObjectAccess::hasPublicMethod($object, $methodName) |
hasProperty |
Returns true if object has property | ObjectAccess::hasProperty($object, $propertyName) |
hasMethod |
Returns true if object has method | ObjectAccess::hasMethod($object, $methodName) |
Map Access
Method | Description | Code Snippet |
---|---|---|
get |
Returns value from the container by key | MapAccess::get($container, $key, $defaultValue) |
set |
Sets value to the container by key | MapAccess::set($container, $key, $value) |
exists |
Returns true if accessible key exists in the container | MapAccess::exists($container, $key) |
Usage
Unique Extractor
Tool for extracting unique IDs and hashes of any PHP variables and data structures.
Works in two modes: strict and non-strict.
In strict mode:
- scalars: unique strictly by type;
- objects: unique by instance;
- arrays: unique by serialized value;
- resources: result is unique by instance.
In non-strict mode:
- scalars: unique by value;
- objects: unique by serialized value;
- arrays: unique by serialized value;
- resources: result is unique by instance.
Get String
Returns unique string of the given variable.
Get Hash
Returns unique md5 hash string of the given variable.
Object Type Caster
Tool for casting types of objects.
Cast
Cast object to another relative type (upcast or downcast).
Object Access
Tool for reflecting and accessing object properties and methods.
Get Property Value
Returns value of the object property.
Can access property by its name or by getter.
Throws Smoren\TypeTools\Exceptions\KeyError
if property is not accessible to read.
Set Property Value
Sets value of the object property.
Can access property by its name or by setter.
Throws Smoren\TypeTools\Exceptions\KeyError
if property is not accessible to write.
Has Readable Property
Returns true if object has property that is readable by name or by getter.
Has Writable Property
Returns true if object has property that is writable by name or by setter.
Has Public Property
Returns true if object has public property.
Has Public Method
Returns true if object has public method.
Has Property
Returns true if object has property.
Has Method
Returns true if object has method.
Map Access
Tool for map-like accessing of different containers by string keys.
Can access:
- properties of objects (by name or by getter);
- elements of arrays and ArrayAccess objects (by key).
Get
Returns value from the container by key or default value if key does not exist or not accessible.
Throws Smoren\TypeTools\Exceptions\KeyError
if key is not accessible to read.
Set
Sets value to the container by key.
Throws Smoren\TypeTools\Exceptions\KeyError
if key is not accessible to write.
Exists
Returns true if accessible key exists in the container.
Unit testing
License
PHP Type Tools is licensed under the MIT License.