PHP code example of anhoder / annotations-collector
1. Go to this page and download the library: Download anhoder/annotations-collector 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/ */
anhoder / annotations-collector example snippets
class AttributeConfig implements ConfigInterface
{
#[ArrayShape(['scanDirs' => 'array'])]
public static function getAttributeConfigs(): array
{
return [
'scanDirs' => [
__NAMESPACE__ => __DIR__,
],
];
}
}
// Attribute
#[Attribute(Attribute::TARGET_CLASS)]
class ClassAttribute
{
public const TEST = 'test';
private string $test;
public function __construct(#[ExpectedValues(valuesFromClass: ClassAttribute::class)] string $test)
{
$this->test = $test;
}
public function getTest(): string
{
return $this->test;
}
}
// AttributeHandler
#[AttributeHandler(ClassAttribute::class)]
class ClassAttributeHandler extends AbstractHandler
{
public function handle(): void
{
/**
* @var $attribute ClassAttribute
*/
var_dump($this);
$attribute = $this->attribute;
var_dump($attribute->getTest());
}
}
#[ClassAttribute(ClassAttribute::TEST)]
class ClassAttributeTest
{
}