Property Attributes
PHP Class with Class Attributes
<?php
declare(strict_types=1);
class Abc
{
#[TestAttribute2('testValue2')]
public ?string $test_property_1 = null;
public ?string $test_property_2 = null;
// 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 Property Attributes
public function hasPropertyAttributes(?string $property_name = null): boolIf
$property_nameisnull, returnstrueorfalsebased on availability of Property attributes in the class.If
$property_nameis notnull, returnstrueorfalsebased on availability of Property attributes for the given$property_name.
public function getPropertyAttributes(?string $property_name = null): array | PropertyNotFoundExceptionIf
$property_nameisnull, returns all the Property attributes in the class.If
$property_nameis notnull, returns all the Property 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\AttributeRefer Attribute class Reference documentation for more details.
If given
$property_nameis not available within the list of Property attributes, this function will throwsAntonDPerera\PHPAttributesReader\Exceptions\PropertyNotFoundException.
public function getPropertyAttribute(string $property_name, string $attribute_name): Attribute | PropertyAttributeNotFoundExceptionIf given
$property_nameis not available within the list of Property attributes, this function will throwsAntonDPerera\PHPAttributesReader\Exceptions\PropertyNotFoundException.If given
$property_nameis available within the list of Property attributes but the given$attribute_namedoesn't exists in the attributes list this function will throwsAntonDPerera\PHPAttributesReader\Exceptions\PropertyAttributeNotFoundException.If given
$property_nameis available within the list of Property attributes and the given$attribute_nameexists too for that method, this function will return an instance of Attribute class. Refer Attribute class Reference documentation for more details.
Last updated