PHPackages                             themadhenchman/encoder-annotation - 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. themadhenchman/encoder-annotation

ActiveLibrary

themadhenchman/encoder-annotation
=================================

Package that allows the transformation of data-objects into persistant formats based on annotation.

1.0.0(3mo ago)00MITPHP

Since May 6Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/themadhenchman/EncoderAnnotation)[ Packagist](https://packagist.org/packages/themadhenchman/encoder-annotation)[ RSS](/packages/themadhenchman-encoder-annotation/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

Notice
======

[](#notice)

This library is in beta-status; depending on use-cases or problems found some internal implementations may change. Should it affect persisted data, a method for updating the data-format will be provided.

### Purpose

[](#purpose)

The purpose of this module is to allow PHP itself to infer the desired structure for the encoded data. It will move the description of what the output is supposed to be onto the dataobject itself and negates the need to have dedicated encoderlogic.

### Inspiration

[](#inspiration)

This package was inspired by GoLang's JSON-module.

### Extensibility

[](#extensibility)

The logic this package provides is split into two parts communicating over a common data-structure.

Any one of those parts is replaceable by a custom implementation catering to encoding/decoding to/from formats other than the one provided(JSON).

It also allows for custom logic during transformation.

Please see the test provided for some illustration.

### Deployment

[](#deployment)

The implementation for encoding and decoding can be composed freely.

This needs to be done in the code using it and as long the extensibility requirements are honoured there shouldn't be any problems.

Otherwise, please file a bug-report.

Using this package you will want to initialize and use the services provided.

### Example

[](#example)

```
#[DecodeClass(DataObject::class)]
#[EncodeClass(DataObject::class)]
class DataObject
{
    #[EncodeProperty('dataObjectValue')]
    #[DecodeToProperty('dataObjectValue')]
    public int $computedValue;

    public function __construct(int $computedValue = 0)
    {
        $this->computedValue = $computedValue;
    }
}

$instance = new DataObject(44);
```

Upon an instance of this class being put into the services provided the class will be persisted into

```
{
  "dataObjectValue": 44
}
```

Without having to implement further logic.

This also holds true for more complex items. Collections that are not homomorphic (read holding various datatypes, e.g. `[2,'a', new class{}]`) are not supported.

The different objects are composable can can stack. The result must not always be a JSON IF the encoder-logic provided creates e.g. XML. You can also encode one object and decode it to another object. Additionally, properties known on the part-object can also be encoded (annotation must take place on the class level though).

An earlier iteration of this (not released) also provided invocations of method-calls. However, this blurred the line between data and logic and will most likely (unless for a very good reason) not be supported going forward.

Encoding into other formats is also on the table (e.g. currently XML is up there as a candidate for implementation). They are subject to time-constraints, though.

The provided attribute-parameter in the annotation is a going to be used there. For the time being that parameter is provided, but not actively used. Feel free to test out implementations using that parameter(e.g. for XML) and provide feedback/PRs/bug-reports.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance81

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

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 ~334 days

Total

4

Last Release

103d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/db404e42eed52b831190d68f9661274f421b607d48a1a6dc2eefc5f95253c171?d=identicon)[themadhenchman](/maintainers/themadhenchman)

---

Top Contributors

[![themadhenchman](https://avatars.githubusercontent.com/u/132675828?v=4)](https://github.com/themadhenchman "themadhenchman (5 commits)")

---

Tags

encodingdecodingannotationmetaprogramming

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/themadhenchman-encoder-annotation/health.svg)

```
[![Health](https://phpackages.com/badges/themadhenchman-encoder-annotation/health.svg)](https://phpackages.com/packages/themadhenchman-encoder-annotation)
```

###  Alternatives

[zbateson/mb-wrapper

Wrapper for mbstring with fallback to iconv for encoding conversion and string manipulation

4948.6M5](/packages/zbateson-mb-wrapper)[delight-im/base64

Simple and convenient Base64 encoding and decoding for PHP

15158.1k6](/packages/delight-im-base64)[falseclock/advanced-cms

A PHP Library that allows you to decode and manipulate CAdES or in other words CMS Advanced Electronic Signatures described in ETSI standart TS 101 733.

223.2k](/packages/falseclock-advanced-cms)[adapik/cms

A PHP Library that allows you to decode ASN.1 CMS using Basic Encoding Rules (BER).

147.2k1](/packages/adapik-cms)[anisimov/emoji

Allows to detect emoji, remove emoji, encode emoji and decode emoji in string.

103.7k](/packages/anisimov-emoji)

PHPackages © 2026

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