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

[6.x] Remove Container dependency on Illuminate\Support #30518

Merged
merged 2 commits into from Nov 6, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -75,7 +75,7 @@ protected static function callClass($container, $target, array $parameters = [],
protected static function callBoundMethod($container, $callback, $default)
{
if (! is_array($callback)) {
return value($default);
return Util::unwrapIfClosure($default);
}

// Here we need to turn the array callable into a Class@method string we can use to
@@ -87,7 +87,7 @@ protected static function callBoundMethod($container, $callback, $default)
return $container->callMethodBinding($method, $callback[0]);
}

return value($default);
return Util::unwrapIfClosure($default);
}

/**
@@ -7,7 +7,6 @@
use Exception;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Contracts\Container\Container as ContainerContract;
use Illuminate\Support\Arr;
use LogicException;
use ReflectionClass;
use ReflectionException;
@@ -144,7 +143,7 @@ public function when($concrete)
{
$aliases = [];

foreach (Arr::wrap($concrete) as $c) {
foreach (Util::arrayWrap($concrete) as $c) {
$aliases[] = $this->getAlias($c);
}

@@ -4,7 +4,6 @@

use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Container\ContextualBindingBuilder as ContextualBindingBuilderContract;
use Illuminate\Support\Arr;

class ContextualBindingBuilder implements ContextualBindingBuilderContract
{
@@ -63,7 +62,7 @@ public function needs($abstract)
*/
public function give($implementation)
{
foreach (Arr::wrap($this->concrete) as $concrete) {
foreach (Util::arrayWrap($this->concrete) as $concrete) {
$this->container->addContextualBinding($concrete, $this->needs, $implementation);
}
}
@@ -0,0 +1,36 @@
<?php

namespace Illuminate\Container;

class Util
{
/**
* If the given value is not an array and not null, wrap it in one.
*
* From Arr::wrap() in Illuminate\Support.
*
* @param mixed $value
* @return array
*/
public static function arrayWrap($value)
{
if (is_null($value)) {
return [];
}

return is_array($value) ? $value : [$value];
}

/**
* Return the default value of the given value.
*
* From global value() helper in Illuminate\Support.
*
* @param mixed $value
* @return mixed
*/
public static function unwrapIfClosure($value)
{
return $value instanceof \Closure ? $value() : $value;
}
}
@@ -16,7 +16,6 @@
"require": {
"php": "^7.2",
"illuminate/contracts": "^6.0",
"illuminate/support": "^6.0",
"psr/container": "^1.0"
},
"autoload": {
@@ -0,0 +1,42 @@
<?php

namespace Illuminate\Tests\Container;

use Illuminate\Container\Util;
use PHPUnit\Framework\TestCase;

class UtilTest extends TestCase
{
public function testUnwrapIfClosure()
{
$this->assertSame('foo', Util::unwrapIfClosure('foo'));
$this->assertSame('foo', UtiL::unwrapIfClosure(function () {

This comment has been minimized.

Copy link
@paulredmond

paulredmond Nov 13, 2019

Contributor

@iansltx I noticed a capital L on this line.

Actual: UtiL::unwrapIfClosure
Expected: Util::unwrapIfClosure

// @driesvints

This comment has been minimized.

Copy link
@iansltx

iansltx Nov 13, 2019

Author Contributor

Whoops.

Mind PR'ing a typo fix here, as this has already been merged?

return 'foo';
}));
}

public function testArrayWrap()
{
$string = 'a';
$array = ['a'];
$object = new \stdClass;
$object->value = 'a';
$this->assertEquals(['a'], Util::arrayWrap($string));
$this->assertEquals($array, Util::arrayWrap($array));
$this->assertEquals([$object], Util::arrayWrap($object));
$this->assertEquals([], Util::arrayWrap(null));
$this->assertEquals([null], Util::arrayWrap([null]));
$this->assertEquals([null, null], Util::arrayWrap([null, null]));
$this->assertEquals([''], Util::arrayWrap(''));
$this->assertEquals([''], Util::arrayWrap(['']));
$this->assertEquals([false], Util::arrayWrap(false));
$this->assertEquals([false], Util::arrayWrap([false]));
$this->assertEquals([0], Util::arrayWrap(0));

$obj = new \stdClass;
$obj->value = 'a';
$obj = unserialize(serialize($obj));
$this->assertEquals([$obj], Util::arrayWrap($obj));
$this->assertSame($obj, Util::arrayWrap($obj)[0]);
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.