mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-30 12:39:20 +03:00
v1.2.7.416
This commit is contained in:
parent
54e2645fcf
commit
3b27abbe9a
434 changed files with 51 additions and 72 deletions
|
|
@ -1,87 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Buzz\Client;
|
||||
|
||||
use Buzz\Message\MessageInterface;
|
||||
use Buzz\Message\RequestInterface;
|
||||
use Buzz\Util\CookieJar;
|
||||
use Buzz\Exception\ClientException;
|
||||
|
||||
class FileGetContents extends AbstractStream
|
||||
{
|
||||
/**
|
||||
* @var CookieJar
|
||||
*/
|
||||
protected $cookieJar;
|
||||
|
||||
/**
|
||||
* @param CookieJar|null $cookieJar
|
||||
*/
|
||||
public function __construct(CookieJar $cookieJar = null)
|
||||
{
|
||||
if ($cookieJar) {
|
||||
$this->setCookieJar($cookieJar);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CookieJar $cookieJar
|
||||
*/
|
||||
public function setCookieJar(CookieJar $cookieJar)
|
||||
{
|
||||
$this->cookieJar = $cookieJar;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CookieJar
|
||||
*/
|
||||
public function getCookieJar()
|
||||
{
|
||||
return $this->cookieJar;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ClientInterface
|
||||
*
|
||||
* @throws ClientException If file_get_contents() fires an error
|
||||
*/
|
||||
public function send(RequestInterface $request, MessageInterface $response)
|
||||
{
|
||||
if ($cookieJar = $this->getCookieJar()) {
|
||||
$cookieJar->clearExpiredCookies();
|
||||
$cookieJar->addCookieHeaders($request);
|
||||
}
|
||||
|
||||
$context = stream_context_create($this->getStreamContextArray($request));
|
||||
$url = $request->getHost().$request->getResource();
|
||||
|
||||
$level = error_reporting(0);
|
||||
$content = file_get_contents($url, 0, $context);
|
||||
error_reporting($level);
|
||||
if (false === $content) {
|
||||
$error = error_get_last();
|
||||
throw new ClientException($error['message']);
|
||||
}
|
||||
|
||||
$response->setHeaders($this->filterHeaders((array) $http_response_header));
|
||||
$response->setContent($content);
|
||||
|
||||
if ($cookieJar) {
|
||||
$cookieJar->processSetCookieHeaders($request, $response);
|
||||
}
|
||||
}
|
||||
|
||||
private function filterHeaders(array $headers)
|
||||
{
|
||||
$filtered = array();
|
||||
foreach ($headers as $header) {
|
||||
if (0 === stripos($header, 'http/')) {
|
||||
$filtered = array();
|
||||
}
|
||||
|
||||
$filtered[] = $header;
|
||||
}
|
||||
|
||||
return $filtered;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue