default services conflit ?

This commit is contained in:
armansansd
2022-04-27 11:30:43 +02:00
parent 28190a5749
commit 8bb1064a3b
8132 changed files with 900138 additions and 426 deletions

View File

@@ -0,0 +1,46 @@
# Change Log
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
## 4.4.0
### Added
- Add support for PHP 8.0
### Removed
- Drop support for PHP 7.2
### Changed
- Upgrade PHPUnit to version 9
## 4.3.0
### Removed
- Drop support for PHP < 7.2
## 4.2.0
## 4.1.0
### Changed
- Refactored `AbstractHttpProvider::getUrlContents` to split it up to different functions. We now
got `AbstractHttpProvider::getUrlContents`, `AbstractHttpProvider::getRequest` and `AbstractHttpProvider::getParsedResponse`.
## 4.0.0
No changes since beta 2.
## 4.0.0-beta2
- Removed `AbstractHttpProvider::setMessageFactory`.
- Removed `AbstractHttpProvider::getHttpClient`.
- Make sure we have a `MessageFactory` in the constructor of `AbstractHttpProvider`.
## 4.0.0-beta1
First release of this library.

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2011 — William Durand <william.durand1@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,123 @@
<?php
declare(strict_types=1);
/*
* This file is part of the Geocoder package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
namespace Geocoder\Http\Provider;
use Geocoder\Exception\InvalidCredentials;
use Geocoder\Exception\InvalidServerResponse;
use Geocoder\Exception\QuotaExceeded;
use Geocoder\Provider\AbstractProvider;
use Http\Message\MessageFactory;
use Http\Discovery\MessageFactoryDiscovery;
use Http\Client\HttpClient;
use Psr\Http\Message\RequestInterface;
/**
* @author William Durand <william.durand1@gmail.com>
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
abstract class AbstractHttpProvider extends AbstractProvider
{
/**
* @var HttpClient
*/
private $client;
/**
* @var MessageFactory
*/
private $messageFactory;
/**
* @param HttpClient $client
* @param MessageFactory|null $factory
*/
public function __construct(HttpClient $client, MessageFactory $factory = null)
{
$this->client = $client;
$this->messageFactory = $factory ?: MessageFactoryDiscovery::find();
}
/**
* Get URL and return contents. If content is empty, an exception will be thrown.
*
* @param string $url
*
* @return string
*
* @throws InvalidServerResponse
*/
protected function getUrlContents(string $url): string
{
$request = $this->getRequest($url);
return $this->getParsedResponse($request);
}
/**
* @param string $url
*
* @return RequestInterface
*/
protected function getRequest(string $url): RequestInterface
{
return $this->getMessageFactory()->createRequest('GET', $url);
}
/**
* Send request and return contents. If content is empty, an exception will be thrown.
*
* @param RequestInterface $request
*
* @return string
*
* @throws InvalidServerResponse
*/
protected function getParsedResponse(RequestInterface $request): string
{
$response = $this->getHttpClient()->sendRequest($request);
$statusCode = $response->getStatusCode();
if (401 === $statusCode || 403 === $statusCode) {
throw new InvalidCredentials();
} elseif (429 === $statusCode) {
throw new QuotaExceeded();
} elseif ($statusCode >= 300) {
throw InvalidServerResponse::create((string) $request->getUri(), $statusCode);
}
$body = (string) $response->getBody();
if (empty($body)) {
throw InvalidServerResponse::emptyResponse((string) $request->getUri());
}
return $body;
}
/**
* Returns the HTTP adapter.
*
* @return HttpClient
*/
protected function getHttpClient(): HttpClient
{
return $this->client;
}
/**
* @return MessageFactory
*/
protected function getMessageFactory(): MessageFactory
{
return $this->messageFactory;
}
}

View File

@@ -0,0 +1,26 @@
# Common classes for HTTP based Geocoders
[![Build Status](https://travis-ci.org/geocoder-php/php-common-http.svg?branch=master)](http://travis-ci.org/geocoder-php/php-common-http)
[![Latest Stable Version](https://poser.pugx.org/geocoder-php/common-http/v/stable)](https://packagist.org/packages/geocoder-php/common-http)
[![Total Downloads](https://poser.pugx.org/geocoder-php/common-http/downloads)](https://packagist.org/packages/geocoder-php/common-http)
[![Monthly Downloads](https://poser.pugx.org/geocoder-php/common-http/d/monthly.png)](https://packagist.org/packages/geocoder-php/common-http)
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/geocoder-php/php-common-http.svg?style=flat-square)](https://scrutinizer-ci.com/g/geocoder-php/php-common-http)
[![Quality Score](https://img.shields.io/scrutinizer/g/geocoder-php/php-common-http.svg?style=flat-square)](https://scrutinizer-ci.com/g/geocoder-php/php-common-http)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
This package has dependency on HTTP related libraries. Such as the great [HTTPlug](http://httplug.io/) and [PSR7](http://www.php-fig.org/psr/psr-7/).
It does contain a an `AbstractHttpProvider`.
### Install
In 99% of the cases you do **not** want to install this package directly. You are more likely to install one provider.
Have a look at [the documentation](https://github.com/geocoder-php/Geocoder) to see the different providers.
```bash
composer require geocoder-php/common-http
```
### Contribute
Contributions are very welcome! Send a pull request to the [main repository](https://github.com/geocoder-php/Geocoder) or
report any issues you find on the [issue tracker](https://github.com/geocoder-php/Geocoder/issues).

View File

@@ -0,0 +1,52 @@
{
"name": "geocoder-php/common-http",
"type": "library",
"description": "Common files for HTTP based Geocoders",
"keywords": [
"http geocoder"
],
"homepage": "http://geocoder-php.org",
"license": "MIT",
"authors": [
{
"name": "Tobias Nyholm",
"email": "tobias.nyholm@gmail.com"
}
],
"require": {
"php": "^7.3 || ^8.0",
"php-http/client-implementation": "^1.0",
"php-http/discovery": "^1.6",
"php-http/httplug": "^1.0 || ^2.0",
"php-http/message-factory": "^1.0.2",
"psr/http-message": "^1.0",
"psr/http-message-implementation": "^1.0",
"willdurand/geocoder": "^4.0"
},
"require-dev": {
"nyholm/psr7": "^1.0",
"php-http/message": "^1.0",
"php-http/mock-client": "^1.0",
"phpunit/phpunit": "^9.5",
"symfony/stopwatch": "~2.5"
},
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
}
},
"autoload": {
"psr-4": {
"Geocoder\\Http\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"test": "vendor/bin/phpunit",
"test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml"
}
}