summaryrefslogtreecommitdiff
path: root/inc/mailgun/php-http/discovery
diff options
context:
space:
mode:
authorCarson Fleming <cflems@cflems.net>2017-03-02 22:49:24 -0500
committerCarson Fleming <cflems@cflems.net>2017-03-02 22:49:24 -0500
commitb76e2ff898b23745d4c9aaee49eeb7d88f2896ab (patch)
tree9b794be8db310a575d70165d9ebde0a183b61b01 /inc/mailgun/php-http/discovery
parentbfcc9f7a7656a2db0c905b3c13114664f00f6c37 (diff)
downloadbulletin-b76e2ff898b23745d4c9aaee49eeb7d88f2896ab.tar.gz
Updated mailgun plugin
Diffstat (limited to 'inc/mailgun/php-http/discovery')
-rw-r--r--inc/mailgun/php-http/discovery/CHANGELOG.md179
-rw-r--r--inc/mailgun/php-http/discovery/LICENSE19
-rw-r--r--inc/mailgun/php-http/discovery/README.md46
-rw-r--r--inc/mailgun/php-http/discovery/composer.json48
-rw-r--r--inc/mailgun/php-http/discovery/src/ClassDiscovery.php207
-rw-r--r--inc/mailgun/php-http/discovery/src/Exception.php12
-rw-r--r--inc/mailgun/php-http/discovery/src/Exception/ClassInstantiationFailedException.php14
-rw-r--r--inc/mailgun/php-http/discovery/src/Exception/DiscoveryFailedException.php51
-rw-r--r--inc/mailgun/php-http/discovery/src/Exception/NotFoundException.php16
-rw-r--r--inc/mailgun/php-http/discovery/src/Exception/PuliUnavailableException.php12
-rw-r--r--inc/mailgun/php-http/discovery/src/Exception/StrategyUnavailableException.php15
-rw-r--r--inc/mailgun/php-http/discovery/src/HttpAsyncClientDiscovery.php36
-rw-r--r--inc/mailgun/php-http/discovery/src/HttpClientDiscovery.php36
-rw-r--r--inc/mailgun/php-http/discovery/src/MessageFactoryDiscovery.php36
-rw-r--r--inc/mailgun/php-http/discovery/src/NotFoundException.php14
-rw-r--r--inc/mailgun/php-http/discovery/src/Strategy/CommonClassesStrategy.php76
-rw-r--r--inc/mailgun/php-http/discovery/src/Strategy/DiscoveryStrategy.php23
-rw-r--r--inc/mailgun/php-http/discovery/src/Strategy/MockClientStrategy.php24
-rw-r--r--inc/mailgun/php-http/discovery/src/Strategy/PuliBetaStrategy.php91
-rw-r--r--inc/mailgun/php-http/discovery/src/StreamFactoryDiscovery.php36
-rw-r--r--inc/mailgun/php-http/discovery/src/UriFactoryDiscovery.php36
21 files changed, 1027 insertions, 0 deletions
diff --git a/inc/mailgun/php-http/discovery/CHANGELOG.md b/inc/mailgun/php-http/discovery/CHANGELOG.md
new file mode 100644
index 0000000..0c56331
--- /dev/null
+++ b/inc/mailgun/php-http/discovery/CHANGELOG.md
@@ -0,0 +1,179 @@
+# Change Log
+
+
+## 1.2.1 - 2017-03-02
+
+### Fixed
+
+- Fixed minor issue with `MockClientStrategy`, also added more tests.
+
+## 1.2.0 - 2017-02-12
+
+### Added
+
+- MockClientStrategy class.
+
+## 1.1.1 - 2016-11-27
+
+### Changed
+
+- Made exception messages clearer. `StrategyUnavailableException` is no longer the previous exception to `DiscoveryFailedException`.
+- `CommonClassesStrategy` is using `self` instead of `static`. Using `static` makes no sense when `CommonClassesStrategy` is final.
+
+## 1.1.0 - 2016-10-20
+
+### Added
+
+- Discovery support for Slim Framework factories
+
+## 1.0.0 - 2016-07-18
+
+### Added
+
+- Added back `Http\Discovery\NotFoundException` to preserve BC with 0.8 version. You may upgrade from 0.8.x and 0.9.x to 1.0.0 without any BC breaks.
+- Added interface `Http\Discovery\Exception` which is implemented by all our exceptions
+
+### Changed
+
+- Puli strategy renamed to Puli Beta strategy to prevent incompatibility with a future Puli stable
+
+### Deprecated
+
+- For BC reasons, the old `Http\Discovery\NotFoundException` (extending the new exception) will be thrown until version 2.0
+
+
+## 0.9.1 - 2016-06-28
+
+### Changed
+
+- Dropping PHP 5.4 support because we use the ::class constant.
+
+
+## 0.9.0 - 2016-06-25
+
+### Added
+
+- Discovery strategies to find classes
+
+### Changed
+
+- [Puli](http://puli.io) made optional
+- Improved exceptions
+- **[BC] `NotFoundException` moved to `Http\Discovery\Exception\NotFoundException`**
+
+
+## 0.8.0 - 2016-02-11
+
+### Changed
+
+- Puli composer plugin must be installed separately
+
+
+## 0.7.0 - 2016-01-15
+
+### Added
+
+- Temporary puli.phar (Beta 10) executable
+
+### Changed
+
+- Updated HTTPlug dependencies
+- Updated Puli dependencies
+- Local configuration to make tests passing
+
+### Removed
+
+- Puli CLI dependency
+
+
+## 0.6.4 - 2016-01-07
+
+### Fixed
+
+- Puli [not working](https://twitter.com/PuliPHP/status/685132540588507137) with the latest json-schema
+
+
+## 0.6.3 - 2016-01-04
+
+### Changed
+
+- Adjust Puli dependencies
+
+
+## 0.6.2 - 2016-01-04
+
+### Changed
+
+- Make Puli CLI a requirement
+
+
+## 0.6.1 - 2016-01-03
+
+### Changed
+
+- More flexible Puli requirement
+
+
+## 0.6.0 - 2015-12-30
+
+### Changed
+
+- Use [Puli](http://puli.io) for discovery
+- Improved exception messages
+
+
+## 0.5.0 - 2015-12-25
+
+### Changed
+
+- Updated message factory dependency (php-http/message)
+
+
+## 0.4.0 - 2015-12-17
+
+### Added
+
+- Array condition evaluation in the Class Discovery
+
+### Removed
+
+- Message factories (moved to php-http/utils)
+
+
+## 0.3.0 - 2015-11-18
+
+### Added
+
+- HTTP Async Client Discovery
+- Stream factories
+
+### Changed
+
+- Discoveries and Factories are final
+- Message and Uri factories have the type in their names
+- Diactoros Message factory uses Stream factory internally
+
+### Fixed
+
+- Improved docblocks for API documentation generation
+
+
+## 0.2.0 - 2015-10-31
+
+### Changed
+
+- Renamed AdapterDiscovery to ClientDiscovery
+
+
+## 0.1.1 - 2015-06-13
+
+### Fixed
+
+- Bad HTTP Adapter class name for Guzzle 5
+
+
+## 0.1.0 - 2015-06-12
+
+### Added
+
+- Initial release
diff --git a/inc/mailgun/php-http/discovery/LICENSE b/inc/mailgun/php-http/discovery/LICENSE
new file mode 100644
index 0000000..4558d6f
--- /dev/null
+++ b/inc/mailgun/php-http/discovery/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2015-2016 PHP HTTP Team <team@php-http.org>
+
+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.
diff --git a/inc/mailgun/php-http/discovery/README.md b/inc/mailgun/php-http/discovery/README.md
new file mode 100644
index 0000000..7c5151e
--- /dev/null
+++ b/inc/mailgun/php-http/discovery/README.md
@@ -0,0 +1,46 @@
+# HTTPlug Discovery
+
+[![Latest Version](https://img.shields.io/github/release/php-http/discovery.svg?style=flat-square)](https://github.com/php-http/discovery/releases)
+[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
+[![Build Status](https://img.shields.io/travis/php-http/discovery.svg?style=flat-square)](https://travis-ci.org/php-http/discovery)
+[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/php-http/discovery.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/discovery)
+[![Quality Score](https://img.shields.io/scrutinizer/g/php-http/discovery.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/discovery)
+[![Total Downloads](https://img.shields.io/packagist/dt/php-http/discovery.svg?style=flat-square)](https://packagist.org/packages/php-http/discovery)
+
+**Finds installed HTTPlug implementations and PSR-7 message factories.**
+
+
+## Install
+
+Via Composer
+
+``` bash
+$ composer require php-http/discovery
+```
+
+
+## Documentation
+
+Please see the [official documentation](http://php-http.readthedocs.org/en/latest/discovery.html).
+
+
+## Testing
+
+``` bash
+$ composer test
+```
+
+
+## Contributing
+
+Please see our [contributing guide](http://docs.php-http.org/en/latest/development/contributing.html).
+
+
+## Security
+
+If you discover any security related issues, please contact us at [security@php-http.org](mailto:security@php-http.org).
+
+
+## License
+
+The MIT License (MIT). Please see [License File](LICENSE) for more information.
diff --git a/inc/mailgun/php-http/discovery/composer.json b/inc/mailgun/php-http/discovery/composer.json
new file mode 100644
index 0000000..128af59
--- /dev/null
+++ b/inc/mailgun/php-http/discovery/composer.json
@@ -0,0 +1,48 @@
+{
+ "name": "php-http/discovery",
+ "description": "Finds installed HTTPlug implementations and PSR-7 message factories",
+ "license": "MIT",
+ "keywords": ["http", "discovery", "client", "adapter", "message", "factory", "psr7"],
+ "homepage": "http://php-http.org",
+ "authors": [
+ {
+ "name": "Márk Sági-Kazár",
+ "email": "mark.sagikazar@gmail.com"
+ }
+ ],
+ "require": {
+ "php": "^5.5 || ^7.0"
+ },
+ "require-dev": {
+ "php-http/httplug": "^1.0",
+ "php-http/message-factory": "^1.0",
+ "puli/composer-plugin": "1.0.0-beta10",
+ "phpspec/phpspec": "^2.4",
+ "henrikbjorn/phpspec-code-coverage" : "^2.0.2"
+ },
+ "suggest": {
+ "puli/composer-plugin": "Sets up Puli which is recommended for Discovery to work. Check http://docs.php-http.org/en/latest/discovery.html for more details.",
+ "php-http/message": "Allow to use Guzzle, Diactoros or Slim Framework factories"
+ },
+ "autoload": {
+ "psr-4": {
+ "Http\\Discovery\\": "src/"
+ }
+ },
+ "autoload-dev": {
+ "psr-4": {
+ "spec\\Http\\Discovery\\": "spec/"
+ }
+ },
+ "scripts": {
+ "test": "vendor/bin/phpspec run",
+ "test-ci": "vendor/bin/phpspec run -c phpspec.ci.yml"
+ },
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.3-dev"
+ }
+ },
+ "prefer-stable": true,
+ "minimum-stability": "beta"
+}
diff --git a/inc/mailgun/php-http/discovery/src/ClassDiscovery.php b/inc/mailgun/php-http/discovery/src/ClassDiscovery.php
new file mode 100644
index 0000000..2c3e877
--- /dev/null
+++ b/inc/mailgun/php-http/discovery/src/ClassDiscovery.php
@@ -0,0 +1,207 @@
+<?php
+
+namespace Http\Discovery;
+
+use Http\Discovery\Exception\ClassInstantiationFailedException;
+use Http\Discovery\Exception\DiscoveryFailedException;
+use Http\Discovery\Exception\StrategyUnavailableException;
+
+/**
+ * Registry that based find results on class existence.
+ *
+ * @author David de Boer <david@ddeboer.nl>
+ * @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
+ * @author Tobias Nyholm <tobias.nyholm@gmail.com>
+ */
+abstract class ClassDiscovery
+{
+ /**
+ * A list of strategies to find classes.
+ *
+ * @var array
+ */
+ private static $strategies = [
+ Strategy\PuliBetaStrategy::class,
+ Strategy\CommonClassesStrategy::class,
+ ];
+
+ /**
+ * Discovery cache to make the second time we use discovery faster.
+ *
+ * @var array
+ */
+ private static $cache = [];
+
+ /**
+ * Finds a class.
+ *
+ * @param string $type
+ *
+ * @return string|\Closure
+ *
+ * @throws DiscoveryFailedException
+ */
+ protected static function findOneByType($type)
+ {
+ // Look in the cache
+ if (null !== ($class = self::getFromCache($type))) {
+ return $class;
+ }
+
+ $exceptions = [];
+ foreach (self::$strategies as $strategy) {
+ try {
+ $candidates = call_user_func($strategy.'::getCandidates', $type);
+ } catch (StrategyUnavailableException $e) {
+ $exceptions[] = $e;
+ continue;
+ }
+
+ foreach ($candidates as $candidate) {
+ if (isset($candidate['condition'])) {
+ if (!self::evaluateCondition($candidate['condition'])) {
+ continue;
+ }
+ }
+
+ // save the result for later use
+ self::storeInCache($type, $candidate);
+
+ return $candidate['class'];
+ }
+ }
+
+ throw DiscoveryFailedException::create($exceptions);
+ }
+
+ /**
+ * Get a value from cache.
+ *
+ * @param string $type
+ *
+ * @return string|null
+ */
+ private static function getFromCache($type)
+ {
+ if (!isset(self::$cache[$type])) {
+ return;
+ }
+
+ $candidate = self::$cache[$type];
+ if (isset($candidate['condition'])) {
+ if (!self::evaluateCondition($candidate['condition'])) {
+ return;
+ }
+ }
+
+ return $candidate['class'];
+ }
+
+ /**
+ * Store a value in cache.
+ *
+ * @param string $type
+ * @param string $class
+ */
+ private static function storeInCache($type, $class)
+ {
+ self::$cache[$type] = $class;
+ }
+
+ /**
+ * Set new strategies and clear the cache.
+ *
+ * @param array $strategies string array of fully qualified class name to a DiscoveryStrategy
+ */
+ public static function setStrategies(array $strategies)
+ {
+ self::$strategies = $strategies;
+ self::clearCache();
+ }
+
+ /**
+ * Append a strategy at the end of the strategy queue.
+ *
+ * @param string $strategy Fully qualified class name to a DiscoveryStrategy
+ */
+ public static function appendStrategy($strategy)
+ {
+ self::$strategies[] = $strategy;
+ self::clearCache();
+ }
+
+ /**
+ * Prepend a strategy at the beginning of the strategy queue.
+ *
+ * @param string $strategy Fully qualified class name to a DiscoveryStrategy
+ */
+ public static function prependStrategy($strategy)
+ {
+ array_unshift(self::$strategies, $strategy);
+ self::clearCache();
+ }
+
+ /**
+ * Clear the cache.
+ */
+ public static function clearCache()
+ {
+ self::$cache = [];
+ }
+
+ /**
+ * Evaluates conditions to boolean.
+ *
+ * @param mixed $condition
+ *
+ * @return bool
+ */
+ protected static function evaluateCondition($condition)
+ {
+ if (is_string($condition)) {
+ // Should be extended for functions, extensions???
+ return class_exists($condition);
+ } elseif (is_callable($condition)) {
+ return $condition();
+ } elseif (is_bool($condition)) {
+ return $condition;
+ } elseif (is_array($condition)) {
+ $evaluatedCondition = true;
+
+ // Immediately stop execution if the condition is false
+ for ($i = 0; $i < count($condition) && false !== $evaluatedCondition; ++$i) {
+ $evaluatedCondition &= static::evaluateCondition($condition[$i]);
+ }
+
+ return $evaluatedCondition;
+ }
+
+ return false;
+ }
+
+ /**
+ * Get an instance of the $class.
+ *
+ * @param string|\Closure $class A FQCN of a class or a closure that instantiate the class.
+ *
+ * @return object
+ *
+ * @throws ClassInstantiationFailedException
+ */
+ protected static function instantiateClass($class)
+ {
+ try {
+ if (is_string($class)) {
+ return new $class();
+ }
+
+ if (is_callable($class)) {
+ return $class();
+ }
+ } catch (\Exception $e) {
+ throw new ClassInstantiationFailedException('Unexpected exception when instantiating class.', 0, $e);
+ }
+
+ throw new ClassInstantiationFailedException('Could not instantiate class because parameter is neither a callable nor a string');
+ }
+}
diff --git a/inc/mailgun/php-http/discovery/src/Exception.php b/inc/mailgun/php-http/discovery/src/Exception.php
new file mode 100644
index 0000000..973c908
--- /dev/null
+++ b/inc/mailgun/php-http/discovery/src/Exception.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace Http\Discovery;
+
+/**
+ * An interface implemented by all discovery related exceptions.
+ *
+ * @author Tobias Nyholm <tobias.nyholm@gmail.com>
+ */
+interface Exception
+{
+}
diff --git a/inc/mailgun/php-http/discovery/src/Exception/ClassInstantiationFailedException.php b/inc/mailgun/php-http/discovery/src/Exception/ClassInstantiationFailedException.php
new file mode 100644
index 0000000..e95bf5d
--- /dev/null
+++ b/inc/mailgun/php-http/discovery/src/Exception/ClassInstantiationFailedException.php
@@ -0,0 +1,14 @@
+<?php
+
+namespace Http\Discovery\Exception;
+
+use Http\Discovery\Exception;
+
+/**
+ * Thrown when a class fails to instantiate.
+ *
+ * @author Tobias Nyholm <tobias.nyholm@gmail.com>
+ */
+final class ClassInstantiationFailedException extends \RuntimeException implements Exception
+{
+}
diff --git a/inc/mailgun/php-http/discovery/src/Exception/DiscoveryFailedException.php b/inc/mailgun/php-http/discovery/src/Exception/DiscoveryFailedException.php
new file mode 100644
index 0000000..304b727
--- /dev/null
+++ b/inc/mailgun/php-http/discovery/src/Exception/DiscoveryFailedException.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace Http\Discovery\Exception;
+
+use Http\Discovery\Exception;
+
+/**
+ * Thrown when all discovery strategies fails to find a resource.
+ *
+ * @author Tobias Nyholm <tobias.nyholm@gmail.com>
+ */
+final class DiscoveryFailedException extends \Exception implements Exception
+{
+ /**
+ * @var \Exception[]
+ */
+ private $exceptions;
+
+ /**
+ * @param string $message
+ * @param \Exception[] $exceptions
+ */
+ public function __construct($message, array $exceptions = [])
+ {
+ $this->exceptions = $exceptions;
+
+ parent::__construct($message);
+ }
+
+ /**
+ * @param \Exception[] $exceptions
+ */
+ public static function create($exceptions)
+ {
+ $message = 'Could not find resource using any discovery strategy. Find more information at http://docs.php-http.org/en/latest/discovery.html#common-errors';
+ foreach ($exceptions as $e) {
+ $message .= "\n - ".$e->getMessage();
+ }
+ $message .= "\n\n";
+
+ return new self($message, $exceptions);
+ }
+
+ /**
+ * @return \Exception[]
+ */
+ public function getExceptions()
+ {
+ return $this->exceptions;
+ }
+}
diff --git a/inc/mailgun/php-http/discovery/src/Exception/NotFoundException.php b/inc/mailgun/php-http/discovery/src/Exception/NotFoundException.php
new file mode 100644
index 0000000..befbf48
--- /dev/null
+++ b/inc/mailgun/php-http/discovery/src/Exception/NotFoundException.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace Http\Discovery\Exception;
+
+use Http\Discovery\Exception;
+
+/**
+ * Thrown when a discovery does not find any matches.
+ *
+ * @final do NOT extend this class, not final for BC reasons
+ *
+ * @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
+ */
+/*final */class NotFoundException extends \RuntimeException implements Exception
+{
+}
diff --git a/inc/mailgun/php-http/discovery/src/Exception/PuliUnavailableException.php b/inc/mailgun/php-http/discovery/src/Exception/PuliUnavailableException.php
new file mode 100644
index 0000000..a6ade73
--- /dev/null
+++ b/inc/mailgun/php-http/discovery/src/Exception/PuliUnavailableException.php
@@ -0,0 +1,12 @@
+<?php
+
+namespace Http\Discovery\Exception;
+
+/**
+ * Thrown when we can't use Puli for discovery.
+ *
+ * @author Tobias Nyholm <tobias.nyholm@gmail.com>
+ */
+final class PuliUnavailableException extends StrategyUnavailableException
+{
+}
diff --git a/inc/mailgun/php-http/discovery/src/Exception/StrategyUnavailableException.php b/inc/mailgun/php-http/discovery/src/Exception/StrategyUnavailableException.php
new file mode 100644
index 0000000..89ecf35
--- /dev/null
+++ b/inc/mailgun/php-http/discovery/src/Exception/StrategyUnavailableException.php
@@ -0,0 +1,15 @@
+<?php
+
+namespace Http\Discovery\Exception;
+
+use Http\Discovery\Exception;
+
+/**
+ * This exception is thrown when we cannot use a discovery strategy. This is *not* thrown when
+ * the discovery fails to find a class.
+ *
+ * @author Tobias Nyholm <tobias.nyholm@gmail.com>
+ */
+class StrategyUnavailableException extends \RuntimeException implements Exception
+{
+}
diff --git a/inc/mailgun/php-http/discovery/src/HttpAsyncClientDiscovery.php b/inc/mailgun/php-http/discovery/src/HttpAsyncClientDiscovery.php
new file mode 100644
index 0000000..6ef60e7
--- /dev/null
+++ b/inc/mailgun/php-http/discovery/src/HttpAsyncClientDiscovery.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace Http\Discovery;
+
+use Http\Client\HttpAsyncClient;
+use Http\Discovery\Exception\DiscoveryFailedException;
+
+/**
+ * Finds an HTTP Asynchronous Client.
+ *
+ * @author Joel Wurtz <joel.wurtz@gmail.com>
+ */
+final class HttpAsyncClientDiscovery extends ClassDiscovery
+{
+ /**
+ * Finds an HTTP Async Client.
+ *
+ * @return HttpAsyncClient
+ *
+ * @throws Exception\NotFoundException
+ */
+ public static function find()
+ {
+ try {
+ $asyncClient = static::findOneByType(HttpAsyncClient::class);
+ } catch (DiscoveryFailedException $e) {
+ throw new NotFoundException(
+ 'No HTTPlug async clients found. Make sure to install a package providing "php-http/async-client-implementation". Example: "php-http/guzzle6-adapter".',
+ 0,
+ $e
+ );
+ }
+
+ return static::instantiateClass($asyncClient);
+ }
+}
diff --git a/inc/mailgun/php-http/discovery/src/HttpClientDiscovery.php b/inc/mailgun/php-http/discovery/src/HttpClientDiscovery.php
new file mode 100644
index 0000000..2654b7e
--- /dev/null
+++ b/inc/mailgun/php-http/discovery/src/HttpClientDiscovery.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace Http\Discovery;
+
+use Http\Client\HttpClient;
+use Http\Discovery\Exception\DiscoveryFailedException;
+
+/**
+ * Finds an HTTP Client.
+ *
+ * @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
+ */
+final class HttpClientDiscovery extends ClassDiscovery
+{
+ /**
+ * Finds an HTTP Client.
+ *
+ * @return HttpClient
+ *
+ * @throws Exception\NotFoundException
+ */
+ public static function find()
+ {
+ try {
+ $client = static::findOneByType(HttpClient::class);
+ } catch (DiscoveryFailedException $e) {
+ throw new NotFoundException(
+ 'No HTTPlug clients found. Make sure to install a package providing "php-http/client-implementation". Example: "php-http/guzzle6-adapter".',
+ 0,
+ $e
+ );
+ }
+
+ return static::instantiateClass($client);
+ }
+}
diff --git a/inc/mailgun/php-http/discovery/src/MessageFactoryDiscovery.php b/inc/mailgun/php-http/discovery/src/MessageFactoryDiscovery.php
new file mode 100644
index 0000000..c21b9bf
--- /dev/null
+++ b/inc/mailgun/php-http/discovery/src/MessageFactoryDiscovery.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace Http\Discovery;
+
+use Http\Discovery\Exception\DiscoveryFailedException;
+use Http\Message\MessageFactory;
+
+/**
+ * Finds a Message Factory.
+ *
+ * @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
+ */
+final class MessageFactoryDiscovery extends ClassDiscovery
+{
+ /**
+ * Finds a Message Factory.
+ *
+ * @return MessageFactory
+ *
+ * @throws Exception\NotFoundException
+ */
+ public static function find()
+ {
+ try {
+ $messageFactory = static::findOneByType(MessageFactory::class);
+ } catch (DiscoveryFailedException $e) {
+ throw new NotFoundException(
+ 'No message factories found. To use Guzzle, Diactoros or Slim Framework factories install php-http/message and the chosen message implementation.',
+ 0,
+ $e
+ );
+ }
+
+ return static::instantiateClass($messageFactory);
+ }
+}
diff --git a/inc/mailgun/php-http/discovery/src/NotFoundException.php b/inc/mailgun/php-http/discovery/src/NotFoundException.php
new file mode 100644
index 0000000..d59dadb
--- /dev/null
+++ b/inc/mailgun/php-http/discovery/src/NotFoundException.php
@@ -0,0 +1,14 @@
+<?php
+
+namespace Http\Discovery;
+
+/**
+ * Thrown when a discovery does not find any matches.
+ *
+ * @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
+ *
+ * @deprecated since since version 1.0, and will be removed in 2.0. Use {@link \Http\Discovery\Exception\NotFoundException} instead.
+ */
+final class NotFoundException extends \Http\Discovery\Exception\NotFoundException
+{
+}
diff --git a/inc/mailgun/php-http/discovery/src/Strategy/CommonClassesStrategy.php b/inc/mailgun/php-http/discovery/src/Strategy/CommonClassesStrategy.php
new file mode 100644
index 0000000..cbed15d
--- /dev/null
+++ b/inc/mailgun/php-http/discovery/src/Strategy/CommonClassesStrategy.php
@@ -0,0 +1,76 @@
+<?php
+
+namespace Http\Discovery\Strategy;
+
+use GuzzleHttp\Psr7\Request as GuzzleRequest;
+use Http\Message\MessageFactory\GuzzleMessageFactory;
+use Http\Message\StreamFactory\GuzzleStreamFactory;
+use Http\Message\UriFactory\GuzzleUriFactory;
+use Http\Message\MessageFactory\DiactorosMessageFactory;
+use Http\Message\StreamFactory\DiactorosStreamFactory;
+use Http\Message\UriFactory\DiactorosUriFactory;
+use Zend\Diactoros\Request as DiactorosRequest;
+use Http\Message\MessageFactory\SlimMessageFactory;
+use Http\Message\StreamFactory\SlimStreamFactory;
+use Http\Message\UriFactory\SlimUriFactory;
+use Slim\Http\Request as SlimRequest;
+use Http\Adapter\Guzzle6\Client as Guzzle6;
+use Http\Adapter\Guzzle5\Client as Guzzle5;
+use Http\Client\Curl\Client as Curl;
+use Http\Client\Socket\Client as Socket;
+use Http\Adapter\React\Client as React;
+use Http\Adapter\Buzz\Client as Buzz;
+
+/**
+ * @internal
+ *
+ * @author Tobias Nyholm <tobias.nyholm@gmail.com>
+ */
+final class CommonClassesStrategy implements DiscoveryStrategy
+{
+ /**
+ * @var array
+ */
+ private static $classes = [
+ 'Http\Message\MessageFactory' => [
+ ['class' => GuzzleMessageFactory::class, 'condition' => [GuzzleRequest::class, GuzzleMessageFactory::class]],
+ ['class' => DiactorosMessageFactory::class, 'condition' => [DiactorosRequest::class, DiactorosMessageFactory::class]],
+ ['class' => SlimMessageFactory::class, 'condition' => [SlimRequest::class, SlimMessageFactory::class]],
+ ],
+ 'Http\Message\StreamFactory' => [
+ ['class' => GuzzleStreamFactory::class, 'condition' => [GuzzleRequest::class, GuzzleStreamFactory::class]],
+ ['class' => DiactorosStreamFactory::class, 'condition' => [DiactorosRequest::class, DiactorosStreamFactory::class]],
+ ['class' => SlimStreamFactory::class, 'condition' => [SlimRequest::class, SlimStreamFactory::class]],
+ ],
+ 'Http\Message\UriFactory' => [
+ ['class' => GuzzleUriFactory::class, 'condition' => [GuzzleRequest::class, GuzzleUriFactory::class]],
+ ['class' => DiactorosUriFactory::class, 'condition' => [DiactorosRequest::class, DiactorosUriFactory::class]],
+ ['class' => SlimUriFactory::class, 'condition' => [SlimRequest::class, SlimUriFactory::class]],
+ ],
+ 'Http\Client\HttpAsyncClient' => [
+ ['class' => Guzzle6::class, 'condition' => Guzzle6::class],
+ ['class' => Curl::class, 'condition' => Curl::class],
+ ['class' => React::class, 'condition' => React::class],
+ ],
+ 'Http\Client\HttpClient' => [
+ ['class' => Guzzle6::class, 'condition' => Guzzle6::class],
+ ['class' => Guzzle5::class, 'condition' => Guzzle5::class],
+ ['class' => Curl::class, 'condition' => Curl::class],
+ ['class' => Socket::class, 'condition' => Socket::class],
+ ['class' => Buzz::class, 'condition' => Buzz::class],
+ ['class' => React::class, 'condition' => React::class],
+ ],
+ ];
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getCandidates($type)
+ {
+ if (isset(self::$classes[$type])) {
+ return self::$classes[$type];
+ }
+
+ return [];
+ }
+}
diff --git a/inc/mailgun/php-http/discovery/src/Strategy/DiscoveryStrategy.php b/inc/mailgun/php-http/discovery/src/Strategy/DiscoveryStrategy.php
new file mode 100644
index 0000000..641485a
--- /dev/null
+++ b/inc/mailgun/php-http/discovery/src/Strategy/DiscoveryStrategy.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace Http\Discovery\Strategy;
+
+use Http\Discovery\Exception\StrategyUnavailableException;
+
+/**
+ * @author Tobias Nyholm <tobias.nyholm@gmail.com>
+ */
+interface DiscoveryStrategy
+{
+ /**
+ * Find a resource of a specific type.
+ *
+ * @param string $type
+ *
+ * @return array The return value is always an array with zero or more elements. Each
+ * element is an array with two keys ['class' => string, 'condition' => mixed].
+ *
+ * @throws StrategyUnavailableException if we cannot use this strategy.
+ */
+ public static function getCandidates($type);
+}
diff --git a/inc/mailgun/php-http/discovery/src/Strategy/MockClientStrategy.php b/inc/mailgun/php-http/discovery/src/Strategy/MockClientStrategy.php
new file mode 100644
index 0000000..ea464cf
--- /dev/null
+++ b/inc/mailgun/php-http/discovery/src/Strategy/MockClientStrategy.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace Http\Discovery\Strategy;
+
+use Http\Client\HttpClient;
+use Http\Mock\Client as Mock;
+
+/**
+ * Find the Mock client.
+ *
+ * @author Sam Rapaport <me@samrapdev.com>
+ */
+final class MockClientStrategy implements DiscoveryStrategy
+{
+ /**
+ * {@inheritdoc}
+ */
+ public static function getCandidates($type)
+ {
+ return ($type === HttpClient::class)
+ ? [['class' => Mock::class, 'condition' => Mock::class]]
+ : [];
+ }
+}
diff --git a/inc/mailgun/php-http/discovery/src/Strategy/PuliBetaStrategy.php b/inc/mailgun/php-http/discovery/src/Strategy/PuliBetaStrategy.php
new file mode 100644
index 0000000..2666fb3
--- /dev/null
+++ b/inc/mailgun/php-http/discovery/src/Strategy/PuliBetaStrategy.php
@@ -0,0 +1,91 @@
+<?php
+
+namespace Http\Discovery\Strategy;
+
+use Http\Discovery\Exception\PuliUnavailableException;
+use Puli\Discovery\Api\Discovery;
+use Puli\GeneratedPuliFactory;
+
+/**
+ * Find candidates using Puli.
+ *
+ * @internal
+ * @final
+ *
+ * @author David de Boer <david@ddeboer.nl>
+ * @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
+ */
+class PuliBetaStrategy implements DiscoveryStrategy
+{
+ /**
+ * @var GeneratedPuliFactory
+ */
+ protected static $puliFactory;
+
+ /**
+ * @var Discovery
+ */
+ protected static $puliDiscovery;
+
+ /**
+ * @return GeneratedPuliFactory
+ *
+ * @throws PuliUnavailableException
+ */
+ private static function getPuliFactory()
+ {
+ if (null === self::$puliFactory) {
+ if (!defined('PULI_FACTORY_CLASS')) {
+ throw new PuliUnavailableException('Puli Factory is not available');
+ }
+
+ $puliFactoryClass = PULI_FACTORY_CLASS;
+
+ if (!class_exists($puliFactoryClass)) {
+ throw new PuliUnavailableException('Puli Factory class does not exist');
+ }
+
+ self::$puliFactory = new $puliFactoryClass();
+ }
+
+ return self::$puliFactory;
+ }
+
+ /**
+ * Returns the Puli discovery layer.
+ *
+ * @return Discovery
+ *
+ * @throws PuliUnavailableException
+ */
+ private static function getPuliDiscovery()
+ {
+ if (!isset(self::$puliDiscovery)) {
+ $factory = self::getPuliFactory();
+ $repository = $factory->createRepository();
+
+ self::$puliDiscovery = $factory->createDiscovery($repository);
+ }
+
+ return self::$puliDiscovery;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getCandidates($type)
+ {
+ $returnData = [];
+ $bindings = self::getPuliDiscovery()->findBindings($type);
+
+ foreach ($bindings as $binding) {
+ $condition = true;
+ if ($binding->hasParameterValue('depends')) {
+ $condition = $binding->getParameterValue('depends');
+ }
+ $returnData[] = ['class' => $binding->getClassName(), 'condition' => $condition];
+ }
+
+ return $returnData;
+ }
+}
diff --git a/inc/mailgun/php-http/discovery/src/StreamFactoryDiscovery.php b/inc/mailgun/php-http/discovery/src/StreamFactoryDiscovery.php
new file mode 100644
index 0000000..7bcc8ce
--- /dev/null
+++ b/inc/mailgun/php-http/discovery/src/StreamFactoryDiscovery.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace Http\Discovery;
+
+use Http\Discovery\Exception\DiscoveryFailedException;
+use Http\Message\StreamFactory;
+
+/**
+ * Finds a Stream Factory.
+ *
+ * @author Михаил Красильников <m.krasilnikov@yandex.ru>
+ */
+final class StreamFactoryDiscovery extends ClassDiscovery
+{
+ /**
+ * Finds a Stream Factory.
+ *
+ * @return StreamFactory
+ *
+ * @throws Exception\NotFoundException
+ */
+ public static function find()
+ {
+ try {
+ $streamFactory = static::findOneByType(StreamFactory::class);
+ } catch (DiscoveryFailedException $e) {
+ throw new NotFoundException(
+ 'No stream factories found. To use Guzzle, Diactoros or Slim Framework factories install php-http/message and the chosen message implementation.',
+ 0,
+ $e
+ );
+ }
+
+ return static::instantiateClass($streamFactory);
+ }
+}
diff --git a/inc/mailgun/php-http/discovery/src/UriFactoryDiscovery.php b/inc/mailgun/php-http/discovery/src/UriFactoryDiscovery.php
new file mode 100644
index 0000000..1eef1e6
--- /dev/null
+++ b/inc/mailgun/php-http/discovery/src/UriFactoryDiscovery.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace Http\Discovery;
+
+use Http\Discovery\Exception\DiscoveryFailedException;
+use Http\Message\UriFactory;
+
+/**
+ * Finds a URI Factory.
+ *
+ * @author David de Boer <david@ddeboer.nl>
+ */
+final class UriFactoryDiscovery extends ClassDiscovery
+{
+ /**
+ * Finds a URI Factory.
+ *
+ * @return UriFactory
+ *
+ * @throws Exception\NotFoundException
+ */
+ public static function find()
+ {
+ try {
+ $uriFactory = static::findOneByType(UriFactory::class);
+ } catch (DiscoveryFailedException $e) {
+ throw new NotFoundException(
+ 'No uri factories found. To use Guzzle, Diactoros or Slim Framework factories install php-http/message and the chosen message implementation.',
+ 0,
+ $e
+ );
+ }
+
+ return static::instantiateClass($uriFactory);
+ }
+}