PHPackages                             vox/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. vox/metadata

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

vox/metadata
============

1.0.2(4y ago)0103↓85.7%2MITPHPPHP &gt;=7.4CI failing

Since Apr 2Pushed 4y ago1 watchersCompare

[ Source](https://github.com/jhonatanTeixeira/metadata)[ Packagist](https://packagist.org/packages/vox/metadata)[ RSS](/packages/vox-metadata/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (6)Dependencies (7)Versions (13)Used By (2)

PHP Metadata Reader
===================

[](#php-metadata-reader)

Easily read php classes metadata using doctrine annotations, php 8 attributes or yaml files. All metadata can be cached using any psr cache solution or doctrine cache, this library is also capable of reading data from proxies created by ocramius proxy manager.

Reads types from typehints (also from php 7.4 properties), docblocks (using @var), return types (typehints and dockblocks) from:

- Classes
- Child classes
- Properties
- Methods
- Method Properties

This lib is also circular dependency safe.

Usage
-----

[](#usage)

To read the metadata you need a MetadataFactory instance, you can create it manualy or using the convenient factory methods

### Create a metadata factory instance

[](#create-a-metadata-factory-instance)

there are two metadata factory factory methods, one for annotations based and another yaml based

#### Create annotations metadatada factory:

[](#create-annotations-metadatada-factory)

```
$factory = (new MetadataFactoryFactory(debug: false))->createAnnotationMetadataFactory();
```

the constructor may receive one optional parameter, to set debug on or off

#### Create yaml metadata factory:

[](#create-yaml-metadata-factory)

```
$factory = (new MetadataFactoryFactory(debug: true))->createYmlMetadataFactory(__DIR__ . '/../metadata');
```

#### Factory method interface

[](#factory-method-interface)

There are several options on these factory methods, read its documentation to understand them

```
/**
 * @param string $metadataClassName the fqcn to be used as class metadata holder, must implement the interface
 * @param Reader|null $reader the desired annotation reader, a custom one can be derived from the doctrine interface
 * @param string $methodMetadataClassName the fqcn to be used as method metadata holder, must implement the interface
 * @param string $propertyMetadataClassName the fqcn to be used as property metadata holder, must implement the interface
 *
 * @return MetadataFactory
 */
public function createAnnotationMetadataFactory(
    string $metadataClassName = ClassMetadata::class,
    Reader $reader = null,
    string $methodMetadataClassName = MethodMetadata::class,
    string $propertyMetadataClassName = PropertyMetadata::class
);

/**
 * @param string $metadataPath the path for the folder containing the metadata yaml files
 * @param string $metadataClassName the fqcn to be used as class metadata holder, must implement the interface
 * @param string $methodMetadataClassName the fqcn to be used as method metadata holder, must implement the interface
 * @param string $propertyMetadataClassName the fqcn to be used as property metadata holder, must implement the interface
 * @param string $yamlExtension the desired extension for the yaml files
 *
 * @return MetadataFactory
 */
public function createYmlMetadataFactory(
    string $metadataPath,
    string $metadataClassName = ClassMetadata::class,
    string $methodMetadataClassName = MethodMetadata::class,
    string $propertyMetadataClassName = PropertyMetadata::class,
    string $yamlExtension = 'yaml'
);
```

#### Adding cache for optimization

[](#adding-cache-for-optimization)

This library uses jms/metadata implementation to store its metadata, that means that the metadata is fully serializable and cacheable you can create your own cache implementation of Metadata\\Cache\\CacheInterface however, this package bundles a psr-16 simple cache adapter, see the example:

```
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Psr16Cache;
use Vox\Metadata\Cache\PsrSimpleCacheAdapter;

$factory = (new MetadataFactoryFactory(true))->createAnnotationMetadataFactory();

$factory->setCache(new PsrSimpleCacheAdapter(new Psr16Cache(new FileSystemAdapter())));
```

#### Creating your own annotations

[](#creating-your-own-annotations)

There are 2 types of annotations you can use, doctrine's or php 8 attributes, look at an example compatible with both in case you want to suport php 7.4 and 8

```
/**
 * @Annotation
 * @NamedArgumentConstructor
 * @Target({"CLASS", "METHOD", "PROPERTY"})
 */
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::TARGET_PROPERTY)]
class TestAnnotation
{
    /**
     * @var string
     */
    public string $name = 'default';

    public function __construct($name = 'default')
    {
        $this->name = $name;
    }
}
```

#### Reading the metadata

[](#reading-the-metadata)

Annotating the class:

```
/**
 * @Controller()
 */
class SomeAnnotatedClass {
    private SomeService $service;

    /**
     * @var SomeType
     */
    private $someType;

    #[Get('/{id}')]
    public function getData(int $id) {}
}
```

Reading the class

```
$factory = (new MetadataFactoryFactory(true))->createAnnotationMetadataFactory();

$metadata = $factory->getMetadataForClass(SomeAnnotatedClass::class);

$metadata->name; // MyNamespace\\SomeAnnotatedClass
$metadata->getAnnotations(); // [ MyNamespace\\Controller ]
$metadata->getAnnotation(Controller::class); // MyNamespace\\Controller
$metadata->propertyMetadata['service']->type; // MyNamespace\\SomeService
$metadata->propertyMetadata['someType']->type; // MyNamespace\\SomeType
$metadata->methodMetadata['getData']->getAnnotations(); // [ MyNamespace\\Get ]
$metadata->methodMetadata['getData']->params[0]->type; // int
```

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 52.2% 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 ~119 days

Recently: every ~65 days

Total

12

Last Release

1695d ago

Major Versions

0.6.6 → 1.0.02021-10-12

PHP version history (2 changes)0.5.4PHP &gt;=7.0

0.6.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/2b151b09844eedb0fc2a4a3f5ff6766ec85d3bd1f3c5553e0c117ee279ede952?d=identicon)[jhonatanTeixeira](/maintainers/jhonatanTeixeira)

---

Top Contributors

[![Guararapes](https://avatars.githubusercontent.com/u/60523424?v=4)](https://github.com/Guararapes "Guararapes (12 commits)")[![jhonatanTeixeira](https://avatars.githubusercontent.com/u/1003279?v=4)](https://github.com/jhonatanTeixeira "jhonatanTeixeira (11 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.4k1.5M3](/packages/shopware-platform)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k12](/packages/tempest-framework)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.4M534](/packages/shopware-core)[akeneo/pim-community-dev

Akeneo PIM, the future of catalog management is open!

1.0k624.1k86](/packages/akeneo-pim-community-dev)[oro/platform

Business Application Platform (BAP)

642140.7k110](/packages/oro-platform)[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

103519.9k45](/packages/friendsoftypo3-content-blocks)

PHPackages © 2026

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