-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #224 from auraphp/improve_test_reflector_target_ge…
…tter improve reflector test, use specific method for attribute specification
- Loading branch information
Showing
15 changed files
with
393 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Aura\Di\ClassScanner; | ||
|
||
final class ClassSpecification | ||
{ | ||
private string $className; | ||
private string $filename; | ||
/** | ||
* @param array<int, AttributeSpecification> $attributes | ||
*/ | ||
private array $attributes; | ||
|
||
/** | ||
* @param array<int, AttributeSpecification> $attributes | ||
*/ | ||
public function __construct( | ||
string $className, | ||
string $filename, | ||
array $attributes = [], | ||
) | ||
{ | ||
$this->className = $className; | ||
$this->filename = $filename; | ||
$this->attributes = $attributes; | ||
} | ||
|
||
public function getClassName(): string | ||
{ | ||
return $this->className; | ||
} | ||
|
||
public function getFilename(): string | ||
{ | ||
return $this->filename; | ||
} | ||
|
||
/** | ||
* @return array<int, AttributeSpecification> | ||
*/ | ||
public function getAttributes(): array | ||
{ | ||
return $this->attributes; | ||
} | ||
|
||
public function isAttributeClass(): bool | ||
{ | ||
foreach ($this->attributes as $specification) { | ||
if ($specification->getAttributeInstance() instanceof \Attribute) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @return array<int, AttributeSpecification> | ||
*/ | ||
public function getClassAttributes(): array | ||
{ | ||
return \array_filter( | ||
$this->attributes, | ||
function (AttributeSpecification $specification) { | ||
return $specification->getAttributeTarget() === \Attribute::TARGET_CLASS; | ||
} | ||
); | ||
} | ||
|
||
/** | ||
* @return array<int, AttributeSpecification> | ||
*/ | ||
public function getParameterAttributesForMethod(string $methodName): array | ||
{ | ||
return \array_filter( | ||
$this->attributes, | ||
function (AttributeSpecification $specification) use ($methodName) { | ||
return $specification->getTargetMethod() === $methodName; | ||
} | ||
); | ||
} | ||
} |
Oops, something went wrong.