-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[6.x] Support PHP 8's reflection API (#33039)
* Support PHP 8's reflection API * Fixes
- Loading branch information
1 parent
744d01d
commit 1af0632
Showing
11 changed files
with
87 additions
and
26 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
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,37 @@ | ||
<?php | ||
|
||
namespace Illuminate\Support; | ||
|
||
use ReflectionClass; | ||
|
||
class Reflector | ||
{ | ||
/** | ||
* Get the class name of the given parameter's type, if possible. | ||
* | ||
* @param \ReflectionParameter $parameter | ||
* @return string|null | ||
*/ | ||
public static function getParameterClassName($parameter) | ||
{ | ||
$type = $parameter->getType(); | ||
|
||
return ($type && ! $type->isBuiltin()) ? $type->getName() : null; | ||
} | ||
|
||
/** | ||
* Determine if the parameter's type is a subclass of the given type. | ||
* | ||
* @param \ReflectionParameter $parameter | ||
* @param string $className | ||
* @return bool | ||
*/ | ||
public static function isParameterSubclassOf($parameter, $className) | ||
{ | ||
$paramClassName = static::getParameterClassName($parameter); | ||
|
||
return ($paramClassName && class_exists($paramClassName)) | ||
? (new ReflectionClass($paramClassName))->isSubclassOf($className) | ||
: false; | ||
} | ||
} |