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
If
$method_name
isnull
, returnstrue
orfalse
based on availability of Method attributes in the class.If
$method_name
is notnull
, returnstrue
orfalse
based on availability of Method attributes for the given$method_name
.
public function getMethodAttributes(?string $method_name = null): array | MethodNotFoundException
If
$method_name
isnull
, returns all the Method attributes in the class.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.
If given
$method_name
is not available within the list of Method attributes, this function will throwsAntonDPerera\PHPAttributesReader\Exceptions\MethodNotFoundException
.
public function getMethodAttribute(string $method_name, string $attribute_name): Attribute | MethodAttributeNotFoundException
If given
$method_name
is not available within the list of Method attributes, this function will throwsAntonDPerera\PHPAttributesReader\Exceptions\MethodNotFoundException
.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 throwsAntonDPerera\PHPAttributesReader\Exceptions\MethodAttributeNotFoundException
.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