-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reflection classes extend native, attributes fully supported, more co…
…mpatibility tests, memory management via session
- Loading branch information
Showing
70 changed files
with
3,401 additions
and
2,555 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use PhpCsFixer\Config; | ||
use PhpCsFixer\Finder; | ||
use PHPyh\CodingStandard\PhpCsFixerCodingStandard; | ||
|
||
$finder = Finder::create()->append([ | ||
__FILE__, | ||
__DIR__ . '/src/TypeResolver/RecursiveTypeReplacer.php', | ||
]); | ||
|
||
$config = (new Config()) | ||
->setFinder($finder) | ||
->setCacheFile(__DIR__ . '/var/' . basename(__FILE__) . '.cache'); | ||
|
||
(new PhpCsFixerCodingStandard())->applyTo($config, [ | ||
'final_public_method_for_abstract_class' => false, | ||
]); | ||
|
||
return $config; |
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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use PhpCsFixer\Config; | ||
use PhpCsFixer\Finder; | ||
use PHPyh\CodingStandard\PhpCsFixerCodingStandard; | ||
|
||
$finder = Finder::create()->append([ | ||
__FILE__, | ||
__DIR__ . '/src/AttributeReflection.php', | ||
__DIR__ . '/src/ClassReflection.php', | ||
__DIR__ . '/src/MethodReflection.php', | ||
__DIR__ . '/src/ParameterReflection.php', | ||
__DIR__ . '/src/PropertyReflection.php', | ||
]); | ||
|
||
$config = (new Config()) | ||
->setFinder($finder) | ||
->setCacheFile(__DIR__ . '/var/' . basename(__FILE__) . '.cache'); | ||
|
||
(new PhpCsFixerCodingStandard())->applyTo($config); | ||
|
||
$rules = $config->getRules(); | ||
$rules['ordered_class_elements']['sort_algorithm'] = 'alpha'; | ||
$rules['no_unset_on_property'] = false; | ||
$rules['phpdoc_no_alias_tag'] = false; | ||
|
||
return $config->setRules($rules); |
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use PhpCsFixer\Config; | ||
use PhpCsFixer\Finder; | ||
use PHPyh\CodingStandard\PhpCsFixerCodingStandard; | ||
|
||
$finder = Finder::create()->append([ | ||
__FILE__, | ||
__DIR__ . '/src/Inheritance/TypeInheritanceResolver.php', | ||
]); | ||
|
||
$config = (new Config()) | ||
->setFinder($finder) | ||
->setCacheFile(__DIR__ . '/var/' . basename(__FILE__) . '.cache'); | ||
|
||
(new PhpCsFixerCodingStandard())->applyTo($config, [ | ||
'strict_comparison' => false, | ||
]); | ||
|
||
return $config; |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Typhoon\Reflection\Attributes; | ||
|
||
use Typhoon\Reflection\AttributeReflection; | ||
use Typhoon\Reflection\ClassReflection\ClassReflector; | ||
use Typhoon\Reflection\Metadata\AttributeMetadata; | ||
|
||
/** | ||
* @internal | ||
* @psalm-internal Typhoon\Reflection | ||
* @template-covariant T of object | ||
* @psalm-suppress PossiblyUnusedProperty | ||
*/ | ||
final class AttributeReflections | ||
{ | ||
/** | ||
* @var list<AttributeReflection> | ||
*/ | ||
private readonly array $attributes; | ||
|
||
/** | ||
* @param list<AttributeMetadata> $attributes | ||
* @param \Closure(): list<\ReflectionAttribute> $nativeAttributes | ||
*/ | ||
public function __construct( | ||
private readonly ClassReflector $classReflector, | ||
array $attributes, | ||
\Closure $nativeAttributes, | ||
) { | ||
$this->attributes = array_map( | ||
static fn(AttributeMetadata $attribute): \ReflectionAttribute => new AttributeReflection($attribute, $nativeAttributes), | ||
$attributes, | ||
); | ||
} | ||
|
||
/** | ||
* @template TClass as object | ||
* @param class-string<TClass>|null $name | ||
* @return ($name is null ? list<AttributeReflection<object>> : list<AttributeReflection<TClass>>) | ||
*/ | ||
public function get(?string $name, int $flags): array | ||
{ | ||
if ($this->attributes === []) { | ||
return []; | ||
} | ||
|
||
if ($name === null) { | ||
return $this->attributes; | ||
} | ||
|
||
if ($flags & \ReflectionAttribute::IS_INSTANCEOF) { | ||
/** @var list<AttributeReflection<TClass>> */ | ||
return array_filter( | ||
$this->attributes, | ||
fn(AttributeReflection $attribute): bool => $attribute->getName() === $name | ||
|| $this->classReflector->reflectClass($attribute->getName())->isSubclassOf($name), | ||
); | ||
} | ||
|
||
/** @var list<AttributeReflection<TClass>> */ | ||
return array_filter( | ||
$this->attributes, | ||
static fn(AttributeReflection $attribute): bool => $attribute->getName() === $name, | ||
); | ||
} | ||
} |
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.