-
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.
add class specification class, allows attribute config to ask for rel…
…ated attributes
- Loading branch information
1 parent
49e2c94
commit 69fe40c
Showing
11 changed files
with
185 additions
and
48 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; | ||
} | ||
); | ||
} | ||
} |
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
Oops, something went wrong.