Skip to content

thgs/attributes-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

attributes-loader

This small library is meant to provide a way to load PHP 8.x attributes from classes. It is still in early development.

Usage

Example usage

<?php

namespace Thgs\AttributesLoader;

use Attribute;

#[Attribute()]
class TestAttribute
{
    public function __construct(private $where = null)
    {
    }

    public function getWhere()
    {
        return $this->where;
    }
}

#[TestAttribute(where: 'class')]
class TestSubject
{
    #[TestAttribute(where: 'method')]
    public function method()
    {
    }
}

$loader = new AttributesLoader();
$loader->fromClass(TestSubject::class);

/** @var TestAttribute[] $attributes */
$attributes = $loader->getAttributesCollected();

Or use the FluentAttributeCollector

<?php

$attributesCollected = FluentAttributeCollector::new()
    ->only([TestAttribute2::class])
    ->target(\Attribute::TARGET_PROPERTY)
    ->fromClass(TestSubject::class)
    ->getCollectedAttributes();

More examples of usage can be found currently by looking at the tests.

About

Collects PHP 8.x attributes for you

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages