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
  1. If $property_name is null, returns true or false based on availability of Property attributes in the class.

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

public function getPropertyAttributes(?string $property_name = null): array | PropertyNotFoundException
  1. If $property_name is null, returns all the Property attributes in the class.

  2. If $property_name is not null, 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.

  3. If given $property_name is not available within the list of Property attributes, this function will throws AntonDPerera\PHPAttributesReader\Exceptions\PropertyNotFoundException.

public function getPropertyAttribute(string $property_name, string $attribute_name): Attribute | PropertyAttributeNotFoundException
  1. If given $property_name is not available within the list of Property attributes, this function will throws AntonDPerera\PHPAttributesReader\Exceptions\PropertyNotFoundException.

  2. 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 throws AntonDPerera\PHPAttributesReader\Exceptions\PropertyAttributeNotFoundException.

  3. 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