Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove reflection from XP Core #332

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
8 changes: 5 additions & 3 deletions src/main/php/lang/FunctionType.class.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php namespace lang;

use Throwable as Any;

/**
* Represents function types
*
Expand Down Expand Up @@ -303,7 +305,7 @@ public function isAssignableFrom($type): bool {
* @param var[] $args
* @return var
* @throws lang.IllegalArgumentException in case the passed function is not an instance of this type
* @throws lang.reflect.TargetInvocationException for any exception raised from the invoked function
* @throws lang.Throwable for any exception raised from the invoked function
*/
public function invoke($func, $args= []) {
$closure= $this->verified($func, function($m) use($func) { throw new IllegalArgumentException(sprintf(
Expand All @@ -314,8 +316,8 @@ public function invoke($func, $args= []) {
)); });
try {
return $closure(...$args);
} catch (Throwable $e) {
throw new \lang\reflect\TargetInvocationException($this->getName(), $e);
} catch (Any $e) {
throw Throwable::wrap($e);
}
}
}
3 changes: 2 additions & 1 deletion src/main/php/lang/GenericTypes.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public function newType(XPClass $base, array $arguments) {
public function newType0($base, $arguments) {

// Verify
$annotations= $base->getAnnotations();
$details= XPClass::detailsForClass($base->getName());
$annotations= $details ? $details['class'][DETAIL_ANNOTATIONS] : [];
if (!isset($annotations['generic']['self'])) {
throw new IllegalStateException('Class '.$base->name.' is not a generic definition');
}
Expand Down
Loading