12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- 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);
- }
- /**
- * @param CommandInterface $command
- * @param RequestInterface $request
- * @param Parameter $param
- *
- * @return MessageInterface
- */
- public function visit(
- CommandInterface $command,
- RequestInterface $request,
- Parameter $param
- ) {
- $oldValue = $request->getBody()->getContents();
- $value = $command[$param->getName()];
- $value = $param->getName() . '=' . $param->filter($value);
- if ($oldValue !== '') {
- $value = $oldValue . '&' . $value;
- }
- return $request->withBody(Psr7\stream_for($value));
- }
- }
|