Attribute Class

Namespace:

AntonDPerera\PHPAttributesReader\Attribute

The Attribute class on PHP Attributes Reader library is a class that helps to access details of a PHP attribute which was fetched through the AttributesReader

PHP Class with Class Attributes

<?php

declare(strict_types=1);

#[TestAttribute11(["key1" => "key1 value"])]
#[TestAttribute12(10.13)]
#[TestAttribute13(123)]
#[TestAttribute14()]
#[TestAttribute15(["value1", "value2"])]
class Abc
{
    // rest of the codes
}

Initialize the Attributes Reader and retrieve an attribute

<?php

declare(strict_types=1);

use \AntonDPerera\PHPAttributesReader\AttributesReader;

$class = Abc::class;

$attributes_reader = AttributesReader($class);

//This will return instance of AntonDPerera\PHPAttributesReader\Attribute
$attributes_reader->getClassAttribute("TestAttribute11");

Refer to Class Attributes , Method Attributes and Property Attributes guides to see how to get attributes from the AttributesReader.

Available functions in Attribute class

public function getClass(): string

Returns namespace of the Attribute class Caution: if there isn't a specific class with the Attribute name then this won't be a valid class namespace)

public function getName(): string

Returns name of the attribute.

public function hasArguments(): bool

Returns true or false based on availability of arguments of the attribute.

public function getArguments(): array

Returns an array of Arguments for the Attribute. Each item on array will be an instance of Argument class \AntonDPerera\PHPAttributesReader\Argument

Refer Argument class Reference documentation for more details.

Last updated