-
Notifications
You must be signed in to change notification settings - Fork 0
Php8 rollback #4
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
base: master
Are you sure you want to change the base?
Changes from all commits
b995743
3ec3df7
7ebf327
40fb8fa
9f5762b
7ed3647
47e5f41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -542,7 +542,7 @@ public function build($concrete, $parameters = array()) | |||||||||
| /** | ||||||||||
| * Resolve all of the dependencies from the ReflectionParameters. | ||||||||||
| * | ||||||||||
| * @param array $parameters | ||||||||||
| * @param \ReflectionParameter[] $parameters | ||||||||||
| * @param array $primitives | ||||||||||
| * @return array | ||||||||||
| */ | ||||||||||
|
|
@@ -552,7 +552,9 @@ protected function getDependencies($parameters, array $primitives = array()) | |||||||||
|
|
||||||||||
| foreach ($parameters as $parameter) | ||||||||||
| { | ||||||||||
| $dependency = $parameter->getClass(); | ||||||||||
| $dependency = $parameter->getType() && ! $parameter->getType()->isBuiltin() | ||||||||||
| ? new ReflectionClass($parameter->getType()->getName()) | ||||||||||
| : null; | ||||||||||
|
Comment on lines
+555
to
+557
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential compatibility issue with The usage of Apply this diff to restore compatibility with PHP versions before 7.0: -$dependency = $parameter->getType() && ! $parameter->getType()->isBuiltin()
- ? new ReflectionClass($parameter->getType()->getName())
- : null;
+$dependency = $parameter->getClass();This change uses 📝 Committable suggestion
Suggested change
|
||||||||||
|
|
||||||||||
| // If the class is null, it means the dependency is a string or some other | ||||||||||
| // primitive type which we can not resolve since it is not a class and | ||||||||||
|
|
@@ -606,7 +608,7 @@ protected function resolveClass(ReflectionParameter $parameter) | |||||||||
| { | ||||||||||
| try | ||||||||||
| { | ||||||||||
| return $this->make($parameter->getClass()->name); | ||||||||||
| return $this->make($parameter->getType()->getName()); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // If we can not resolve the class instance, we will check to see if the value | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| <?php namespace Illuminate\Routing; | ||
|
|
||
| use Illuminate\Container\Container; | ||
| use Illuminate\Http\Request; | ||
| use Illuminate\Routing\Matching\UriValidator; | ||
| use Illuminate\Routing\Matching\HostValidator; | ||
|
|
@@ -9,6 +10,8 @@ | |
|
|
||
| class Route { | ||
|
|
||
| use RouteDependencyResolverTrait; | ||
|
|
||
| /** | ||
| * The URI pattern the route responds to. | ||
| * | ||
|
|
@@ -65,6 +68,13 @@ class Route { | |
| */ | ||
| protected $compiled; | ||
|
|
||
| /** | ||
| * The container instance used by the route. | ||
| * | ||
| * @var \Illuminate\Container\Container | ||
| */ | ||
| protected $container; | ||
|
|
||
|
Comment on lines
+76
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure The |
||
| /** | ||
| * The validators used by the routes. | ||
| * | ||
|
|
@@ -104,9 +114,11 @@ public function __construct($methods, $uri, $action) | |
| */ | ||
| public function run() | ||
| { | ||
| $parameters = array_filter($this->parameters(), function($p) { return isset($p); }); | ||
| $callable = $this->action['uses']; | ||
|
|
||
| return call_user_func_array($this->action['uses'], $parameters); | ||
| return $callable(...array_values($this->resolveMethodDependencies( | ||
| $this->parametersWithoutNulls(), new \ReflectionFunction($callable) | ||
| ))); | ||
|
Comment on lines
+117
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle callable types correctly in In the Modify the code to check if $callable = $this->action['uses'];
if (is_array($callable)) {
$reflector = new \ReflectionMethod($callable[0], $callable[1]);
} else {
$reflector = new \ReflectionFunction($callable);
}
return $callable(...array_values($this->resolveMethodDependencies(
$this->parametersWithoutNulls(), $reflector
))); |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -811,4 +823,16 @@ public function getCompiled() | |
| return $this->compiled; | ||
| } | ||
|
|
||
| /** | ||
| * Set the container instance on the route. | ||
| * | ||
| * @param \Illuminate\Container\Container $container | ||
| * @return $this | ||
| */ | ||
| public function setContainer(Container $container) | ||
| { | ||
| $this->container = $container; | ||
|
|
||
| return $this; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,112 @@ | ||||||||||
| <?php | ||||||||||
|
|
||||||||||
| namespace Illuminate\Routing; | ||||||||||
|
|
||||||||||
| use Illuminate\Support\Arr; | ||||||||||
| use Illuminate\Support\Reflector; | ||||||||||
| use ReflectionFunctionAbstract; | ||||||||||
| use ReflectionMethod; | ||||||||||
| use ReflectionParameter; | ||||||||||
| use stdClass; | ||||||||||
|
|
||||||||||
| trait RouteDependencyResolverTrait | ||||||||||
| { | ||||||||||
| /** | ||||||||||
| * Resolve the object method's type-hinted dependencies. | ||||||||||
| * | ||||||||||
| * @param array $parameters | ||||||||||
| * @param object $instance | ||||||||||
| * @param string $method | ||||||||||
| * @return array | ||||||||||
| */ | ||||||||||
| protected function resolveClassMethodDependencies(array $parameters, $instance, $method) | ||||||||||
| { | ||||||||||
| if (! method_exists($instance, $method)) { | ||||||||||
| return $parameters; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return $this->resolveMethodDependencies( | ||||||||||
| $parameters, new ReflectionMethod($instance, $method) | ||||||||||
| ); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Resolve the given method's type-hinted dependencies. | ||||||||||
| * | ||||||||||
| * @param array $parameters | ||||||||||
| * @param \ReflectionFunctionAbstract $reflector | ||||||||||
| * @return array | ||||||||||
| */ | ||||||||||
| public function resolveMethodDependencies(array $parameters, ReflectionFunctionAbstract $reflector) | ||||||||||
| { | ||||||||||
| $instanceCount = 0; | ||||||||||
|
|
||||||||||
| $values = array_values($parameters); | ||||||||||
|
|
||||||||||
| $skippableValue = new stdClass; | ||||||||||
|
|
||||||||||
| foreach ($reflector->getParameters() as $key => $parameter) { | ||||||||||
| $instance = $this->transformDependency($parameter, $parameters, $skippableValue); | ||||||||||
|
|
||||||||||
| if ($instance !== $skippableValue) { | ||||||||||
| $instanceCount++; | ||||||||||
|
|
||||||||||
| $this->spliceIntoParameters($parameters, $key, $instance); | ||||||||||
| } elseif (! isset($values[$key - $instanceCount]) && | ||||||||||
| $parameter->isDefaultValueAvailable()) { | ||||||||||
| $this->spliceIntoParameters($parameters, $key, $parameter->getDefaultValue()); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return $parameters; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Attempt to transform the given parameter into a class instance. | ||||||||||
| * | ||||||||||
| * @param \ReflectionParameter $parameter | ||||||||||
| * @param array $parameters | ||||||||||
| * @param object $skippableValue | ||||||||||
| * @return mixed | ||||||||||
| */ | ||||||||||
| protected function transformDependency(ReflectionParameter $parameter, $parameters, $skippableValue) | ||||||||||
| { | ||||||||||
| $className = Reflector::getParameterClassName($parameter); | ||||||||||
|
|
||||||||||
| // If the parameter has a type-hinted class, we will check to see if it is already in | ||||||||||
| // the list of parameters. If it is we will just skip it as it is probably a model | ||||||||||
| // binding and we do not want to mess with those; otherwise, we resolve it here. | ||||||||||
| if ($className && ! $this->alreadyInParameters($className, $parameters)) { | ||||||||||
| return $parameter->isDefaultValueAvailable() ? null : $this->container->make($className); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return $skippableValue; | ||||||||||
| } | ||||||||||
|
Comment on lines
+72
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure In the method |
||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Determine if an object of the given class is in a list of parameters. | ||||||||||
| * | ||||||||||
| * @param string $class | ||||||||||
| * @param array $parameters | ||||||||||
| * @return bool | ||||||||||
| */ | ||||||||||
| protected function alreadyInParameters($class, array $parameters) | ||||||||||
| { | ||||||||||
| return ! is_null(Arr::first($parameters, fn ($value) => $value instanceof $class)); | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace arrow function for compatibility with PHP versions before 7.4 The use of the arrow function syntax Apply this diff to fix the compatibility issue: -return ! is_null(Arr::first($parameters, fn ($value) => $value instanceof $class));
+return ! is_null(Arr::first($parameters, function ($value) use ($class) {
+ return $value instanceof $class;
+}));📝 Committable suggestion
Suggested change
|
||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Splice the given value into the parameter list. | ||||||||||
| * | ||||||||||
| * @param array $parameters | ||||||||||
| * @param string $offset | ||||||||||
| * @param mixed $value | ||||||||||
| * @return void | ||||||||||
| */ | ||||||||||
| protected function spliceIntoParameters(array &$parameters, $offset, $value) | ||||||||||
| { | ||||||||||
| array_splice( | ||||||||||
| $parameters, $offset, 0, [$value] | ||||||||||
| ); | ||||||||||
| } | ||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| <?php | ||
|
|
||
| namespace Illuminate\Support; | ||
|
|
||
| use ReflectionClass; | ||
| use ReflectionMethod; | ||
| use ReflectionNamedType; | ||
| use ReflectionUnionType; | ||
|
Comment on lines
+7
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using The Consider refactoring the code to avoid using |
||
|
|
||
| class Reflector | ||
| { | ||
| /** | ||
| * This is a PHP 7.4 compatible implementation of is_callable. | ||
| * | ||
| * @param mixed $var | ||
| * @param bool $syntaxOnly | ||
| * @return bool | ||
| */ | ||
| public static function isCallable($var, $syntaxOnly = false) | ||
| { | ||
| if (! is_array($var)) { | ||
| return is_callable($var, $syntaxOnly); | ||
| } | ||
|
|
||
| if ((! isset($var[0]) || ! isset($var[1])) || | ||
| ! is_string($var[1] ?? null)) { | ||
| return false; | ||
| } | ||
|
|
||
| if ($syntaxOnly && | ||
| (is_string($var[0]) || is_object($var[0])) && | ||
| is_string($var[1])) { | ||
| return true; | ||
| } | ||
|
|
||
| $class = is_object($var[0]) ? get_class($var[0]) : $var[0]; | ||
|
|
||
| $method = $var[1]; | ||
|
|
||
| if (! class_exists($class)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (method_exists($class, $method)) { | ||
| return (new ReflectionMethod($class, $method))->isPublic(); | ||
| } | ||
|
|
||
| if (is_object($var[0]) && method_exists($class, '__call')) { | ||
| return (new ReflectionMethod($class, '__call'))->isPublic(); | ||
| } | ||
|
|
||
| if (! is_object($var[0]) && method_exists($class, '__callStatic')) { | ||
| return (new ReflectionMethod($class, '__callStatic'))->isPublic(); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * 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(); | ||
|
|
||
| if (! $type instanceof ReflectionNamedType || $type->isBuiltin()) { | ||
| return; | ||
| } | ||
|
|
||
| return static::getTypeName($parameter, $type); | ||
| } | ||
|
|
||
| /** | ||
| * Get the class names of the given parameter's type, including union types. | ||
| * | ||
| * @param \ReflectionParameter $parameter | ||
| * @return array | ||
| */ | ||
| public static function getParameterClassNames($parameter) | ||
| { | ||
| $type = $parameter->getType(); | ||
|
|
||
| if (! $type instanceof ReflectionUnionType) { | ||
| return array_filter([static::getParameterClassName($parameter)]); | ||
| } | ||
|
|
||
| $unionTypes = []; | ||
|
|
||
| foreach ($type->getTypes() as $listedType) { | ||
| if (! $listedType instanceof ReflectionNamedType || $listedType->isBuiltin()) { | ||
| continue; | ||
| } | ||
|
|
||
| $unionTypes[] = static::getTypeName($parameter, $listedType); | ||
| } | ||
|
|
||
| return array_filter($unionTypes); | ||
| } | ||
|
|
||
| /** | ||
| * Get the given type's class name. | ||
| * | ||
| * @param \ReflectionParameter $parameter | ||
| * @param \ReflectionNamedType $type | ||
| * @return string | ||
| */ | ||
| protected static function getTypeName($parameter, $type) | ||
| { | ||
| $name = $type->getName(); | ||
|
|
||
| if (! is_null($class = $parameter->getDeclaringClass())) { | ||
| if ($name === 'self') { | ||
| return $class->getName(); | ||
| } | ||
|
|
||
| if ($name === 'parent' && $parent = $class->getParentClass()) { | ||
| return $parent->getName(); | ||
| } | ||
| } | ||
|
|
||
| return $name; | ||
| } | ||
|
|
||
| /** | ||
| * 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) || interface_exists($paramClassName)) | ||
| && (new ReflectionClass($paramClassName))->isSubclassOf($className); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Security vulnerability found in phpseclib version constraint
The
~2.0constraint inphpseclib/phpsecliballows using versions with known HIGH severity vulnerabilities (up to 2.0.47). These include:Recommendation: Update the constraint to
~2.0.47to ensure using a patched version.🔗 Analysis chain
Verify security implications of fixed versions.
The changes pin specific versions:
Let's verify if these versions have known security vulnerabilities.
Also applies to: 32-33
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 5332