PHPackages                             jasny/meta - 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. jasny/meta

Abandoned → [jasny/phpdoc-parser](/?search=jasny%2Fphpdoc-parser)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

jasny/meta
==========

Define metadata for classes, properties and functions

v3.0.3(9y ago)119.8k↓54.3%32MITPHPPHP &gt;=5.6.0

Since Sep 25Pushed 7y agoCompare

[ Source](https://github.com/jasny/meta)[ Packagist](https://packagist.org/packages/jasny/meta)[ Docs](http://jasny.github.com/meta)[ RSS](/packages/jasny-meta/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (15)Used By (2)

Jasny Meta
==========

[](#jasny-meta)

[![Build Status](https://camo.githubusercontent.com/1fd42a7c76b41daaf6c5a4f6ba49cfaae26a91527614e4fbdc7a86021fc3f000/68747470733a2f2f7472617669732d63692e6f72672f6a61736e792f6d6574612e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/jasny/meta)[![Coverage Status](https://camo.githubusercontent.com/7aeb6c6e51927aaa432936c345310085606bbf76f33bca6c35c33133eb7dfabe/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6a61736e792f6d6574612f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/jasny/meta?branch=master)

The Jasny Meta library allows you to attach metadata to a class and class properties. The metadata is available at runtime and can be used to trigger particular behaviour.

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

[](#installation)

The Jasny Meta package is available on [packagist](https://packagist.org/packages/jasny/meta). Install it using composer:

```
composer require jasny/meta

```

Annotations
-----------

[](#annotations)

Metadata can be specified through annotations. In PHP annotations are written in the docblock and start with `@`. If you're familiar with writing docblocks, you probably recognize them.

Here's an example of obtaining metadata for given class:

```
use Jasny\Meta\Factory;

$factory = new Factory($source, $cache);
$meta = $factory->forClass(FooBar::class);
```

In here:

- `$source` is an implementation of `Jasny\Meta\Source\SourceInterface` - to obtain metadata from class and return it as associative array
- `$cache` is an implementation of `Jasny\Meta\Cache\CacheInterface` - to handle caching meta
- `$meta` returned is an instance of `Jasny\Meta\MetaClass`.

Lets look closely at all of those.

Meta Sources
------------

[](#meta-sources)

Source is an object that actually obtains metadata from class definition. We have three classes of sources defined:

- `Jasny\Meta\Source\PhpdocSource` - for obtaining metadata, defined in doc-comments
- `Jasny\Meta\Source\ReflectionSource` - for obtaining some generic information, using reflection methods
- `Jasny\Meta\Source\CombinedSource` - a class that uses other sources to get meta and to merge it in a single output array

### PhpdocSource

[](#phpdocsource)

Given a class:

```
/**
 * Original FooBar class
 *
 * @package FoosAndBars
 * @author Jimi Hendrix
 */
class FooBar
{
    /**
     * Very first property
     * @var array
     * @required
     */
    public $first;

    /**
     * And some more property
     * @var string|Foo
     * @version 3.4
     * @default 'a_place_for_foo'
     */
    public $secondFoo;

    /**
     * Protected properties are not included in fetched meta
     * @var int
     */
    protected $third;

    /**
     * Privates also are not included
     * @var array
     */
    private $fourth;

    //Methods and constants are not included in meta for now
}
```

We obtain metadata:

```
use Jasny\Meta\Source\PhpdocSource;
use Jasny\ReflectionFactory\ReflectionFactory;
use Jasny\PhpdocParser\PhpdocParser;
use Jasny\PhpdocParser\Set\PhpDocumentor;

$reflectionFactory = new ReflectionFactory();

$tags = PhpDocumentor::tags();
$phpdocParser = new PhpdocParser($tags);

$source = new PhpdocSource($reflectionFactory, $phpdocParser);
$meta = $source->forClass(FooBar::class);

var_export($meta);
```

```
[
    'package' => 'FoosAndBars',
    'author' => [
        'name' => 'Jimi Hendrix',
        'email' => 'jimi-guitars@example.com'
    ],
    '@properties' => [
        'first' => [
            'var' => 'array',
            'required' => true
        ],
        'secondFoo' => [
            'var' => 'string|Foo',
            'version' => '3.4',
            'default' => 'a_place_for_foo'
        ]
    ]
]
```

In here we used two additional dependencies:

- `Jasny\ReflectionFactory\ReflectionFactory` - class for creating reflections, is defined in [Jasny Reflection factory](https://github.com/jasny/reflection-factory)
- `Jasny\PhpdocParser\PhpdocParser` - class for parsing doc-comments, is defined in [Jasny PHPDoc parser](https://github.com/jasny/phpdoc-parser)

### ReflectionSource

[](#reflectionsource)

This class does not take any information from doc-comments, but fetches data using only reflection methods.

Having a class from previous example as input, we obtain metadata:

```
use Jasny\Meta\Source\ReflectionSource;
use Jasny\ReflectionFactory\ReflectionFactory;

$reflectionFactory = new ReflectionFactory();

$source = new ReflectionSource($reflectionFactory);
$meta = $source->forClass(FooBar::class);

var_export($meta);
```

```
[
    'name' => 'Some\\Namespace\\FoosAndBars',
    'title' => 'foos and bars',
    '@properties' => [
        'first' => [
            'name' => 'first',
            'title' => 'first',
            'default' => null
        ],
        'secondFoo' => [
            'name' => 'secondFoo',
            'title' => 'second foo',
            'default' => 'a_place_for_foo'
        ]
    ]
]
```

`$reflectionFactory` dependency is the same as defined in the upper example for `PhpdocSource`.

### CombinedSource

[](#combinedsource)

Here's an example for the same class definition:

```
$sources = [$phpdocSource, $reflectionSource];
$source = new CombinedSource($sources);
$meta = $source->forClass(FooBar::class);

var_export($meta);
```

```
[
    'package' => 'FoosAndBars',
    'author' => [
        'name' => 'Jimi Hendrix',
        'email' => 'jimi-guitars@example.com'
    ],
    'name' => 'Some\\Namespace\\FoosAndBars',
    'title' => 'foos and bars',
    '@properties' => [
        'first' => [
            'var' => 'array',
            'required' => true,
            'name' => 'first',
            'title' => 'first',
            'default' => null
        ],
        'secondFoo' => [
            'var' => 'string|Foo',
            'version' => '3.4',
            'name' => 'secondFoo',
            'title' => 'second foo',
            'default' => 'a_place_for_foo'
        ]
    ]
]
```

As you see, meta, obtained by means of `$phpdocSource` and `$reflectionSource`, was merged into a single array.

Caching
-------

[](#caching)

The second parameter to pass to factory constructor is an instance of `Jasny\Meta\Cache\CacheInterface`. It is used to cache metadata between calls for the same class name.

We have two implementations of cache:

- `Jasny\Meta\Cache\None` - actually does not perform any caching, used to simplify a code for cache usage
- `Jasny\Meta\Cache\Simple` - caching into a process memory (so in array). This cache does not persist among different php processes and lasts till the current process ends.

So if you don't want to cache meta, just use a `$cache = new Jasny\Meta\Cache\None()`.

Meta
----

[](#meta)

Meta returned by factory is an instance of `Jasny\Meta\MetaClass`. It has the following methods to obtain data:

- `get(string $key, $default = null)` - get class meta by key
- `is(string $key): bool` - check if meta key exists and is not empty
- `has(string $key): bool` - check if meta key exists (can be empty)
- `getProperty(string $name): ?MetaProperty` - obtain metadata for given class property. Result is either null, if property does not exists, or an instance of `Jasny\Meta\MetaProperty`
- `getProperties(): array` - get metadata for all class properties as array of `Jasny\Meta\MetaProperty` objects

`MetaProperty` class implements the first three methods of those (so `get`, `is` and `has`).

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 52.8% 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 ~56 days

Recently: every ~20 days

Total

13

Last Release

3568d ago

Major Versions

v1.2.4 → v2.0.02016-05-05

v2.0.1 → v3.0.02016-05-20

PHP version history (2 changes)v1.1.0PHP &gt;=5.4.0

v2.0.0PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/3379a93d51305df325df9045e1a8b205d195e4e8c01312dff53a000ee79002eb?d=identicon)[jasny](/maintainers/jasny)

---

Top Contributors

[![Minstel](https://avatars.githubusercontent.com/u/6154708?v=4)](https://github.com/Minstel "Minstel (47 commits)")[![jasny](https://avatars.githubusercontent.com/u/100821?v=4)](https://github.com/jasny "jasny (41 commits)")[![moesjarraf](https://avatars.githubusercontent.com/u/5793511?v=4)](https://github.com/moesjarraf "moesjarraf (1 commits)")

---

Tags

annotationsmetatype-casting

### Embed Badge

![Health badge](/badges/jasny-meta/health.svg)

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

###  Alternatives

[eusonlito/laravel-meta

A package to manage Header Meta Tags

196525.1k2](/packages/eusonlito-laravel-meta)[minime/annotations

The KISS PHP annotations library

229378.6k37](/packages/minime-annotations)[zoha/laravel-meta

a package for working with models meta

236121.7k](/packages/zoha-laravel-meta)[symfony/ai-platform

PHP library for interacting with AI platform provider.

51927.7k136](/packages/symfony-ai-platform)[spiral/attributes

PHP attributes reader

233.6M45](/packages/spiral-attributes)[torann/laravel-meta-tags

A package to manage Header Meta Tags

65273.3k4](/packages/torann-laravel-meta-tags)

PHPackages © 2026

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