generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
820d1dd
commit 318ae2b
Showing
12 changed files
with
74 additions
and
283 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 was deleted.
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Dedoc\Scramble\Support; | ||
|
||
use Dedoc\Scramble\Support\OperationExtensions\ParameterExtractor\ParameterExtractor; | ||
use ReflectionClass; | ||
use ReflectionNamedType; | ||
use ReflectionParameter; | ||
|
||
class ContainerUtils | ||
{ | ||
/** | ||
* @template T of object | ||
* | ||
* @param class-string<T> $class | ||
* @return T | ||
*/ | ||
public static function makeContextable(string $class, array $contextfulBindings = []) | ||
{ | ||
$reflectionClass = new ReflectionClass($class); | ||
|
||
$parameters = $reflectionClass->getConstructor()?->getParameters() ?? []; | ||
|
||
$contextfulArguments = collect($parameters) | ||
->mapWithKeys(function (ReflectionParameter $p) use ($contextfulBindings) { | ||
$parameterClass = $p->getType() instanceof ReflectionNamedType | ||
? $p->getType()->getName() | ||
: null; | ||
|
||
return $parameterClass && isset($contextfulBindings[$parameterClass]) ? [ | ||
$p->name => $contextfulBindings[$parameterClass], | ||
] : []; | ||
}) | ||
->all(); | ||
|
||
return app()->make($class, $contextfulArguments); | ||
} | ||
} |
Oops, something went wrong.