PHP code example of rinsvent / attribute-extractor
1. Go to this page and download the library: Download rinsvent/attribute-extractor 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/ */
rinsvent / attribute-extractor example snippets
namespace Rinsvent\AttributeExtractor\Tests\unit\Listener\fixtures;
use Rinsvent\AttributeExtractor\Tests\unit\Listener\fixtures\Annotation\HeaderKey;
use Rinsvent\AttributeExtractor\Tests\unit\Listener\fixtures\Annotation\PropertyPath;
use Rinsvent\AttributeExtractor\Tests\unit\Listener\fixtures\Annotation\RequestDTO;
use Rinsvent\AttributeExtractor\Tests\unit\Listener\fixtures\Annotation\MultiplePropertyPath;
#[RequestDTO(className: 'HelloRequestDTO', jsonPath: '$.customObject')]
class HelloRequest
{
#[HeaderKey(key: 'X-Surname')]
public string $surname;
public int $age;
#[PropertyPath(path: 'DTO')]
public string $dto;
#[MultiplePropertyPath(path: 'dto1')]
#[MultiplePropertyPath(path: 'dto2')]
public function getDto(): string
{
return $this->dto;
}
}
use Rinsvent\AttributeExtractor\ClassIterator;
// Инициалищируем
$classIterator = new ClassIterator(HelloRequest::class, RequestDTO::class);
// Получаем первый атрибут
$result = $classIterator[0];
use Rinsvent\AttributeExtractor\PropertyIterator;
// Инициалищируем
$propertyIterator = new PropertyIterator(HelloRequest::class, 'dto', PropertyPath::class);
// Получаем первый атрибут
$result = $propertyIterator[0];
use Rinsvent\AttributeExtractor\MethodIterator;
// Инициалищируем
$methodIterator = new MethodIterator(HelloRequest::class, 'getDto', MultiplePropertyPath::class);
// Перебираем все атрибуты
foreach ($methodIterator as $result) {
// todo реализация
}
#[\Attribute]
class RequestDTO
{
public function __construct(
public string $className,
public string $jsonPath = '$',
) {}
}
#[\Attribute]
class UserRequestDTO extends RequestDTO
{
public function __construct(
public string $className,
public string $jsonPath = '$.user',
) {}
}
use Rinsvent\AttributeExtractor\Tests\unit\Listener\fixtures\Annotation\UserRequestDTO;
class ExtendsRequest
{
#[UserRequestDTO(className: 'HelloRequestDTO')]
public object $user;
}
$propertyIterator = new PropertyIterator(ExtendsRequest::class, 'user', RequestDTO::class);
$result = $propertyIterator[0];
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.