46 lines
1.0 KiB
PHP
Raw Normal View History

2023-07-15 10:16:32 +08:00
<?php
2023-07-17 09:56:51 +08:00
2023-07-15 10:16:32 +08:00
namespace GuzzleHttp\Command\Guzzle\RequestLocation;
use GuzzleHttp\Command\CommandInterface;
use GuzzleHttp\Command\Guzzle\Parameter;
use GuzzleHttp\Psr7;
use Psr\Http\Message\MessageInterface;
use Psr\Http\Message\RequestInterface;
/**
* Adds a body to a request
*/
class BodyLocation extends AbstractLocation
{
/**
* Set the name of the location
*
* @param string $locationName
*/
public function __construct($locationName = 'body')
{
parent::__construct($locationName);
}
/**
* @return MessageInterface
*/
public function visit(
CommandInterface $command,
RequestInterface $request,
Parameter $param
) {
$oldValue = $request->getBody()->getContents();
$value = $command[$param->getName()];
2023-07-17 09:56:51 +08:00
$value = $param->getName().'='.$param->filter($value);
2023-07-15 10:16:32 +08:00
if ($oldValue !== '') {
2023-07-17 09:56:51 +08:00
$value = $oldValue.'&'.$value;
2023-07-15 10:16:32 +08:00
}
return $request->withBody(Psr7\Utils::streamFor($value));
}
}