Method Attributes

PHP Class with Class Attributes

<?php

declare(strict_types=1);

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

Initialize the Attributes Reader

<?php

declare(strict_types=1);

use \AntonDPerera\PHPAttributesReader\AttributesReader;

$class = Abc::class;

$attributes_reader = AttributesReader($class);

Available functions for Method Attributes

public function hasMethodAttributes(?string $method_name = null): bool
  1. If $method_name is null, returns true or false based on availability of Method attributes in the class.

  2. If $method_name is not null, returns true or false based on availability of Method attributes for the given $method_name.

public function getMethodAttributes(?string $method_name = null): array | MethodNotFoundException
  1. If $method_name is null, returns all the Method attributes in the class.

  2. If $method_name is not null, returns all the Method attributes for the given method name. It will be an array of attributes. Each item on Array will be an instance of Attribute class

    \AntonDPerera\PHPAttributesReader\Attribute

    Refer Attribute class Reference documentation for more details.

  3. If given $method_name is not available within the list of Method attributes, this function will throws AntonDPerera\PHPAttributesReader\Exceptions\MethodNotFoundException.

public function getMethodAttribute(string $method_name, string $attribute_name): Attribute | MethodAttributeNotFoundException
  1. If given $method_name is not available within the list of Method attributes, this function will throws AntonDPerera\PHPAttributesReader\Exceptions\MethodNotFoundException.

  2. If given $method_name is available within the list of Method attributes but the given $attribute_name doesn't exists in the attributes list this function will throws AntonDPerera\PHPAttributesReader\Exceptions\MethodAttributeNotFoundException.

  3. If given $method_name is available within the list of Method attributes and the given $attribute_name exists too for that method, this function will return an instance of Attribute class. Refer Attribute class Reference documentation for more details.

Last updated