PHPackages                             kcs/metadata - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. kcs/metadata

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

kcs/metadata
============

Class/Attribute metadata management component

v4.1.3(1y ago)230.2k↓38.9%4MITPHPPHP ^8.1CI failing

Since Feb 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/alekitto/metadata)[ Packagist](https://packagist.org/packages/kcs/metadata)[ GitHub Sponsors](https://github.com/alekitto)[ RSS](/packages/kcs-metadata/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (11)Versions (25)Used By (4)

Metadata management library in PHP
==================================

[](#metadata-management-library-in-php)

[![Tests](https://github.com/alekitto/metadata/workflows/Tests/badge.svg)](https://github.com/alekitto/metadata/workflows/Tests/badge.svg)[![codecov](https://camo.githubusercontent.com/5a30f0b94a7d7be5154b1cc3ee576ccf3ce43943885297337b48f34d7d599d8e/68747470733a2f2f636f6465636f762e696f2f67682f616c656b6974746f2f6d657461646174612f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/alekitto/metadata)

Overview
--------

[](#overview)

This library provides utilities for metadata loading, management and retrieval for PHP classes, methods and properties.

Installation
------------

[](#installation)

Install with composer

```
$ composer require kcs/metadata
```

Usage
-----

[](#usage)

A metadata factory responsible for retrieving metadatas for a given class.
To create a metadata factory you can implement `MetadataFactoryInterface`on your own class or extend the `AbstractMetadataFactory`.

```
use Kcs\Metadata\ClassMetadataInterface;
use Kcs\Metadata\Factory\MetadataFactoryInterface;

class Factory implements MetadataFactoryInterface
{
    public function getMetadataFor($class): ClassMetadataInterface
    {
        ...
    }
}
```

```
use Kcs\Metadata\ClassMetadataInterface;
use Kcs\Metadata\Factory\AbstractMetadataFactory;

class Factory extends AbstractMetadataFactory
{
    protected function createMetadata(\ReflectionClass $class): ClassMetadataInterface
    {
        return new MyClassMetadata($class);
    }
}
```

This allows you to specify which implementation of `ClassMetadataInterface`will be used for your metadata simply extending the `createMetadata` method.

If you extend the `AbstractMetadataFactory` class (or use `MetadataFactory` class which creates a `ClassMetadata` instance for class metadatas), you have to create your metadata loader class implementing `LoaderInterface`.

```
use Kcs\Metadata\Loader\LoaderInterface;

class Loader implements LoaderInterface
{
    public function loadClassMetadata(ClassMetadataInterface $classMetadata)
    {
        ...
    }
}
```

If more than one source is available for your metadata (Annotations, YAMLs, XMLs, etc.) you can use the `ChainLoader` class, adding your loaders to it.

Validation
----------

[](#validation)

When a metadata is loaded the factory `validate` method is called with the newly loaded metadata as argument and the `Kcs\Metadata\Event\ClassMetadataLoadedEvent` event is dispatched (if an event dispatcher is present).
You can extend `validate` or listen for the metadata loaded event and check for metadata validity. If a validation error occurs you have to throw an `InvalidMetadataException`.

Metadata classes
----------------

[](#metadata-classes)

You can extend the provided classes `ClassMetadata`, `MethodMetadata` and `PropertyMetadata`to build your metadata information.
By default, all the public properties are serialized in cache (if cache is present). You can customize this behaviour by extending the `__sleep` method of the metadata classes, returning an array of serialized properties.

License
-------

[](#license)

This library is released under the MIT license

Contributions
-------------

[](#contributions)

Contributions are always welcome. Feel free to open an issue or submit a PR to improve this library.

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance43

Moderate activity, may be stable

Popularity30

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

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

Recently: every ~330 days

Total

24

Last Release

448d ago

Major Versions

v1.5.0 → v2.0.02017-11-01

v2.1.1 → v3.0.02019-06-16

v3.2.0 → v4.0.02020-12-19

PHP version history (7 changes)v1.0PHP &gt;= 5.4.0

v2.0.0PHP &gt;=7.1

v2.1.0PHP ^7.1

v3.0.0PHP ^7.3

v4.0.0PHP ^7.4|^8.0

v4.1.0PHP ^8.0

v4.1.3PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/73dd7f3bebd03ec946b6b12359141ea461b770c3671acac4e8004e3c2d78e78f?d=identicon)[alekitto](/maintainers/alekitto)

---

Top Contributors

[![alekitto](https://avatars.githubusercontent.com/u/1257206?v=4)](https://github.com/alekitto "alekitto (72 commits)")

---

Tags

annotationsmetadataphpxmlyamlannotationsmetadata

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kcs-metadata/health.svg)

```
[![Health](https://phpackages.com/badges/kcs-metadata/health.svg)](https://phpackages.com/packages/kcs-metadata)
```

###  Alternatives

[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[thunderer/serializard

Flexible serializer

2767.3k1](/packages/thunderer-serializard)

PHPackages © 2026

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