Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wordpres.../vendor_p.../guzzleht.../guzzle/src
File: HandlerStack.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace YoastSEO_Vendor\GuzzleHttp;
[2] Fix | Delete
[3] Fix | Delete
use YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface;
[4] Fix | Delete
use YoastSEO_Vendor\Psr\Http\Message\RequestInterface;
[5] Fix | Delete
use YoastSEO_Vendor\Psr\Http\Message\ResponseInterface;
[6] Fix | Delete
/**
[7] Fix | Delete
* Creates a composed Guzzle handler function by stacking middlewares on top of
[8] Fix | Delete
* an HTTP handler function.
[9] Fix | Delete
*
[10] Fix | Delete
* @final
[11] Fix | Delete
*/
[12] Fix | Delete
class HandlerStack
[13] Fix | Delete
{
[14] Fix | Delete
/**
[15] Fix | Delete
* @var (callable(RequestInterface, array): PromiseInterface)|null
[16] Fix | Delete
*/
[17] Fix | Delete
private $handler;
[18] Fix | Delete
/**
[19] Fix | Delete
* @var array{(callable(callable(RequestInterface, array): PromiseInterface): callable), (string|null)}[]
[20] Fix | Delete
*/
[21] Fix | Delete
private $stack = [];
[22] Fix | Delete
/**
[23] Fix | Delete
* @var (callable(RequestInterface, array): PromiseInterface)|null
[24] Fix | Delete
*/
[25] Fix | Delete
private $cached;
[26] Fix | Delete
/**
[27] Fix | Delete
* Creates a default handler stack that can be used by clients.
[28] Fix | Delete
*
[29] Fix | Delete
* The returned handler will wrap the provided handler or use the most
[30] Fix | Delete
* appropriate default handler for your system. The returned HandlerStack has
[31] Fix | Delete
* support for cookies, redirects, HTTP error exceptions, and preparing a body
[32] Fix | Delete
* before sending.
[33] Fix | Delete
*
[34] Fix | Delete
* The returned handler stack can be passed to a client in the "handler"
[35] Fix | Delete
* option.
[36] Fix | Delete
*
[37] Fix | Delete
* @param (callable(RequestInterface, array): PromiseInterface)|null $handler HTTP handler function to use with the stack. If no
[38] Fix | Delete
* handler is provided, the best handler for your
[39] Fix | Delete
* system will be utilized.
[40] Fix | Delete
*/
[41] Fix | Delete
public static function create(callable $handler = null) : self
[42] Fix | Delete
{
[43] Fix | Delete
$stack = new self($handler ?: \YoastSEO_Vendor\GuzzleHttp\Utils::chooseHandler());
[44] Fix | Delete
$stack->push(\YoastSEO_Vendor\GuzzleHttp\Middleware::httpErrors(), 'http_errors');
[45] Fix | Delete
$stack->push(\YoastSEO_Vendor\GuzzleHttp\Middleware::redirect(), 'allow_redirects');
[46] Fix | Delete
$stack->push(\YoastSEO_Vendor\GuzzleHttp\Middleware::cookies(), 'cookies');
[47] Fix | Delete
$stack->push(\YoastSEO_Vendor\GuzzleHttp\Middleware::prepareBody(), 'prepare_body');
[48] Fix | Delete
return $stack;
[49] Fix | Delete
}
[50] Fix | Delete
/**
[51] Fix | Delete
* @param (callable(RequestInterface, array): PromiseInterface)|null $handler Underlying HTTP handler.
[52] Fix | Delete
*/
[53] Fix | Delete
public function __construct(callable $handler = null)
[54] Fix | Delete
{
[55] Fix | Delete
$this->handler = $handler;
[56] Fix | Delete
}
[57] Fix | Delete
/**
[58] Fix | Delete
* Invokes the handler stack as a composed handler
[59] Fix | Delete
*
[60] Fix | Delete
* @return ResponseInterface|PromiseInterface
[61] Fix | Delete
*/
[62] Fix | Delete
public function __invoke(\YoastSEO_Vendor\Psr\Http\Message\RequestInterface $request, array $options)
[63] Fix | Delete
{
[64] Fix | Delete
$handler = $this->resolve();
[65] Fix | Delete
return $handler($request, $options);
[66] Fix | Delete
}
[67] Fix | Delete
/**
[68] Fix | Delete
* Dumps a string representation of the stack.
[69] Fix | Delete
*
[70] Fix | Delete
* @return string
[71] Fix | Delete
*/
[72] Fix | Delete
public function __toString()
[73] Fix | Delete
{
[74] Fix | Delete
$depth = 0;
[75] Fix | Delete
$stack = [];
[76] Fix | Delete
if ($this->handler !== null) {
[77] Fix | Delete
$stack[] = '0) Handler: ' . $this->debugCallable($this->handler);
[78] Fix | Delete
}
[79] Fix | Delete
$result = '';
[80] Fix | Delete
foreach (\array_reverse($this->stack) as $tuple) {
[81] Fix | Delete
++$depth;
[82] Fix | Delete
$str = "{$depth}) Name: '{$tuple[1]}', ";
[83] Fix | Delete
$str .= 'Function: ' . $this->debugCallable($tuple[0]);
[84] Fix | Delete
$result = "> {$str}\n{$result}";
[85] Fix | Delete
$stack[] = $str;
[86] Fix | Delete
}
[87] Fix | Delete
foreach (\array_keys($stack) as $k) {
[88] Fix | Delete
$result .= "< {$stack[$k]}\n";
[89] Fix | Delete
}
[90] Fix | Delete
return $result;
[91] Fix | Delete
}
[92] Fix | Delete
/**
[93] Fix | Delete
* Set the HTTP handler that actually returns a promise.
[94] Fix | Delete
*
[95] Fix | Delete
* @param callable(RequestInterface, array): PromiseInterface $handler Accepts a request and array of options and
[96] Fix | Delete
* returns a Promise.
[97] Fix | Delete
*/
[98] Fix | Delete
public function setHandler(callable $handler) : void
[99] Fix | Delete
{
[100] Fix | Delete
$this->handler = $handler;
[101] Fix | Delete
$this->cached = null;
[102] Fix | Delete
}
[103] Fix | Delete
/**
[104] Fix | Delete
* Returns true if the builder has a handler.
[105] Fix | Delete
*/
[106] Fix | Delete
public function hasHandler() : bool
[107] Fix | Delete
{
[108] Fix | Delete
return $this->handler !== null;
[109] Fix | Delete
}
[110] Fix | Delete
/**
[111] Fix | Delete
* Unshift a middleware to the bottom of the stack.
[112] Fix | Delete
*
[113] Fix | Delete
* @param callable(callable): callable $middleware Middleware function
[114] Fix | Delete
* @param string $name Name to register for this middleware.
[115] Fix | Delete
*/
[116] Fix | Delete
public function unshift(callable $middleware, string $name = null) : void
[117] Fix | Delete
{
[118] Fix | Delete
\array_unshift($this->stack, [$middleware, $name]);
[119] Fix | Delete
$this->cached = null;
[120] Fix | Delete
}
[121] Fix | Delete
/**
[122] Fix | Delete
* Push a middleware to the top of the stack.
[123] Fix | Delete
*
[124] Fix | Delete
* @param callable(callable): callable $middleware Middleware function
[125] Fix | Delete
* @param string $name Name to register for this middleware.
[126] Fix | Delete
*/
[127] Fix | Delete
public function push(callable $middleware, string $name = '') : void
[128] Fix | Delete
{
[129] Fix | Delete
$this->stack[] = [$middleware, $name];
[130] Fix | Delete
$this->cached = null;
[131] Fix | Delete
}
[132] Fix | Delete
/**
[133] Fix | Delete
* Add a middleware before another middleware by name.
[134] Fix | Delete
*
[135] Fix | Delete
* @param string $findName Middleware to find
[136] Fix | Delete
* @param callable(callable): callable $middleware Middleware function
[137] Fix | Delete
* @param string $withName Name to register for this middleware.
[138] Fix | Delete
*/
[139] Fix | Delete
public function before(string $findName, callable $middleware, string $withName = '') : void
[140] Fix | Delete
{
[141] Fix | Delete
$this->splice($findName, $withName, $middleware, \true);
[142] Fix | Delete
}
[143] Fix | Delete
/**
[144] Fix | Delete
* Add a middleware after another middleware by name.
[145] Fix | Delete
*
[146] Fix | Delete
* @param string $findName Middleware to find
[147] Fix | Delete
* @param callable(callable): callable $middleware Middleware function
[148] Fix | Delete
* @param string $withName Name to register for this middleware.
[149] Fix | Delete
*/
[150] Fix | Delete
public function after(string $findName, callable $middleware, string $withName = '') : void
[151] Fix | Delete
{
[152] Fix | Delete
$this->splice($findName, $withName, $middleware, \false);
[153] Fix | Delete
}
[154] Fix | Delete
/**
[155] Fix | Delete
* Remove a middleware by instance or name from the stack.
[156] Fix | Delete
*
[157] Fix | Delete
* @param callable|string $remove Middleware to remove by instance or name.
[158] Fix | Delete
*/
[159] Fix | Delete
public function remove($remove) : void
[160] Fix | Delete
{
[161] Fix | Delete
if (!\is_string($remove) && !\is_callable($remove)) {
[162] Fix | Delete
trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a callable or string to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__);
[163] Fix | Delete
}
[164] Fix | Delete
$this->cached = null;
[165] Fix | Delete
$idx = \is_callable($remove) ? 0 : 1;
[166] Fix | Delete
$this->stack = \array_values(\array_filter($this->stack, static function ($tuple) use($idx, $remove) {
[167] Fix | Delete
return $tuple[$idx] !== $remove;
[168] Fix | Delete
}));
[169] Fix | Delete
}
[170] Fix | Delete
/**
[171] Fix | Delete
* Compose the middleware and handler into a single callable function.
[172] Fix | Delete
*
[173] Fix | Delete
* @return callable(RequestInterface, array): PromiseInterface
[174] Fix | Delete
*/
[175] Fix | Delete
public function resolve() : callable
[176] Fix | Delete
{
[177] Fix | Delete
if ($this->cached === null) {
[178] Fix | Delete
if (($prev = $this->handler) === null) {
[179] Fix | Delete
throw new \LogicException('No handler has been specified');
[180] Fix | Delete
}
[181] Fix | Delete
foreach (\array_reverse($this->stack) as $fn) {
[182] Fix | Delete
/** @var callable(RequestInterface, array): PromiseInterface $prev */
[183] Fix | Delete
$prev = $fn[0]($prev);
[184] Fix | Delete
}
[185] Fix | Delete
$this->cached = $prev;
[186] Fix | Delete
}
[187] Fix | Delete
return $this->cached;
[188] Fix | Delete
}
[189] Fix | Delete
private function findByName(string $name) : int
[190] Fix | Delete
{
[191] Fix | Delete
foreach ($this->stack as $k => $v) {
[192] Fix | Delete
if ($v[1] === $name) {
[193] Fix | Delete
return $k;
[194] Fix | Delete
}
[195] Fix | Delete
}
[196] Fix | Delete
throw new \InvalidArgumentException("Middleware not found: {$name}");
[197] Fix | Delete
}
[198] Fix | Delete
/**
[199] Fix | Delete
* Splices a function into the middleware list at a specific position.
[200] Fix | Delete
*/
[201] Fix | Delete
private function splice(string $findName, string $withName, callable $middleware, bool $before) : void
[202] Fix | Delete
{
[203] Fix | Delete
$this->cached = null;
[204] Fix | Delete
$idx = $this->findByName($findName);
[205] Fix | Delete
$tuple = [$middleware, $withName];
[206] Fix | Delete
if ($before) {
[207] Fix | Delete
if ($idx === 0) {
[208] Fix | Delete
\array_unshift($this->stack, $tuple);
[209] Fix | Delete
} else {
[210] Fix | Delete
$replacement = [$tuple, $this->stack[$idx]];
[211] Fix | Delete
\array_splice($this->stack, $idx, 1, $replacement);
[212] Fix | Delete
}
[213] Fix | Delete
} elseif ($idx === \count($this->stack) - 1) {
[214] Fix | Delete
$this->stack[] = $tuple;
[215] Fix | Delete
} else {
[216] Fix | Delete
$replacement = [$this->stack[$idx], $tuple];
[217] Fix | Delete
\array_splice($this->stack, $idx, 1, $replacement);
[218] Fix | Delete
}
[219] Fix | Delete
}
[220] Fix | Delete
/**
[221] Fix | Delete
* Provides a debug string for a given callable.
[222] Fix | Delete
*
[223] Fix | Delete
* @param callable|string $fn Function to write as a string.
[224] Fix | Delete
*/
[225] Fix | Delete
private function debugCallable($fn) : string
[226] Fix | Delete
{
[227] Fix | Delete
if (\is_string($fn)) {
[228] Fix | Delete
return "callable({$fn})";
[229] Fix | Delete
}
[230] Fix | Delete
if (\is_array($fn)) {
[231] Fix | Delete
return \is_string($fn[0]) ? "callable({$fn[0]}::{$fn[1]})" : "callable(['" . \get_class($fn[0]) . "', '{$fn[1]}'])";
[232] Fix | Delete
}
[233] Fix | Delete
/** @var object $fn */
[234] Fix | Delete
return 'callable(' . \spl_object_hash($fn) . ')';
[235] Fix | Delete
}
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function