PHP code example of thgs / attributes-loader
1. Go to this page and download the library: Download thgs/attributes-loader library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
thgs / attributes-loader example snippets
namespace Thgs\AttributesLoader;
use Attribute;
#[Attribute()]
class TestAttribute
{
public function __construct(private $where = null)
{
}
public function getWhere()
{
return $this->where;
}
}
#[TestAttribute(where: 'class')]
class TestSubject
{
#[TestAttribute(where: 'method')]
public function method()
{
}
}
$loader = new AttributesLoader();
$loader->fromClass(TestSubject::class);
/** @var TestAttribute[] $attributes */
$attributes = $loader->getAttributesCollected();
$attributesCollected = FluentAttributeCollector::new()
->only([TestAttribute2::class])
->target(\Attribute::TARGET_PROPERTY)
->fromClass(TestSubject::class)
->getCollectedAttributes();