Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ git tag $VERSION
git push origin --tags

# Tag Components
for REMOTE in auth broadcasting bus cache collections conditionable config console container contracts cookie database encryption events filesystem hashing http json-schema log macroable mail notifications pagination pipeline process queue redis routing session support testing translation validation view
for REMOTE in auth broadcasting bus cache collections conditionable config console container contracts cookie database encryption events filesystem hashing http json-schema log macroable mail notifications pagination pipeline process queue reflections redis routing session support testing translation validation view
do
echo ""
echo ""
Expand Down
2 changes: 2 additions & 0 deletions bin/split.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ remote pagination [email protected]:illuminate/pagination.git
remote pipeline [email protected]:illuminate/pipeline.git
remote process [email protected]:illuminate/process.git
remote queue [email protected]:illuminate/queue.git
remote reflections [email protected]:illuminate/reflections.git
remote redis [email protected]:illuminate/redis.git
remote routing [email protected]:illuminate/routing.git
remote session [email protected]:illuminate/session.git
Expand Down Expand Up @@ -79,6 +80,7 @@ split 'src/Illuminate/Pagination' pagination
split 'src/Illuminate/Pipeline' pipeline
split 'src/Illuminate/Process' process
split 'src/Illuminate/Queue' queue
split 'src/Illuminate/Reflections' reflections
split 'src/Illuminate/Redis' redis
split 'src/Illuminate/Routing' routing
split 'src/Illuminate/Session' session
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"illuminate/pipeline": "self.version",
"illuminate/process": "self.version",
"illuminate/queue": "self.version",
"illuminate/reflections": "self.version",
"illuminate/redis": "self.version",
"illuminate/routing": "self.version",
"illuminate/session": "self.version",
Expand Down Expand Up @@ -143,6 +144,7 @@
"src/Illuminate/Filesystem/functions.php",
"src/Illuminate/Foundation/helpers.php",
"src/Illuminate/Log/functions.php",
"src/Illuminate/Reflections/helpers.php",
"src/Illuminate/Support/functions.php",
"src/Illuminate/Support/helpers.php"
],
Expand All @@ -151,7 +153,8 @@
"Illuminate\\Support\\": [
"src/Illuminate/Macroable/",
"src/Illuminate/Collections/",
"src/Illuminate/Conditionable/"
"src/Illuminate/Conditionable/",
"src/Illuminate/Reflections/"
]
}
},
Expand Down
39 changes: 3 additions & 36 deletions src/Illuminate/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@
use Illuminate\Contracts\Container\Container as ContainerContract;
use Illuminate\Contracts\Container\ContextualAttribute;
use Illuminate\Contracts\Container\SelfBuilding;
use Illuminate\Support\Traits\ReflectsClosures;
use LogicException;
use ReflectionAttribute;
use ReflectionClass;
use ReflectionException;
use ReflectionFunction;
use ReflectionIntersectionType;
use ReflectionParameter;
use ReflectionUnionType;
use TypeError;

class Container implements ArrayAccess, ContainerContract
{
use ReflectsClosures;

/**
* The current globally available container (if any).
*
Expand Down Expand Up @@ -563,40 +564,6 @@ protected function bindBasedOnClosureReturnTypes($abstract, $concrete = null, $s
}
}

/**
* Get the class names / types of the return type of the given Closure.
*
* @return list<class-string>
*
* @throws \ReflectionException
*/
protected function closureReturnTypes(Closure $closure)
{
$reflection = new ReflectionFunction($closure);

if ($reflection->getReturnType() === null ||
$reflection->getReturnType() instanceof ReflectionIntersectionType) {
return [];
}

$types = $reflection->getReturnType() instanceof ReflectionUnionType
? $reflection->getReturnType()->getTypes()
: [$reflection->getReturnType()];

$returnTypes = [];

foreach ($types as $type) {
if ($type->isBuiltin() ||
in_array($type->getName(), ['static', 'self'])) {
continue;
}

$returnTypes[] = $type->getName();
}

return $returnTypes;
}

/**
* "Extend" an abstract type in the container.
*
Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Container/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"require": {
"php": "^8.2",
"illuminate/contracts": "^12.0",
"illuminate/reflections": "^12.0",
"psr/container": "^1.1.1|^2.0.1",
"symfony/polyfill-php84": "^1.33",
"symfony/polyfill-php85": "^1.33"
Expand Down
38 changes: 38 additions & 0 deletions src/Illuminate/Reflections/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "illuminate/reflections",
"description": "The Illuminate Reflections package.",
"license": "MIT",
"homepage": "https://laravel.com",
"support": {
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"authors": [
{
"name": "Taylor Otwell",
"email": "[email protected]"
}
],
"require": {
"php": "^8.2",
"illuminate/contracts": "^12.0",
"illuminate/collections": "^12.0"
},
"autoload": {
"psr-4": {
"Illuminate\\Support\\": ""
},
"files": [
"helpers.php"
]
},
"extra": {
"branch-alias": {
"dev-master": "12.x-dev"
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev"
}
97 changes: 97 additions & 0 deletions src/Illuminate/Reflections/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

use Illuminate\Support\Traits\ReflectsClosures;

if (! function_exists('lazy')) {
/**
* Create a lazy instance.
*
* @template TValue of object
*
* @param class-string<TValue>|(\Closure(TValue): mixed) $class
* @param (\Closure(TValue): mixed)|int $callback
* @param int $options
* @param array<string, mixed> $eager
* @return TValue
*/
function lazy($class, $callback = 0, $options = 0, $eager = [])
{
static $closureReflector;

$closureReflector ??= new class
{
use ReflectsClosures;

public function typeFromParameter($callback)
{
return $this->firstClosureParameterType($callback);
}
};

[$class, $callback, $options] = is_string($class)
? [$class, $callback, $options]
: [$closureReflector->typeFromParameter($class), $class, $callback ?: $options];

$reflectionClass = new ReflectionClass($class);

$instance = $reflectionClass->newLazyGhost(function ($instance) use ($callback) {
$result = $callback($instance);

if (is_array($result)) {
$instance->__construct(...$result);
}
}, $options);

foreach ($eager as $property => $value) {
$reflectionClass->getProperty($property)->setRawValueWithoutLazyInitialization($instance, $value);
}

return $instance;
}
}

if (! function_exists('proxy')) {
/**
* Create a lazy proxy instance.
*
* @template TValue of object
*
* @param class-string<TValue>|(\Closure(TValue): TValue) $class
* @param (\Closure(TValue): TValue)|int $callback
* @param int $options
* @param array<string, mixed> $eager
* @return TValue
*/
function proxy($class, $callback = 0, $options = 0, $eager = [])
{
static $closureReflector;

$closureReflector = new class
{
use ReflectsClosures;

public function get($callback)
{
return $this->closureReturnTypes($callback)[0] ?? $this->firstClosureParameterType($callback);
}
};

[$class, $callback, $options] = is_string($class)
? [$class, $callback, $options]
: [$closureReflector->get($class), $class, $callback ?: $options];

$reflectionClass = new ReflectionClass($class);

$proxy = $reflectionClass->newLazyProxy(function () use ($callback, $eager, &$proxy) {
$instance = $callback($proxy, $eager);

return $instance;
}, $options);

foreach ($eager as $property => $value) {
$reflectionClass->getProperty($property)->setRawValueWithoutLazyInitialization($proxy, $value);
}

return $proxy;
}
}
1 change: 1 addition & 0 deletions src/Illuminate/Support/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"illuminate/conditionable": "^12.0",
"illuminate/contracts": "^12.0",
"illuminate/macroable": "^12.0",
"illuminate/reflections": "^12.0",
"nesbot/carbon": "^3.8.4",
"symfony/polyfill-php83": "^1.33",
"symfony/polyfill-php85": "^1.33",
Expand Down
95 changes: 0 additions & 95 deletions src/Illuminate/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Illuminate\Support\Sleep;
use Illuminate\Support\Str;
use Illuminate\Support\Stringable as SupportStringable;
use Illuminate\Support\Traits\ReflectsClosures;

if (! function_exists('append_config')) {
/**
Expand Down Expand Up @@ -197,54 +196,6 @@ function literal(...$arguments)
}
}

if (! function_exists('lazy')) {
/**
* Create a lazy instance.
*
* @template TValue of object
*
* @param class-string<TValue>|(\Closure(TValue): mixed) $class
* @param (\Closure(TValue): mixed)|int $callback
* @param int $options
* @param array<string, mixed> $eager
* @return TValue
*/
function lazy($class, $callback = 0, $options = 0, $eager = [])
{
static $closureReflector;

$closureReflector ??= new class
{
use ReflectsClosures;

public function typeFromParameter($callback)
{
return $this->firstClosureParameterType($callback);
}
};

[$class, $callback, $options] = is_string($class)
? [$class, $callback, $options]
: [$closureReflector->typeFromParameter($class), $class, $callback ?: $options];

$reflectionClass = new ReflectionClass($class);

$instance = $reflectionClass->newLazyGhost(function ($instance) use ($callback) {
$result = $callback($instance);

if (is_array($result)) {
$instance->__construct(...$result);
}
}, $options);

foreach ($eager as $property => $value) {
$reflectionClass->getProperty($property)->setRawValueWithoutLazyInitialization($instance, $value);
}

return $instance;
}
}

if (! function_exists('object_get')) {
/**
* Get an item from an object using "dot" notation.
Expand Down Expand Up @@ -344,52 +295,6 @@ function preg_replace_array($pattern, array $replacements, $subject): string
}
}

if (! function_exists('proxy')) {
/**
* Create a lazy proxy instance.
*
* @template TValue of object
*
* @param class-string<TValue>|(\Closure(TValue): TValue) $class
* @param (\Closure(TValue): TValue)|int $callback
* @param int $options
* @param array<string, mixed> $eager
* @return TValue
*/
function proxy($class, $callback = 0, $options = 0, $eager = [])
{
static $closureReflector;

$closureReflector = new class
{
use ReflectsClosures;

public function get($callback)
{
return $this->closureReturnTypes($callback)[0] ?? $this->firstClosureParameterType($callback);
}
};

[$class, $callback, $options] = is_string($class)
? [$class, $callback, $options]
: [$closureReflector->get($class), $class, $callback ?: $options];

$reflectionClass = new ReflectionClass($class);

$proxy = $reflectionClass->newLazyProxy(function () use ($callback, $eager, &$proxy) {
$instance = $callback($proxy, $eager);

return $instance;
}, $options);

foreach ($eager as $property => $value) {
$reflectionClass->getProperty($property)->setRawValueWithoutLazyInitialization($proxy, $value);
}

return $proxy;
}
}

if (! function_exists('retry')) {
/**
* Retry an operation a given number of times.
Expand Down
Loading