Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
|
@ -14,6 +14,7 @@ use DOMXPath;
|
|||
use Zend\Cache\Storage\StorageInterface as CacheStorage;
|
||||
use Zend\Http as ZendHttp;
|
||||
use Zend\Stdlib\ErrorHandler;
|
||||
use Zend\Feed\Reader\Exception\InvalidHttpClientException;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
|
@ -57,7 +58,7 @@ class Reader implements ReaderImportInterface
|
|||
/**
|
||||
* HTTP client object to use for retrieving feeds
|
||||
*
|
||||
* @var ZendHttp\Client
|
||||
* @var Http\ClientInterface
|
||||
*/
|
||||
protected static $httpClient = null;
|
||||
|
||||
|
|
@ -117,23 +118,30 @@ class Reader implements ReaderImportInterface
|
|||
*
|
||||
* Sets the HTTP client object to use for retrieving the feeds.
|
||||
*
|
||||
* @param ZendHttp\Client $httpClient
|
||||
* @param ZendHttp\Client | Http\ClientInterface $httpClient
|
||||
* @return void
|
||||
*/
|
||||
public static function setHttpClient(ZendHttp\Client $httpClient)
|
||||
public static function setHttpClient($httpClient)
|
||||
{
|
||||
if ($httpClient instanceof ZendHttp\Client) {
|
||||
$httpClient = new Http\ZendHttpClientDecorator($httpClient);
|
||||
}
|
||||
|
||||
if (! $httpClient instanceof Http\ClientInterface) {
|
||||
throw new InvalidHttpClientException();
|
||||
}
|
||||
static::$httpClient = $httpClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTTP client object. If none is set, a new ZendHttp\Client will be used.
|
||||
*
|
||||
* @return ZendHttp\Client
|
||||
* @return Http\ClientInterface
|
||||
*/
|
||||
public static function getHttpClient()
|
||||
{
|
||||
if (!static::$httpClient instanceof ZendHttp\Client) {
|
||||
static::$httpClient = new ZendHttp\Client();
|
||||
if (! static::$httpClient) {
|
||||
static::$httpClient = new Http\ZendHttpClientDecorator(new ZendHttp\Client());
|
||||
}
|
||||
|
||||
return static::$httpClient;
|
||||
|
|
@ -189,17 +197,16 @@ class Reader implements ReaderImportInterface
|
|||
*/
|
||||
public static function import($uri, $etag = null, $lastModified = null)
|
||||
{
|
||||
$cache = self::getCache();
|
||||
$client = self::getHttpClient();
|
||||
$client->resetParameters();
|
||||
$headers = new ZendHttp\Headers();
|
||||
$client->setHeaders($headers);
|
||||
$client->setUri($uri);
|
||||
$cache = self::getCache();
|
||||
$client = self::getHttpClient();
|
||||
$cacheId = 'Zend_Feed_Reader_' . md5($uri);
|
||||
|
||||
if (static::$httpConditionalGet && $cache) {
|
||||
$data = $cache->getItem($cacheId);
|
||||
if ($data) {
|
||||
$headers = [];
|
||||
$data = $cache->getItem($cacheId);
|
||||
if ($data && $client instanceof Http\HeaderAwareClientInterface) {
|
||||
// Only check for ETag and last modified values in the cache
|
||||
// if we have a client capable of emitting headers in the first place.
|
||||
if ($etag === null) {
|
||||
$etag = $cache->getItem($cacheId . '_etag');
|
||||
}
|
||||
|
|
@ -207,26 +214,31 @@ class Reader implements ReaderImportInterface
|
|||
$lastModified = $cache->getItem($cacheId . '_lastmodified');
|
||||
}
|
||||
if ($etag) {
|
||||
$headers->addHeaderLine('If-None-Match', $etag);
|
||||
$headers['If-None-Match'] = [$etag];
|
||||
}
|
||||
if ($lastModified) {
|
||||
$headers->addHeaderLine('If-Modified-Since', $lastModified);
|
||||
$headers['If-Modified-Since'] = [$lastModified];
|
||||
}
|
||||
}
|
||||
$response = $client->send();
|
||||
$response = $client->get($uri, $headers);
|
||||
if ($response->getStatusCode() !== 200 && $response->getStatusCode() !== 304) {
|
||||
throw new Exception\RuntimeException('Feed failed to load, got response code ' . $response->getStatusCode());
|
||||
throw new Exception\RuntimeException(
|
||||
'Feed failed to load, got response code ' . $response->getStatusCode()
|
||||
);
|
||||
}
|
||||
if ($response->getStatusCode() == 304) {
|
||||
$responseXml = $data;
|
||||
} else {
|
||||
$responseXml = $response->getBody();
|
||||
$cache->setItem($cacheId, $responseXml);
|
||||
if ($response->getHeaders()->get('ETag')) {
|
||||
$cache->setItem($cacheId . '_etag', $response->getHeaders()->get('ETag')->getFieldValue());
|
||||
}
|
||||
if ($response->getHeaders()->get('Last-Modified')) {
|
||||
$cache->setItem($cacheId . '_lastmodified', $response->getHeaders()->get('Last-Modified')->getFieldValue());
|
||||
|
||||
if ($response instanceof Http\HeaderAwareResponseInterface) {
|
||||
if ($response->getHeaderLine('ETag', false)) {
|
||||
$cache->setItem($cacheId . '_etag', $response->getHeaderLine('ETag'));
|
||||
}
|
||||
if ($response->getHeaderLine('Last-Modified', false)) {
|
||||
$cache->setItem($cacheId . '_lastmodified', $response->getHeaderLine('Last-Modified'));
|
||||
}
|
||||
}
|
||||
}
|
||||
return static::importString($responseXml);
|
||||
|
|
@ -235,17 +247,21 @@ class Reader implements ReaderImportInterface
|
|||
if ($data) {
|
||||
return static::importString($data);
|
||||
}
|
||||
$response = $client->send();
|
||||
$response = $client->get($uri);
|
||||
if ((int) $response->getStatusCode() !== 200) {
|
||||
throw new Exception\RuntimeException('Feed failed to load, got response code ' . $response->getStatusCode());
|
||||
throw new Exception\RuntimeException(
|
||||
'Feed failed to load, got response code ' . $response->getStatusCode()
|
||||
);
|
||||
}
|
||||
$responseXml = $response->getBody();
|
||||
$cache->setItem($cacheId, $responseXml);
|
||||
return static::importString($responseXml);
|
||||
} else {
|
||||
$response = $client->send();
|
||||
$response = $client->get($uri);
|
||||
if ((int) $response->getStatusCode() !== 200) {
|
||||
throw new Exception\RuntimeException('Feed failed to load, got response code ' . $response->getStatusCode());
|
||||
throw new Exception\RuntimeException(
|
||||
'Feed failed to load, got response code ' . $response->getStatusCode()
|
||||
);
|
||||
}
|
||||
$reader = static::importString($response->getBody());
|
||||
$reader->setOriginalSourceUri($uri);
|
||||
|
|
@ -270,7 +286,7 @@ class Reader implements ReaderImportInterface
|
|||
public static function importRemoteFeed($uri, Http\ClientInterface $client)
|
||||
{
|
||||
$response = $client->get($uri);
|
||||
if (!$response instanceof Http\ResponseInterface) {
|
||||
if (! $response instanceof Http\ResponseInterface) {
|
||||
throw new Exception\RuntimeException(sprintf(
|
||||
'Did not receive a %s\Http\ResponseInterface from the provided HTTP client; received "%s"',
|
||||
__NAMESPACE__,
|
||||
|
|
@ -279,7 +295,9 @@ class Reader implements ReaderImportInterface
|
|||
}
|
||||
|
||||
if ((int) $response->getStatusCode() !== 200) {
|
||||
throw new Exception\RuntimeException('Feed failed to load, got response code ' . $response->getStatusCode());
|
||||
throw new Exception\RuntimeException(
|
||||
'Feed failed to load, got response code ' . $response->getStatusCode()
|
||||
);
|
||||
}
|
||||
$reader = static::importString($response->getBody());
|
||||
$reader->setOriginalSourceUri($uri);
|
||||
|
|
@ -297,7 +315,7 @@ class Reader implements ReaderImportInterface
|
|||
public static function importString($string)
|
||||
{
|
||||
$trimmed = trim($string);
|
||||
if (!is_string($string) || empty($trimmed)) {
|
||||
if (! is_string($string) || empty($trimmed)) {
|
||||
throw new Exception\InvalidArgumentException('Only non empty strings are allowed as input');
|
||||
}
|
||||
|
||||
|
|
@ -315,7 +333,7 @@ class Reader implements ReaderImportInterface
|
|||
libxml_disable_entity_loader($oldValue);
|
||||
libxml_use_internal_errors($libxmlErrflag);
|
||||
|
||||
if (!$status) {
|
||||
if (! $status) {
|
||||
// Build error message
|
||||
$error = libxml_get_last_error();
|
||||
if ($error && $error->message) {
|
||||
|
|
@ -371,11 +389,12 @@ class Reader implements ReaderImportInterface
|
|||
*/
|
||||
public static function findFeedLinks($uri)
|
||||
{
|
||||
$client = static::getHttpClient();
|
||||
$client->setUri($uri);
|
||||
$response = $client->send();
|
||||
$client = static::getHttpClient();
|
||||
$response = $client->get($uri);
|
||||
if ($response->getStatusCode() !== 200) {
|
||||
throw new Exception\RuntimeException("Failed to access $uri, got response code " . $response->getStatusCode());
|
||||
throw new Exception\RuntimeException(
|
||||
"Failed to access $uri, got response code " . $response->getStatusCode()
|
||||
);
|
||||
}
|
||||
$responseHtml = $response->getBody();
|
||||
$libxmlErrflag = libxml_use_internal_errors(true);
|
||||
|
|
@ -384,7 +403,7 @@ class Reader implements ReaderImportInterface
|
|||
$status = $dom->loadHTML(trim($responseHtml));
|
||||
libxml_disable_entity_loader($oldValue);
|
||||
libxml_use_internal_errors($libxmlErrflag);
|
||||
if (!$status) {
|
||||
if (! $status) {
|
||||
// Build error message
|
||||
$error = libxml_get_last_error();
|
||||
if ($error && $error->message) {
|
||||
|
|
@ -416,8 +435,8 @@ class Reader implements ReaderImportInterface
|
|||
$dom = $feed->getDomDocument();
|
||||
} elseif ($feed instanceof DOMDocument) {
|
||||
$dom = $feed;
|
||||
} elseif (is_string($feed) && !empty($feed)) {
|
||||
ErrorHandler::start(E_NOTICE|E_WARNING);
|
||||
} elseif (is_string($feed) && ! empty($feed)) {
|
||||
ErrorHandler::start(E_NOTICE | E_WARNING);
|
||||
ini_set('track_errors', 1);
|
||||
$oldValue = libxml_disable_entity_loader(true);
|
||||
$dom = new DOMDocument;
|
||||
|
|
@ -432,8 +451,8 @@ class Reader implements ReaderImportInterface
|
|||
libxml_disable_entity_loader($oldValue);
|
||||
ini_restore('track_errors');
|
||||
ErrorHandler::stop();
|
||||
if (!$status) {
|
||||
if (!isset($phpErrormsg)) {
|
||||
if (! $status) {
|
||||
if (! isset($phpErrormsg)) {
|
||||
if (function_exists('xdebug_is_enabled')) {
|
||||
$phpErrormsg = '(error message not available, when XDebug is running)';
|
||||
} else {
|
||||
|
|
@ -543,7 +562,7 @@ class Reader implements ReaderImportInterface
|
|||
*/
|
||||
public static function getExtensionManager()
|
||||
{
|
||||
if (!isset(static::$extensionManager)) {
|
||||
if (! isset(static::$extensionManager)) {
|
||||
static::setExtensionManager(new StandaloneExtensionManager());
|
||||
}
|
||||
return static::$extensionManager;
|
||||
|
|
@ -567,7 +586,7 @@ class Reader implements ReaderImportInterface
|
|||
}
|
||||
}
|
||||
|
||||
if (!$manager->has($feedName) && !$manager->has($entryName)) {
|
||||
if (! $manager->has($feedName) && ! $manager->has($entryName)) {
|
||||
throw new Exception\RuntimeException('Could not load extension: ' . $name
|
||||
. ' using Plugin Loader. Check prefix paths are configured and extension exists.');
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue