Skip to content

Commit 86b01ff

Browse files
[HttpClient] introduce the component
1 parent 14c9f88 commit 86b01ff

29 files changed

+2549
-0
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
80+
public function __toString()
81+
{
82+
return $this->content;
83+
}
84+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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 $throw = true;
25+
26+
private $offset;
27+
private $error;
28+
29+
public function __construct(int $offset, \Throwable $error = null)
30+
{
31+
$this->offset = $offset;
32+
$this->error = null !== $error ? [$error->getMessage(), null, null, $error] : ['Reading from the response stream reached the inactivity timeout.'];
33+
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
public function isTimeout(): bool
39+
{
40+
$this->throw = false;
41+
42+
if (1 < \count($this->error)) {
43+
throw new TransportException(...$this->error);
44+
}
45+
46+
return true;
47+
}
48+
49+
/**
50+
* {@inheritdoc}
51+
*/
52+
public function isFirst(): bool
53+
{
54+
$this->throw = false;
55+
throw new TransportException(...$this->error);
56+
}
57+
58+
/**
59+
* {@inheritdoc}
60+
*/
61+
public function isLast(): bool
62+
{
63+
$this->throw = false;
64+
throw new TransportException(...$this->error);
65+
}
66+
67+
/**
68+
* {@inheritdoc}
69+
*/
70+
public function getContent(): string
71+
{
72+
$this->throw = false;
73+
throw new TransportException(...$this->error);
74+
}
75+
76+
/**
77+
* {@inheritdoc}
78+
*/
79+
public function getOffset(): int
80+
{
81+
$this->offset;
82+
}
83+
84+
/**
85+
* {@inheritdoc}
86+
*/
87+
public function getError(): ?string
88+
{
89+
return $this->error[0];
90+
}
91+
92+
public function __toString()
93+
{
94+
return '';
95+
}
96+
97+
public function __destruct()
98+
{
99+
if ($this->throw) {
100+
$this->throw = false;
101+
throw new TransportException(...$this->error);
102+
}
103+
}
104+
}
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)