PHPackages                             harp-orm/serializer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. harp-orm/serializer

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

harp-orm/serializer
===================

Serialize object properties

0.1.1(11y ago)21.0k2BSD-3-ClausePHP

Since Jun 21Pushed 11y ago2 watchersCompare

[ Source](https://github.com/harp-orm/serializer)[ Packagist](https://packagist.org/packages/harp-orm/serializer)[ RSS](/packages/harp-orm-serializer/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (2)DependenciesVersions (3)Used By (2)

Serializer
==========

[](#serializer)

[![Build Status](https://camo.githubusercontent.com/0d529f7ba3a34c07262ecfb48dac99922ce9d5c718846986ad88784c36282b0f/68747470733a2f2f7472617669732d63692e6f72672f686172702d6f726d2f73657269616c697a65722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/harp-orm/serializer)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/b7b6c4eef7f7bb351f1741a74718cedeff1d3c24394e7f4aa7e5e3d27035ef0b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f686172702d6f726d2f73657269616c697a65722f6261646765732f7175616c6974792d73636f72652e706e67)](https://scrutinizer-ci.com/g/harp-orm/serializer/)[![Code Coverage](https://camo.githubusercontent.com/9e0770b8c228138f6ed4cee030413c65605c49b4ec560edc193f5e5b6eae2c90/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f686172702d6f726d2f73657269616c697a65722f6261646765732f636f7665726167652e706e67)](https://scrutinizer-ci.com/g/harp-orm/serializer/)[![Latest Stable Version](https://camo.githubusercontent.com/24a469cd5322c8637e6d6cc37fa4ddb4c8b9f436ffdf69a640cd82020b8d2f8e/68747470733a2f2f706f7365722e707567782e6f72672f686172702d6f726d2f73657269616c697a65722f762f737461626c652e706e67)](https://packagist.org/packages/harp-orm/serializer)

Serialize object/array properties, using different rules for each property.

Usage
-----

[](#usage)

```
use Harp\Serializer;

$serializers = new Serializer\Serializers([
    new Serializer\Native('nativeSerializerdArray'),
    new Serializer\Csv('csvString'),
    new Serializer\Json('jsonProperty'),
]);

$obj = new stdClass();

$obj->nativeSerializerdArray = array('test' => 'param');
$obj->csvString = array('val', 'val2');
$obj->jsonProperty = array('test' => 'asd');

$serializers->serialize($obj);

// Will output:
// stdClass Object
// (
//     [nativeSerializerdArray] => a:1:{s:4:"test";s:5:"param";}
//     [csvString] => val,val2
//     [jsonProperty] => {"test":"asd"}
// )
print_r($obj);

// Will unserialize all the relevant properties
$serializers->unserialize($obj);
```

Object Serialization
--------------------

[](#object-serialization)

If you have an object that implements Serializable, but does not use the native php serialization you can use Object Serializer, greatly reducing the object's string footprint.

```
use Serializable;

class SimpleObject implements Serializable
{
    public $prop1;
    public $prop2;

    public function serialize()
    {
        return $this->prop1.','.$this->prop2;
    }

    public function unserialize($data)
    {
        list($this->prop1, $this->prop2) = explode(',', $data);
    }
}

$serializers = new Serializer\Serializers([
    new Serializer\Object('test', 'SimpleObject'),
]);

$obj = new stdClass();
$obj->test = new SimpleObject();
$obj->test->prop1 = 10;
$obj->test->prop2 = 20;

$serializers->serialize($obj);

// Will output:
// stdClass Object
// (
//     [test] => 10,20
// )
print_r($obj);

// Will unserialize all the relevant properties
$serializers->unserialize($obj);
```

Harp ORM Integration
--------------------

[](#harp-orm-integration)

Serializer is integrated into Harp ORM and gives you the ability to store arbitrary data in your database, by serializing the model's properties.

For example holding an api response in a "response" field.

```
// Model
class Payment extends AbstractModel
{
    public $id;
    public $response;
}

// Repo
class Payment extends AbstractRepo
{
    public function initialize()
    {
        $this
            ->addSerializers([
                new Serializer\Json('response'),
            ]);
    }
}

$model = new Model\Payment(['response' => $someArray]);

// The response property will get serialized as a json string.
Repo\Payment::get()->save($model);
```

SerializersTrait
----------------

[](#serializerstrait)

This trait gives you the ability to easily add serializers to another object.

```
class TestConfig {
    use SerializersTrait;
}

$config = new TestConfig();

$config
    ->serializeCsv('name');

// Return the Asserts object
$config->getSerializers();
```

Here are all the methods added by this trait.

MethodDescription**getSerializers**()Get the Serializers object**addSerializer**(AbstractSerializer)Add arbitrary serializer**serializeCsv**($name)Add an Csv serializer**serializeJson**($name)Add an Json serializer**serializeNative**($name)Add an Native serializer**serializeObject**($name, $class)Add an Object serializerLicense
-------

[](#license)

Copyright (c) 2014, Clippings Ltd. Developed by Ivan Kerin

Under BSD-3-Clause license, read LICENSE file.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~25 days

Total

2

Last Release

4321d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/506129?v=4)[Harry Dobrev](/maintainers/hkdobrev)[@hkdobrev](https://github.com/hkdobrev)

---

Top Contributors

[![ivank](https://avatars.githubusercontent.com/u/4976?v=4)](https://github.com/ivank "ivank (15 commits)")

### Embed Badge

![Health badge](/badges/harp-orm-serializer/health.svg)

```
[![Health](https://phpackages.com/badges/harp-orm-serializer/health.svg)](https://phpackages.com/packages/harp-orm-serializer)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
