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): bool
If
$property_name
isnull
, returnstrue
orfalse
based on availability of Property attributes in the class.If
$property_name
is notnull
, returnstrue
orfalse
based on availability of Property attributes for the given$property_name
.
public function getPropertyAttributes(?string $property_name = null): array | PropertyNotFoundException
If
$property_name
isnull
, returns all the Property attributes in the class.If
$property_name
is 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\Attribute
Refer Attribute class Reference documentation for more details.
If given
$property_name
is 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 | PropertyAttributeNotFoundException
If given
$property_name
is not available within the list of Property attributes, this function will throwsAntonDPerera\PHPAttributesReader\Exceptions\PropertyNotFoundException
.If given
$property_name
is available within the list of Property attributes but the given$attribute_name
doesn't exists in the attributes list this function will throwsAntonDPerera\PHPAttributesReader\Exceptions\PropertyAttributeNotFoundException
.If given
$property_name
is available within the list of Property 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