codamos/tagger

A simple tagging library inspired by Go's struct tags

1.0.0 2025-07-08 09:57 UTC

This package is auto-updated.

Last update: 2025-07-08 10:05:30 UTC


README

A simple tagging library inspired by Go's struct tags

Source Code Download Package PHP Programming Language Read License (MIT)

About

codamos/tagger is a simple tagging library inspired by Go's struct tags. It allows you to fetch free-form tags from class properties via a Tag attribute that can later be used by third-party libraries or your own code.

The library also includes a tag parser and a class tags scanner. These should allow you to use tagger at scale for your entire application at build time, or at runtime.

Installation

Install this package as a dependency using Composer.

composer require codamos/tagger

Usage

You may use the Tag attribute to annotate your class' properties with free-form tags, split by space characters.

use Codamos\Tagger\Attributes\Tag;
use Codamos\Tagger\Parser\TagParser;
use Codamos\Tagger\Scanner\TagScanner;

class UserDTO
{
    #[Tag('json:"id" orm:"id,primaryKey,autoIncrement"')]}
    public int $id;

    #[Tag('json:"name" orm:"name,notNull,size:255"')]
    public string $name;

    #[Tag('json:"email" orm:"email,notNull,size:255,unique,index"')]
    public string $email;

$parser = new TagParser();
$scanner = new TagScanner($scanner);

$map = $scanner->scan(UserDTO::class);

$emailTags = $map->get('email');
$emailTags->get('json'); // string(json:"email")
$emailTags->get('orm'); // string(orm:"email,notNull,size:255,unique,index")

Copyright and License

The codamos/tagger library is copyright © Codamos and licensed for use under the terms of the MIT License (MIT). Please see LICENSE for more information.