Skip to content

Commit

Permalink
adding ReflectionAttribute class
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Jan 29, 2024
1 parent eac85cd commit 1df960d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/ReflectionAttribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);
/**
* Parser Reflection API
*
* @copyright Copyright 2015, Lisachenko Alexander <[email protected]>
*
* This source file is subject to the license that is bundled
* with this source code in the file LICENSE.
*/

namespace Go\ParserReflection;

use Go\ParserReflection\Traits\InternalPropertiesEmulationTrait;
use ReflectionAttribute as BaseReflectionAttribute;
use PhpParser\Node;
use Reflector;

class ReflectionAttribute extends BaseReflectionAttribute
{
use InternalPropertiesEmulationTrait;

public function __construct(
string $attributeName,
private ?Node\Attribute $attributeNode = null,
private ?Node\Stmt\ClassLike $classLikeNode = null,
private ?Reflector $declaringReflector = null
) {
$this->attributeNode ??= ReflectionEngine::parseAttribute($attributeName);
$this->classLikeNode ??= ReflectionEngine::parseClass($attributeName);
}

public function __debugInfo(): array
{
return [];
}

public function getNode(): Node\Attribute
{
return $this->attributeNode;
}
}
6 changes: 6 additions & 0 deletions src/ReflectionEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Go\ParserReflection;

use Exception;
use Go\ParserReflection\Instrument\PathResolver;
use Go\ParserReflection\NodeVisitor\RootNamespaceNormalizer;
use InvalidArgumentException;
Expand Down Expand Up @@ -141,6 +142,11 @@ public static function parseClass(string $fullClassName): ClassLike
throw new InvalidArgumentException("Class $fullClassName was not found in the $classFileName");
}

public static function parseAttribute(string $attributeName): Node\Attribute
{
throw new Exception('to be implemented');
}

/**
* Loop through an array and find a ClassLike statement by the given class name.
*
Expand Down

0 comments on commit 1df960d

Please sign in to comment.