php-serialization/serializer

Abstract over serializer implementations.

v0.3.0 2022-06-15 08:43 UTC

This package is not auto-updated.

Last update: 2024-11-28 18:04:35 UTC


README

static analysis Software License Total Downloads

Each implementation must implement the PhpSerializer\Serializer\SerializeObject and PhpSerializer\Serializer\UnserializeObject interfaces or PhpSerializer\Serializer\Serializer that already implement them.

Usage is quite simple.

SerializeObject example:

<?php

use PhpSerializer\Serializer\SerializeObject;

public function method(SerializeObject $serializeObject): void
{
    $a = $serializeObject->serialize(new A(name: 'Test')); // O:1:"A":1:{s:4:"name";s:4:"Test";}
}

UnserializeObject example:

<?php

use PhpSerializer\Serializer\UnserializeObject;

public function method(UnserializeObject $unserializeObject): void
{
    $a = $unserializeObject->unserialize(A::class, ['name' => 'Test']);

    assert($a instanceof A);
}