Skip to content

Commit

Permalink
Merge branch '7.x' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed Aug 14, 2020
2 parents 98d27f9 + 8f22cab commit 1a14a66
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 8 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
"nyholm/psr7": "Required to use PSR-7 bridging features (^1.2).",
"pda/pheanstalk": "Required to use the beanstalk queue driver (^4.0).",
"phpunit/phpunit": "Required to use assertions and run tests (^8.4|^9.0).",
"predis/predis": "Required to use the predis connector (^1.1.2).",
"psr/http-message": "Required to allow Storage::put to accept a StreamInterface (^1.0).",
"pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^4.0).",
"symfony/cache": "Required to PSR-6 cache bridge (^5.1).",
Expand Down
32 changes: 32 additions & 0 deletions src/Illuminate/Http/Concerns/InteractsWithInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ public function hasAny($keys)
return Arr::hasAny($input, $keys);
}

/**
* Apply the callback if the request contains the given input item key.
*
* @param string $key
* @param callable $callback
* @return $this|mixed
*/
public function whenHas($key, callable $callback)
{
if ($this->has($key)) {
return $callback(data_get($this->all(), $key)) ?: $this;
}

return $this;
}

/**
* Determine if the request contains a non-empty value for an input item.
*
Expand Down Expand Up @@ -163,6 +179,22 @@ public function anyFilled($keys)
return false;
}

/**
* Apply the callback if the request contains a non-empty value for the given input item key.
*
* @param string $key
* @param callable $callback
* @return $this|mixed
*/
public function whenFilled($key, callable $callback)
{
if ($this->filled($key)) {
return $callback(data_get($this->all(), $key)) ?: $this;
}

return $this;
}

/**
* Determine if the request is missing a given input item key.
*
Expand Down
3 changes: 0 additions & 3 deletions src/Illuminate/Redis/Connections/PredisClusterConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace Illuminate\Redis\Connections;

/**
* @deprecated Predis is no longer maintained by its original author
*/
class PredisClusterConnection extends PredisConnection
{
//
Expand Down
1 change: 0 additions & 1 deletion src/Illuminate/Redis/Connections/PredisConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

/**
* @mixin \Predis\Client
* @deprecated Predis is no longer maintained by its original author
*/
class PredisConnection extends Connection implements ConnectionContract
{
Expand Down
3 changes: 0 additions & 3 deletions src/Illuminate/Redis/Connectors/PredisConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
use Illuminate\Support\Arr;
use Predis\Client;

/**
* @deprecated Predis is no longer maintained by its original author
*/
class PredisConnector implements Connector
{
/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Redis/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"suggest": {
"ext-redis": "Required to use the phpredis connector (^4.0|^5.0).",
"predis/predis": "Required to use the predis connector (^1.0)."
"predis/predis": "Required to use the predis connector (^1.1.2)."
},
"extra": {
"branch-alias": {
Expand Down
56 changes: 56 additions & 0 deletions tests/Http/HttpRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,62 @@ public function testHasMethod()
$this->assertTrue($request->has('foo.baz'));
}

public function testWhenHasMethod()
{
$request = Request::create('/', 'GET', ['name' => 'Taylor', 'age' => '', 'city' => null]);

$name = $age = $city = $foo = false;

$request->whenHas('name', function ($value) use (&$name) {
$name = $value;
});

$request->whenHas('age', function ($value) use (&$age) {
$age = $value;
});

$request->whenHas('city', function ($value) use (&$city) {
$city = $value;
});

$request->whenHas('foo', function () use (&$foo) {
$foo = 'test';
});

$this->assertSame('Taylor', $name);
$this->assertSame('', $age);
$this->assertNull($city);
$this->assertFalse($foo);
}

public function testWhenFilledMethod()
{
$request = Request::create('/', 'GET', ['name' => 'Taylor', 'age' => '', 'city' => null]);

$name = $age = $city = $foo = false;

$request->whenFilled('name', function ($value) use (&$name) {
$name = $value;
});

$request->whenFilled('age', function ($value) use (&$age) {
$age = 'test';
});

$request->whenFilled('city', function ($value) use (&$city) {
$city = 'test';
});

$request->whenFilled('foo', function () use (&$foo) {
$foo = 'test';
});

$this->assertSame('Taylor', $name);
$this->assertFalse($age);
$this->assertFalse($city);
$this->assertFalse($foo);
}

public function testMissingMethod()
{
$request = Request::create('/', 'GET', ['name' => 'Taylor', 'age' => '', 'city' => null]);
Expand Down

0 comments on commit 1a14a66

Please sign in to comment.