Stud.IP
6.0
|
Static Public Member Functions | |
static | build ($data, $expected_class=null) |
static | buildMany ($array, $expected_class=null) |
static | isSerializedObject ($variable) |
static | export ($object) |
static | exportAsJson ($object) |
Data Fields | |
const | OBJECT_IDENTIFIER = '__SERIALIZED_CLASS__' |
Object builder class
This class can be used to serialize/unserialize objects without using PHP's native functions. This should be used in contexts where the serialized data is exposed to the user.
PHP's native implementation has proven to be rather insecure in the past and since json_encode() cannot handle objects, we need a less complex solution that has less magic going on in the background.
Like unserialize, the magic methods __sleep() and __wakeup() are supported. Accordingly, objects are created without invoking the constructor.
|
static |
Restores an object that has previously been converted to an array. Like unserialize, an expected class may be passed and the method will throw an exception when the created object is not of that or a derived type.
Object data may either be passed as an array or as a json encoded string which will be decoded prior to object creation.
mixed | $data | Associative array or json encoded string |
mixed | $expected_class | Expected class name of objects (optional) |
InvalidArgumentException | when either the data contains no object |
UnexpectedValueException | when the object is not of the expected type |
|
static |
Restores a collection of objects that have previously been converted to a arrays. This essentially iterates over the passed array and invokes build() on each item.
array | $array | Associative array or json encoded string |
mixed | $expected_class | Expected class name of objects (optional) |
InvalidArgumentException | when either the data contains no objects or an object is not of the expected type |
|
static |
Returns all properties (public, protected and private) from given object as associative array as well as the information about the class itself. Be aware that values will only be returned if they differ from the default value. This should ensure a small footprint.
mixed | $object | Arbitrary object |
InvalidArgumentException | when given object is actually not an object |
|
static |
Returns the exported object as a JSON encoded string. This is just a convenience method that saves you from wrapping the call to export() in json_encode() every single time.
mixed | $object | Arbitrary object |
InvalidArgumentException | when given object is actually not an object |
|
static |
Checks whether the passed variable contains an object. A variable must be an array and must contain the magic string constant as an array index to be considered an object.
mixed | $variable | Variable to check |
const OBJECT_IDENTIFIER = '__SERIALIZED_CLASS__' |