8000 [HttpClient][Contracts] introduce component and related contracts by nicolas-grekas · Pull Request #30413 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpClient][Contracts] introduce component and related contracts #30413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"psr/link": "^1.0",
"psr/log": "~1.0",
"psr/simple-cache": "^1.0",
"symfony/contracts": "^1.0.2",
"symfony/contracts": "^1.1",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-intl-icu": "~1.0",
"symfony/polyfill-intl-idn": "^1.10",
Expand All @@ -55,6 +55,7 @@
"symfony/finder": "self.version",
"symfony/form": "self.version",
"symfony/framework-bundle": "self.version",
"symfony/http-client": "self.version",
"symfony/http-foundation": "self.version",
"symfony/http-kernel": "self.version",
"symfony/inflector": "self.version",
Expand Down Expand Up @@ -101,8 +102,10 @@
"doctrine/reflection": "~1.0",
"doctrine/doctrine-bundle": "~1.4",
"monolog/monolog": "~1.11",
"nyholm/psr7": "^1.0",
"ocramius/proxy-manager": "~0.4|~1.0|~2.0",
"predis/predis": "~1.1",
"psr/http-client": "^1.0",
"egulias/email-validator": "~1.2,>=1.2.8|~2.0",
"symfony/phpunit-bridge": "~3.4|~4.0",
"symfony/security-acl": "~2.8|~3.0",
Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Component/HttpClient/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CHANGELOG
=========

4.3.0
-----

* added the component
79 changes: 79 additions & 0 deletions src/Symfony/Component/HttpClient/Chunk/DataChunk.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\HttpClient\Chunk;

use Symfony\Contracts\HttpClient\ChunkInterface;

/**
* @author Nicolas Grekas <p@tchwork.com>
*
* @internal
*/
class DataChunk implements ChunkInterface
{
private $offset;
private $content;

public function __construct(int $offset = 0, string $content = '')
{
$this->offset = $offset;
$this->content = $content;
}

/**
* {@inheritdoc}
*/
public function isTimeout(): bool
{
return false;
}

/**
* {@inheritdoc}
*/
public function isFirst(): bool
{
return false;
}

/**
* {@inheritdoc}
*/
public function isLast(): bool
{
return false;
}

/**
* {@inheritdoc}
*/
public function getContent(): string
{
return $this->content;
}

/**
* {@inheritdoc}
*/
public function getOffset(): int
{
return $this->offset;
}

/**
* {@inheritdoc}
*/
public function getError(): ?string
{
return null;
}
}
106 changes: 106 additions & 0 deletions src/Symfony/Component/HttpClient/Chunk/ErrorChunk.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\HttpClient\Chunk;

use Symfony\Component\HttpClient\Exception\TransportException;
use Symfony\Contracts\HttpClient\ChunkInterface;

/**
* @author Nicolas Grekas <p@tchwork.com>
*
* @internal
*/
class ErrorChunk implements ChunkInterface
{
protected $didThrow;

private $offset;
private $errorMessage;
private $error;

/**
* @param bool &$didThrow Allows monitoring when the $error has been thrown or not
*/
public function __construct(bool &$didThrow, int $offset, \Throwable $error = null)
{
$didThrow = false;
$this->didThrow = &$didThrow;
$this->offset = $offset;
$this->error = $error;
$this->errorMessage = null !== $error ? $error->getMessage() : 'Reading from the response stream reached the inactivity timeout.';
}

/**
* {@inheritdoc}
*/
public function isTimeout(): bool
{
$this->didThrow = true;

if (null !== $this->error) {
throw new TransportException($this->errorMessage, 0, $this->error);
}

return true;
}

/**
* {@inheritdoc}
*/
public function isFirst(): bool
{
$this->di 10000 dThrow = true;
throw new TransportException($this->errorMessage, 0, $this->error);
}

/**
* {@inheritdoc}
*/
public function isLast(): bool
{
$this->didThrow = true;
throw new TransportException($this->errorMessage, 0, $this->error);
}

/**
* {@inheritdoc}
*/
public function getContent(): string
{
$this->didThrow = true;
throw new TransportException($this->errorMessage, 0, $this->error);
}

/**
* {@inheritdoc}
*/
public function getOffset(): int
{
return $this->offset;
}

/**
* {@inheritdoc}
*/
public function getError(): ?string
{
return $this->errorMessage;
}

public function __destruct()
{
if (!$this->didThrow) {
$this->didThrow = true;
throw new TransportException($this->errorMessage, 0, $this->error);
}
}
}
28 changes: 28 additions & 0 deletions src/Symfony/Component/HttpClient/Chunk/FirstChunk.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\HttpClient\Chunk;

/**
* @author Nicolas Grekas <p@tchwork.com>
*
* @internal
*/
class FirstChunk extends DataChunk
{
/**
* {@inheritdoc}
*/
public function isFirst(): bool
{
return true;
}
}
28 changes: 28 additions & 0 deletions src/Symfony/Component/HttpClient/Chunk/LastChunk.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\HttpClient\Chunk;

/**
* @author Nicolas Grekas <p@tchwork.com>
*
* @internal
*/
class LastChunk extends DataChunk
{
/**
* {@inheritdoc}
*/
public function isLast(): bool
{
return true;
}
}
Loading
0