PHPackages                             terminal42/service-annotation-bundle - 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. terminal42/service-annotation-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

terminal42/service-annotation-bundle
====================================

Add service tags from class annotations

1.2.2(7mo ago)11.5M↓49.8%512MITPHPPHP ^7.1 || ^8.0CI passing

Since Jul 3Pushed 7mo ago2 watchersCompare

[ Source](https://github.com/terminal42/service-annotation-bundle)[ Packagist](https://packagist.org/packages/terminal42/service-annotation-bundle)[ GitHub Sponsors](https://github.com/sponsors/terminal42)[ Fund](https://ko-fi.com/terminal42)[ RSS](/packages/terminal42-service-annotation-bundle/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (1)Dependencies (4)Versions (13)Used By (12)

terminal42/service-annotation-bundle
====================================

[](#terminal42service-annotation-bundle)

This bundle allows to add tags to container services using annotations. Similar to services subscribers for events, this allows the class to contain all necessary information within the same file.

This is most helpful if you use autowiring and autoconfiguration in your service definitions, but it works without it (e.g. for bundles) nonetheless.

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

[](#installation)

```
$ composer.phar require terminal42/service-annotation-bundle ^1.0
```

Afterwards, make sure to enable the `Terminal42\ServiceAnnotation\Terminal42ServiceAnnotationBundle` in your kernel.

Configuration
-------------

[](#configuration)

The bundle currently does not provide any service configuration.

How to use
----------

[](#how-to-use)

Annotations can be used on any service which is registered in the container.

The example annotations below equal to the following tags:

```
service:
    App\EventListener\KernelListener:
        tags:
            - { name: monolog.logger, channel: routing }
            - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
```

**Example:**

```
// src/EventListener/KernelListener.php

namespace App\EventListener;

use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Terminal42\ServiceAnnotationBundle\Annotation\ServiceTag;

/**
 * @ServiceTag("monolog.logger", channel="routing")
 */
class KernelListener
{
    private $logger;

    public function __construct(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }

    /**
     * @ServiceTag("kernel.event_listener", event="kernel.request")
     */
    public function onKernelRequest(GetResponseEvent $event)
    {
        $this->logger->debug('Request for '.$event->getRequest()->getRequestUri());
    }
}
```

If an annotation is added to a method instead of the class, the method name is automatically added to the service tag "method" argument.

Extending the annotations
-------------------------

[](#extending-the-annotations)

If your bundle provides new tags to other services, you can improve DX by providing your own annotations. Good IDEs like PhpStorm can then provide autocomplete support.

**Example:**

```
use Doctrine\Common\Annotations\Annotation\Attribute;
use Doctrine\Common\Annotations\Annotation\Attributes;
use Doctrine\Common\Annotations\Annotation\Target;
use Terminal42\ServiceAnnotationBundle\Annotation\ServiceTagInterface;

/**
 * @Annotation
 * @Target("CLASS")
 * @Attributes({
 *     @Attribute("channel", type = "string", required = true),
 * })
 */
class Logger implements ServiceTagInterface
{
    public $channel;

    public function getName(): string
    {
        return 'monolog.logger';
    }

    public function getAttributes(): array
    {
        return ['channel' => $this->channel];
    }
}
```

Applying this to the example above, the class annotation can be simplified like this:

```
// src/EventListener/KernelListener.php

namespace App\EventListener;

/**
 * @Logger(channel="routing")
 */
class KernelListener
{
    // Same class as before
}
```

###  Health Score

55

—

FairBetter than 97% of packages

Maintenance64

Regular maintenance activity

Popularity43

Moderate usage in the ecosystem

Community29

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 69.6% 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 ~212 days

Recently: every ~243 days

Total

12

Last Release

221d ago

PHP version history (2 changes)1.0.0PHP ^7.1

1.1.3PHP ^7.1 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1073273?v=4)[Andreas Schempp](/maintainers/aschempp)[@aschempp](https://github.com/aschempp)

![](https://avatars.githubusercontent.com/u/481937?v=4)[Yanick Witschi](/maintainers/Toflar)[@Toflar](https://github.com/Toflar)

---

Top Contributors

[![aschempp](https://avatars.githubusercontent.com/u/1073273?v=4)](https://github.com/aschempp "aschempp (16 commits)")[![Toflar](https://avatars.githubusercontent.com/u/481937?v=4)](https://github.com/Toflar "Toflar (3 commits)")[![bytehead](https://avatars.githubusercontent.com/u/754921?v=4)](https://github.com/bytehead "bytehead (1 commits)")[![fritzmg](https://avatars.githubusercontent.com/u/4970961?v=4)](https://github.com/fritzmg "fritzmg (1 commits)")[![MacKP](https://avatars.githubusercontent.com/u/1241811?v=4)](https://github.com/MacKP "MacKP (1 commits)")[![richardhj](https://avatars.githubusercontent.com/u/1284725?v=4)](https://github.com/richardhj "richardhj (1 commits)")

### Embed Badge

![Health badge](/badges/terminal42-service-annotation-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/terminal42-service-annotation-bundle/health.svg)](https://phpackages.com/packages/terminal42-service-annotation-bundle)
```

PHPackages © 2026

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