PHPackages                             omocha/omocha - 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. omocha/omocha

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

omocha/omocha
=============

Simple annotation parser

1.1(11y ago)02262Apache License 2.0PHPPHP &gt;=5.4.0

Since Oct 2Pushed 11y ago1 watchersCompare

[ Source](https://github.com/emaphp/omocha)[ Packagist](https://packagist.org/packages/omocha/omocha)[ RSS](/packages/omocha-omocha/feed)WikiDiscussions master Synced 2w ago

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

omocha
======

[](#omocha)

Simple annotation parser for PHP

[![Build Status](https://camo.githubusercontent.com/0a509ac3f3eb475e4bcbe99e672ed4c67793dda1f043327e59e32ac05f347c69/68747470733a2f2f7472617669732d63692e6f72672f656d617068702f6f6d6f6368612e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/emaphp/omocha)

\####Dependencies

- PHP 5.4

\####Installation

```
{
    "require": {
        "omocha/omocha": "1.1.*"
    }
}
```

\####Examples

> Getting annotations

```
require 'vendor/autoload.php';

use Omocha\Omocha;

/**
 * @Instrument
 * @Type stringed
 * @Price 500.75
 */
class Violin {
    /**
     * @Amount 4
     */
    private $strings;

    /**
     * @Techniques ["Sordino", "Martelé", "Pizzicato"]
     */
    private $bow;

    /**
     * @Detail {"name": "Antonio Stradivari", "occupation": "luthier"}
     */
    private $owner;
}

//get annotations as an instance of AnnotationBag
$reflectionClass = new ReflectionClass('Violin');
$annotationBag = Omocha::getAnnotations($reflectionClass);

//check for annotation
$annotationBag->has('Instrument'); // returns true

//get Annotation instance
$annotation = $annotationBag->get('Instrument');

//default value
$annotation->getValue(); // returns true

//strings
$annotationBag->get('Type')->getValue(); // returns 'stringed'

//floats
$annotationBag->get('Price')->getValue(); // returns 500.75

//integers
$annotationBag = Omocha::getAnnotations($reflectionClass->getProperty('strings'));
$annotationBag->get('Amount')->getValue(); //returns 4

//arrays
$annotationBag = Omocha::getAnnotations($reflectionClass->getProperty('bow'));
$annotationBag->get('Techniques')->getValue(); //returns ["Sordino", "Martelé", "Pizzicato"]

//objects
$annotationBag = Omocha::getAnnotations($reflectionClass->getProperty('owner'));
$value = $annotationBag->get('Detail')->getValue();
$value instanceof stdClass; // returns true
$value->name; //returns "Antonio Stradivari"
$value->occupation; //returns "luthier"
```

> Arguments

```
require 'vendor/autoload.php';

use Omocha\Omocha;
use Omocha\Filter;

/**
 * @RestService
 * @Option(output) XML
 * @Option(template) service.tpl
 * @Option(on_error) 404
 * @Option null
 */
class Webservice {
    /**
     * @Config(MySQL) ['user', 'password', 'database']
     * @Config(PostgreSQL) user=user,password=password,dbname=database
     * @Config(SQLite) database.db
     */
    private $connection;
}

$reflectionClass = new ReflectionClass('Webservice');
$annotationBag = Omocha::getAnnotations($reflectionClass);

//AnnotationBag implements Countable
count($annotationBag); // returns 5

//and IteratorAggregate
foreach ($annotationBag as $annotation) {
    //...
}

//and JsonSerializable
$json = json_encode($annotationBag);

//get first option
$annotation = $annotationBag->get('Option');
//annotation argument is stored as a string
$annotation->getArgument(); //returns 'output'

//the 'find' method gets all annotations with the given name
$options = $annotationBag->find('Option');
count($options); //returns 4

//an additional filter argument could be provided
$argOptions = $annotationBag->find('Option', Filter::HAS_ARGUMENT);
count($argOptions); //returns 3

//annotations could also be filtered by its value type
$annotationBag = Omocha::getAnnotations($reflectionClass->getProperty('connection'));
$connOptions = $annotationBag->find('Config', Filter::HAS_ARGUMENT | Filter::TYPE_ARRAY);
$connOptions[0]->getArgument(); //returns 'MySQL'

//using a custom filter
$conn = $annotationBag->filter(function ($annotation) {
    return $annotation->getArgument() == 'SQLite';
});

$conn[0]->getValue(); // returns 'database.db'
```

\####License

Licensed under the Apache License, Version 2.0.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity59

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

Total

2

Last Release

4278d ago

### Community

Maintainers

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

---

Top Contributors

[![emaphp](https://avatars.githubusercontent.com/u/3780753?v=4)](https://github.com/emaphp "emaphp (10 commits)")

---

Tags

phpreflectionannotationsdocblockmetadata

### Embed Badge

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

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

###  Alternatives

[doctrine/lexer

PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.

11.2k942.7M149](/packages/doctrine-lexer)[jms/metadata

Class/method/property metadata management in PHP

1.8k157.6M95](/packages/jms-metadata)[minime/annotations

The KISS PHP annotations library

229386.3k38](/packages/minime-annotations)[jan-swiecki/simple-annotations

Simple annotation parser

66631.5k19](/packages/jan-swiecki-simple-annotations)[dannykopping/docblock

A simple library for parsing PHP DocBlock comments

191.8k2](/packages/dannykopping-docblock)

PHPackages © 2026

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