Skip to content

Commit eabe04c

Browse files
[HttpClient] introduce the component
1 parent 2fb0448 commit eabe04c

31 files changed

+3323
-1
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"psr/link": "^1.0",
2929
"psr/log": "~1.0",
3030
"psr/simple-cache": "^1.0",
31-
"symfony/contracts": "^1.0.2",
31+
"symfony/contracts": "^1.1",
3232
"symfony/polyfill-ctype": "~1.8",
3333
"symfony/polyfill-intl-icu": "~1.0",
3434
"symfony/polyfill-intl-idn": "^1.10",
@@ -55,6 +55,7 @@
5555
"symfony/finder": "self.version",
5656
"symfony/form": "self.version",
5757
"symfony/framework-bundle": "self.version",
58+
"symfony/http-client": "self.version",
5859
"symfony/http-foundation": "self.version",
5960
"symfony/http-kernel": "self.version",
6061
"symfony/inflector": "self.version",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CHANGELOG
2+
=========
3+
4+
4.3.0
5+
-----
6+
7+
* added the component
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpClient\Chunk;
13+
14+
use Symfony\Contracts\HttpClient\ChunkInterface;
15+
16+
/**
17+
* @author Nicolas Grekas <p@tchwork.com>
18+
*
19+
* @internal
20+
*/
21+
class DataChunk implements ChunkInterface
22+
{
23+
private $offset;
24+
private $content;
25+
26+
public function __construct(int $offset = 0, string $content = '')
27+
{
28+
$this->offset = $offset;
29+
$this->content = $content;
30+
}
31+
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
public function isTimeout(): bool
36+
{
37+
return false;
38+
}
39+
40+
/**
41+
* {@inheritdoc}
42+
*/
43+
public function isFirst(): bool
44+
{
45+
return false;
46+
}
47+
48+
/**
49+
* {@inheritdoc}
50+
*/
51+
public function isLast(): bool
52+
{
53+
return false;
54+
}
55+
56+
/**
57+
* {@inheritdoc}
58+
*/
59+
public function getContent(): string
60+
{
61+
return $this->content;
62+
}
63+
64+
/**
65+
* {@inheritdoc}
66+
*/
67+
public function getOffset(): int
68+
{
69+
return $this->offset;
70+
}
71+
72+
/**
73+
* {@inheritdoc}
74+
*/
75+
public function getError(): ?string
76+
{
77+
return null;
78+
}
79+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpClient\Chunk;
13+
14+
use Symfony\Component\HttpClient\Exception\TransportException;
15+
use Symfony\Contracts\HttpClient\ChunkInterface;
16+
17+
/**
18+
* @author Nicolas Grekas <p@tchwork.com>
19+
*
20+
* @internal
21+
*/
22+
class ErrorChunk implements ChunkInterface
23+
{
24+
protected $didThrow;
25+
26+
private $offset;
27+
private $errorMessage;
28+
private $error;
29+
30+
/**
31+
* @param bool &$didThrow Allows monitoring when the $error has been thrown or not
32+
*/
33+
public function __construct(bool &$didThrow, int $offset, \Throwable $error = null)
34+
{
35+
$didThrow = false;
36+
$this->didThrow = &$didThrow;
37+
$this->offset = $offset;
38+
$this->error = $error;
39+
$this->errorMessage = null !== $error ? $error->getMessage() : 'Reading from the response stream reached the inactivity timeout.';
40+
}
41+
42+
/**
43+
* {@inheritdoc}
44+
*/
45+
public function isTimeout(): bool
46+
{
47+
$this->didThrow = true;
48+
49+
if (null !== $this->error) {
50+
throw new TransportException($this->errorMessage, 0, $this->error);
51+
}
52+
53+
return true;
54+
}
55+
56+
/**
57+
* {@inheritdoc}
58+
*/
59+
public function isFirst(): bool
60+
{
61+
$this->didThrow = true;
62+
throw new TransportException($this->errorMessage, 0, $this->error);
63+
}
64+
65+
/**
66+
* {@inheritdoc}
67+
*/
68+
public function isLast(): bool
69+
{
70+
$this->didThrow = true;
71+
throw new TransportException($this->errorMessage, 0, $this->error);
72+
}
73+
74+
/**
75+
* {@inheritdoc}
76+
*/
77+
public function getContent(): string
78+
{
79+
$this->didThrow = true;
80+
throw new TransportException($this->errorMessage, 0, $this->error);
81+
}
82+
83+
/**
84+
* {@inheritdoc}
85+
*/
86+
public function getOffset(): int
87+
{
88+
return $this->offset;
89+
}
90+
91+
/**
92+
* {@inheritdoc}
93+
*/
94+
public function getError(): ?string
95+
{
96+
return $this->errorMessage;
97+
}
98+
99+
public function __destruct()
100+
{
101+
if (!$this->didThrow) {
102+
$this->didThrow = true;
103+
throw new TransportException($this->errorMessage, 0, $this->error);
104+
}
105+
}
106+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpClient\Chunk;
13+
14+
/**
15+
* @author Nicolas Grekas <p@tchwork.com>
16+
*
17+
* @internal
18+
*/
19+
class FirstChunk extends DataChunk
20+
{
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
public function isFirst(): bool
25+
{
26+
return true;
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpClient\Chunk;
13+
14+
/**
15+
* @author Nicolas Grekas <p@tchwork.com>
16+
*
17+
* @internal
18+
*/
19+
class LastChunk extends DataChunk
20+
{
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
public function isLast(): bool
25+
{
26+
return true;
27+
}
28+
}

0 commit comments

Comments
 (0)