PHP Attributes Reader
  • Introduction
  • Installation
  • Reading Attributes
    • Quick Start
    • Class Attributes
    • Method Attributes
    • Property Attributes
    • Attribute Class
    • Argument Class
  • Limitations
  • Contribution
Powered by GitBook
On this page
  1. Reading Attributes

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");

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

PreviousProperty AttributesNextArgument Class

Last updated 1 year ago

Refer to , and guides to see how to get attributes from the AttributesReader.

Refer documentation for more details.

Class Attributes
Method Attributes
Property Attributes
Argument class Reference