20220717
This commit is contained in:
60
vendor/illuminate/conditionable/HigherOrderWhenProxy.php
vendored
Normal file
60
vendor/illuminate/conditionable/HigherOrderWhenProxy.php
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Support;
|
||||
|
||||
class HigherOrderWhenProxy
|
||||
{
|
||||
/**
|
||||
* The target being conditionally operated on.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $target;
|
||||
|
||||
/**
|
||||
* The condition for proxying.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $condition;
|
||||
|
||||
/**
|
||||
* Create a new proxy instance.
|
||||
*
|
||||
* @param mixed $target
|
||||
* @param bool $condition
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($target, $condition)
|
||||
{
|
||||
$this->target = $target;
|
||||
$this->condition = $condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy accessing an attribute onto the target.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
return $this->condition
|
||||
? $this->target->{$key}
|
||||
: $this->target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy a method call on the target.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
return $this->condition
|
||||
? $this->target->{$method}(...$parameters)
|
||||
: $this->target;
|
||||
}
|
||||
}
|
21
vendor/illuminate/conditionable/LICENSE.md
vendored
Normal file
21
vendor/illuminate/conditionable/LICENSE.md
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Taylor Otwell
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
65
vendor/illuminate/conditionable/Traits/Conditionable.php
vendored
Normal file
65
vendor/illuminate/conditionable/Traits/Conditionable.php
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Support\Traits;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\HigherOrderWhenProxy;
|
||||
|
||||
trait Conditionable
|
||||
{
|
||||
/**
|
||||
* Apply the callback if the given "value" is (or resolves to) truthy.
|
||||
*
|
||||
* @template TWhenParameter
|
||||
* @template TWhenReturnType
|
||||
*
|
||||
* @param (\Closure($this): TWhenParameter)|TWhenParameter $value
|
||||
* @param (callable($this, TWhenParameter): TWhenReturnType)|null $callback
|
||||
* @param (callable($this, TWhenParameter): TWhenReturnType)|null $default
|
||||
* @return $this|TWhenReturnType
|
||||
*/
|
||||
public function when($value, callable $callback = null, callable $default = null)
|
||||
{
|
||||
$value = $value instanceof Closure ? $value($this) : $value;
|
||||
|
||||
if (func_num_args() === 1) {
|
||||
return new HigherOrderWhenProxy($this, $value);
|
||||
}
|
||||
|
||||
if ($value) {
|
||||
return $callback($this, $value) ?? $this;
|
||||
} elseif ($default) {
|
||||
return $default($this, $value) ?? $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the callback if the given "value" is (or resolves to) falsy.
|
||||
*
|
||||
* @template TUnlessParameter
|
||||
* @template TUnlessReturnType
|
||||
*
|
||||
* @param (\Closure($this): TUnlessParameter)|TUnlessParameter $value
|
||||
* @param (callable($this, TUnlessParameter): TUnlessReturnType)|null $callback
|
||||
* @param (callable($this, TUnlessParameter): TUnlessReturnType)|null $default
|
||||
* @return $this|TUnlessReturnType
|
||||
*/
|
||||
public function unless($value, callable $callback = null, callable $default = null)
|
||||
{
|
||||
$value = $value instanceof Closure ? $value($this) : $value;
|
||||
|
||||
if (func_num_args() === 1) {
|
||||
return new HigherOrderWhenProxy($this, ! $value);
|
||||
}
|
||||
|
||||
if (! $value) {
|
||||
return $callback($this, $value) ?? $this;
|
||||
} elseif ($default) {
|
||||
return $default($this, $value) ?? $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
33
vendor/illuminate/conditionable/composer.json
vendored
Normal file
33
vendor/illuminate/conditionable/composer.json
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "illuminate/conditionable",
|
||||
"description": "The Illuminate Conditionable 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": "taylor@laravel.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^8.0.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Illuminate\\Support\\": ""
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "9.x-dev"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
Reference in New Issue
Block a user