diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2024-05-27 13:08:29 +0200 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2024-05-27 13:08:29 +0200 |
commit | 75160b12821f7f4299cce7f0b69c83c1502ae071 (patch) | |
tree | 27e25e4ccaef45f0c58b22831164050d1af1d4db /vendor/paypal/paypalhttp | |
parent | prvi-commit (diff) | |
download | 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.gz 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.bz2 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.lz 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.xz 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.zst 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.zip |
Diffstat (limited to 'vendor/paypal/paypalhttp')
25 files changed, 1078 insertions, 1062 deletions
diff --git a/vendor/paypal/paypalhttp/.gitattributes b/vendor/paypal/paypalhttp/.gitattributes index ec6c2f5..3daf525 100644 --- a/vendor/paypal/paypalhttp/.gitattributes +++ b/vendor/paypal/paypalhttp/.gitattributes @@ -1,7 +1,7 @@ -tests/ export-ignore -.idea/ export-ignore -.github/ export-ignore -.releasinator.rb export-ignore -Gemfile export-ignore -Gemfile.lock export-ignore - +tests/ export-ignore
+.idea/ export-ignore
+.github/ export-ignore
+.releasinator.rb export-ignore
+Gemfile export-ignore
+Gemfile.lock export-ignore
+
diff --git a/vendor/paypal/paypalhttp/.gitignore b/vendor/paypal/paypalhttp/.gitignore index 2efb91f..9adda60 100644 --- a/vendor/paypal/paypalhttp/.gitignore +++ b/vendor/paypal/paypalhttp/.gitignore @@ -1,32 +1,32 @@ -.DS_Store -/vendor/ -composer.phar -composer.lock - -# User-specific stuff: -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/dictionaries - -.idea/codeStyles/Project.xml -.idea/codeStyles/codeStyleConfig.xml -.idea/* - -# Sensitive or high-churn files: -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.xml -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml - -## File-based project format: -*.iws -.idea/*.iml -.idea/vcs.xml -.idea/php.xml -.idea/php-test-framework.xml -.idea/modules.xml -__files/* -mappings/* +.DS_Store
+/vendor/
+composer.phar
+composer.lock
+
+# User-specific stuff:
+.idea/**/workspace.xml
+.idea/**/tasks.xml
+.idea/dictionaries
+
+.idea/codeStyles/Project.xml
+.idea/codeStyles/codeStyleConfig.xml
+.idea/*
+
+# Sensitive or high-churn files:
+.idea/**/dataSources/
+.idea/**/dataSources.ids
+.idea/**/dataSources.xml
+.idea/**/dataSources.local.xml
+.idea/**/sqlDataSources.xml
+.idea/**/dynamic.xml
+.idea/**/uiDesigner.xml
+
+## File-based project format:
+*.iws
+.idea/*.iml
+.idea/vcs.xml
+.idea/php.xml
+.idea/php-test-framework.xml
+.idea/modules.xml
+__files/*
+mappings/*
diff --git a/vendor/paypal/paypalhttp/.travis.yml b/vendor/paypal/paypalhttp/.travis.yml index 4fddbb9..926af50 100644 --- a/vendor/paypal/paypalhttp/.travis.yml +++ b/vendor/paypal/paypalhttp/.travis.yml @@ -1,16 +1,16 @@ -sudo: false -language: php -php: -- 5.6 -- 7.0 -- 7.1 -- hhvm -matrix: - allow_failures: - - php: hhvm - fast_finish: true -before_script: -- composer self-update -- composer install --dev -script: -- vendor/bin/phpunit +sudo: false
+language: php
+php:
+- 5.6
+- 7.0
+- 7.1
+- hhvm
+matrix:
+ allow_failures:
+ - php: hhvm
+ fast_finish: true
+before_script:
+- composer self-update
+- composer install --dev
+script:
+- vendor/bin/phpunit
diff --git a/vendor/paypal/paypalhttp/CHANGELOG.md b/vendor/paypal/paypalhttp/CHANGELOG.md index f55b907..e613b6b 100644 --- a/vendor/paypal/paypalhttp/CHANGELOG.md +++ b/vendor/paypal/paypalhttp/CHANGELOG.md @@ -1,2 +1,5 @@ -## 1.0.0 -- First release +## 1.0.1
+* Fix Case Sensitivity of Content Type for deserialization process
+
+## 1.0.0
+- First release
diff --git a/vendor/paypal/paypalhttp/CONTRIBUTING.md b/vendor/paypal/paypalhttp/CONTRIBUTING.md index 3810a58..f551146 100644 --- a/vendor/paypal/paypalhttp/CONTRIBUTING.md +++ b/vendor/paypal/paypalhttp/CONTRIBUTING.md @@ -1,10 +1,10 @@ -# Contribute to the PayPal PHP HttpClient - -### *Pull requests are welcome!* - -General Guidelines ------------------- - -* **Code style.** Please follow local code style. Ask if you're unsure. -* **No warnings.** All generated code must compile without warnings. - +# Contribute to the PayPal PHP HttpClient
+
+### *Pull requests are welcome!*
+
+General Guidelines
+------------------
+
+* **Code style.** Please follow local code style. Ask if you're unsure.
+* **No warnings.** All generated code must compile without warnings.
+
diff --git a/vendor/paypal/paypalhttp/LICENSE b/vendor/paypal/paypalhttp/LICENSE index c689d74..42062c4 100644 --- a/vendor/paypal/paypalhttp/LICENSE +++ b/vendor/paypal/paypalhttp/LICENSE @@ -1,23 +1,23 @@ -Copyright (c) 2009-2016 PayPal, Inc. - -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. - +Copyright (c) 2009-2021 PayPal, Inc.
+
+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/vendor/paypal/paypalhttp/README.md b/vendor/paypal/paypalhttp/README.md index c4bc958..ff1773b 100644 --- a/vendor/paypal/paypalhttp/README.md +++ b/vendor/paypal/paypalhttp/README.md @@ -1,76 +1,76 @@ -## PayPal HttpClient - -PayPalHttp is a generic HTTP Client. - -In it's simplest form, an [`HttpClient`](lib/PayPalHttp/HttpClient.php) exposes an `execute` method which takes an [HTTP request](lib/PayPalHttp/HttpRequest.php), executes it against the domain described in an [Environment](lib/PayPalHttp/Environment.php), and returns an [HTTP response](lib/PayPalHttp/HttpResponse.php). - -### Environment - -An [`Environment`](./lib/PayPalHttp/environment.rb) describes a domain that hosts a REST API, against which an `HttpClient` will make requests. `Environment` is a simple interface that wraps one method, `baseUrl`. - -```php -$env = new Environment('https://example.com'); -``` - -### Requests - -HTTP requests contain all the information needed to make an HTTP request against the REST API. Specifically, one request describes a path, a verb, any path/query/form parameters, headers, attached files for upload, and body data. - -### Responses - -HTTP responses contain information returned by a server in response to a request as described above. They are simple objects which contain a status code, headers, and any data returned by the server. - -```php -$request = new HttpRequest("/path", "GET"); -$request->body[] = "some data"; - -$response = $client->execute($req); - -$statusCode = $response->statusCode; -$headers = $response->headers; -$data = $response->result; -``` - -### Injectors - -Injectors are blocks that can be used for executing arbitrary pre-flight logic, such as modifying a request or logging data. Injectors are attached to an `HttpClient` using the `addInjector` method. - -The `HttpClient` executes its injectors in a first-in, first-out order, before each request. - -```php -class LogInjector implements Injector -{ - public function inject($httpRequest) - { - // Do some logging here - } -} - -$logInjector = new LogInjector(); -$client = new HttpClient($environment); -$client->addInjector($logInjector); -... -``` - -### Error Handling - -`HttpClient#execute` may throw an `Exception` if something went wrong during the course of execution. If the server returned a non-200 response, [IOException](lib/PayPalHttp/IOException.php) will be thrown, that will contain a status code and headers you can use for debugging. - -```php -try -{ - $client->execute($req); -} -catch (HttpException $e) -{ - $statusCode = $e->response->statusCode; - $headers = $e->response->headers; - $body = $e->response->result; -} -``` - -## License -PayPalHttp-PHP is open source and available under the MIT license. See the [LICENSE](./LICENSE) file for more information. - -## Contributing -Pull requests and issues are welcome. Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for more details. +## PayPal HttpClient
+
+PayPalHttp is a generic HTTP Client.
+
+In it's simplest form, an [`HttpClient`](lib/PayPalHttp/HttpClient.php) exposes an `execute` method which takes an [HTTP request](lib/PayPalHttp/HttpRequest.php), executes it against the domain described in an [Environment](lib/PayPalHttp/Environment.php), and returns an [HTTP response](lib/PayPalHttp/HttpResponse.php).
+
+### Environment
+
+An [`Environment`](./lib/PayPalHttp/environment.rb) describes a domain that hosts a REST API, against which an `HttpClient` will make requests. `Environment` is a simple interface that wraps one method, `baseUrl`.
+
+```php
+$env = new Environment('https://example.com');
+```
+
+### Requests
+
+HTTP requests contain all the information needed to make an HTTP request against the REST API. Specifically, one request describes a path, a verb, any path/query/form parameters, headers, attached files for upload, and body data.
+
+### Responses
+
+HTTP responses contain information returned by a server in response to a request as described above. They are simple objects which contain a status code, headers, and any data returned by the server.
+
+```php
+$request = new HttpRequest("/path", "GET");
+$request->body[] = "some data";
+
+$response = $client->execute($req);
+
+$statusCode = $response->statusCode;
+$headers = $response->headers;
+$data = $response->result;
+```
+
+### Injectors
+
+Injectors are blocks that can be used for executing arbitrary pre-flight logic, such as modifying a request or logging data. Injectors are attached to an `HttpClient` using the `addInjector` method.
+
+The `HttpClient` executes its injectors in a first-in, first-out order, before each request.
+
+```php
+class LogInjector implements Injector
+{
+ public function inject($httpRequest)
+ {
+ // Do some logging here
+ }
+}
+
+$logInjector = new LogInjector();
+$client = new HttpClient($environment);
+$client->addInjector($logInjector);
+...
+```
+
+### Error Handling
+
+`HttpClient#execute` may throw an `Exception` if something went wrong during the course of execution. If the server returned a non-200 response, [IOException](lib/PayPalHttp/IOException.php) will be thrown, that will contain a status code and headers you can use for debugging.
+
+```php
+try
+{
+ $client->execute($req);
+}
+catch (HttpException $e)
+{
+ $statusCode = $e->response->statusCode;
+ $headers = $e->response->headers;
+ $body = $e->response->result;
+}
+```
+
+## License
+PayPalHttp-PHP is open source and available under the MIT license. See the [LICENSE](./LICENSE) file for more information.
+
+## Contributing
+Pull requests and issues are welcome. Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for more details.
diff --git a/vendor/paypal/paypalhttp/Rakefile b/vendor/paypal/paypalhttp/Rakefile index 33a443c..30824c7 100644 --- a/vendor/paypal/paypalhttp/Rakefile +++ b/vendor/paypal/paypalhttp/Rakefile @@ -1,2 +1,2 @@ -spec = Gem::Specification.find_by_name 'releasinator' -load "#{spec.gem_dir}/lib/tasks/releasinator.rake" +spec = Gem::Specification.find_by_name 'releasinator'
+load "#{spec.gem_dir}/lib/tasks/releasinator.rake"
diff --git a/vendor/paypal/paypalhttp/composer.json b/vendor/paypal/paypalhttp/composer.json index 05728a3..dc1d85d 100644 --- a/vendor/paypal/paypalhttp/composer.json +++ b/vendor/paypal/paypalhttp/composer.json @@ -1,23 +1,23 @@ -{ - "name": "paypal/paypalhttp", - "type": "library", - "license": "MIT", - "authors": [ - { - "name": "PayPal", - "homepage": "https://github.com/paypal/paypalhttp_php/contributors" - } - ], - "require": { - "ext-curl": "*" - }, - "require-dev": { - "phpunit/phpunit": "^5.7", - "wiremock-php/wiremock-php": "1.43.2" - }, - "autoload": { - "psr-4": { - "PayPalHttp\\": "lib/PayPalHttp" - } - } -} +{
+ "name": "paypal/paypalhttp",
+ "type": "library",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "PayPal",
+ "homepage": "https://github.com/paypal/paypalhttp_php/contributors"
+ }
+ ],
+ "require": {
+ "ext-curl": "*"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^5.7",
+ "wiremock-php/wiremock-php": "1.43.2"
+ },
+ "autoload": {
+ "psr-4": {
+ "PayPalHttp\\": "lib/PayPalHttp"
+ }
+ }
+}
diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/Curl.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/Curl.php index 08e6eaf..9d5ce8f 100644 --- a/vendor/paypal/paypalhttp/lib/PayPalHttp/Curl.php +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/Curl.php @@ -1,57 +1,57 @@ -<?php - -namespace PayPalHttp; - -/** - * Class Curl - * @package PayPalHttp - * - * Curl wrapper used by HttpClient to make curl requests. - * @see HttpClient - */ -class Curl -{ - protected $curl; - - public function __construct($curl = NULL) - { - - if (is_null($curl)) - { - $curl = curl_init(); - } - $this->curl = $curl; - } - - public function setOpt($option, $value) - { - curl_setopt($this->curl, $option, $value); - return $this; - } - - public function close() - { - curl_close($this->curl); - return $this; - } - - public function exec() - { - return curl_exec($this->curl); - } - - public function errNo() - { - return curl_errno($this->curl); - } - - public function getInfo($option) - { - return curl_getinfo($this->curl, $option); - } - - public function error() - { - return curl_error($this->curl); - } -} +<?php
+
+namespace PayPalHttp;
+
+/**
+ * Class Curl
+ * @package PayPalHttp
+ *
+ * Curl wrapper used by HttpClient to make curl requests.
+ * @see HttpClient
+ */
+class Curl
+{
+ protected $curl;
+
+ public function __construct($curl = NULL)
+ {
+
+ if (is_null($curl))
+ {
+ $curl = curl_init();
+ }
+ $this->curl = $curl;
+ }
+
+ public function setOpt($option, $value)
+ {
+ curl_setopt($this->curl, $option, $value);
+ return $this;
+ }
+
+ public function close()
+ {
+ curl_close($this->curl);
+ return $this;
+ }
+
+ public function exec()
+ {
+ return curl_exec($this->curl);
+ }
+
+ public function errNo()
+ {
+ return curl_errno($this->curl);
+ }
+
+ public function getInfo($option)
+ {
+ return curl_getinfo($this->curl, $option);
+ }
+
+ public function error()
+ {
+ return curl_error($this->curl);
+ }
+}
diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/Encoder.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/Encoder.php index b7158a7..06ce88a 100644 --- a/vendor/paypal/paypalhttp/lib/PayPalHttp/Encoder.php +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/Encoder.php @@ -1,114 +1,115 @@ -<?php - -namespace PayPalHttp; - -use PayPalHttp\Serializer\Form; -use PayPalHttp\Serializer\Json; -use PayPalHttp\Serializer\Multipart; -use PayPalHttp\Serializer\Text; - -/** - * Class Encoder - * @package PayPalHttp - * - * Encoding class for serializing and deserializing request/response. - */ -class Encoder -{ - private $serializers = []; - - function __construct() - { - $this->serializers[] = new Json(); - $this->serializers[] = new Text(); - $this->serializers[] = new Multipart(); - $this->serializers[] = new Form(); - } - - - - public function serializeRequest(HttpRequest $request) - { - if (!array_key_exists('content-type', $request->headers)) { - $message = "HttpRequest does not have Content-Type header set"; - echo $message; - throw new \Exception($message); - } - - $contentType = $request->headers['content-type']; - /** @var Serializer $serializer */ - $serializer = $this->serializer($contentType); - - if (is_null($serializer)) { - $message = sprintf("Unable to serialize request with Content-Type: %s. Supported encodings are: %s", $contentType, implode(", ", $this->supportedEncodings())); - echo $message; - throw new \Exception($message); - } - - if (!(is_string($request->body) || is_array($request->body))) { - $message = "Body must be either string or array"; - echo $message; - throw new \Exception($message); - } - - $serialized = $serializer->encode($request); - - if (array_key_exists("content-encoding", $request->headers) && $request->headers["content-encoding"] === "gzip") { - $serialized = gzencode($serialized); - } - return $serialized; - } - - - public function deserializeResponse($responseBody, $headers) - { - - if (!array_key_exists('content-type', $headers)) { - $message = "HTTP response does not have Content-Type header set"; - echo $message; - throw new \Exception($message); - } - - $contentType = $headers['content-type']; - /** @var Serializer $serializer */ - $serializer = $this->serializer($contentType); - - if (is_null($serializer)) { - throw new \Exception(sprintf("Unable to deserialize response with Content-Type: %s. Supported encodings are: %s", $contentType, implode(", ", $this->supportedEncodings()))); - } - - if (array_key_exists("content-encoding", $headers) && $headers["content-encoding"] === "gzip") { - $responseBody = gzdecode($responseBody); - } - - return $serializer->decode($responseBody); - } - - private function serializer($contentType) - { - /** @var Serializer $serializer */ - foreach ($this->serializers as $serializer) { - try { - if (preg_match($serializer->contentType(), $contentType) == 1) { - return $serializer; - } - } catch (\Exception $ex) { - $message = sprintf("Error while checking content type of %s: %s", get_class($serializer), $ex->getMessage()); - echo $message; - throw new \Exception($message, $ex->getCode(), $ex); - } - } - - return NULL; - } - - private function supportedEncodings() - { - $values = []; - /** @var Serializer $serializer */ - foreach ($this->serializers as $serializer) { - $values[] = $serializer->contentType(); - } - return $values; - } -} +<?php
+
+namespace PayPalHttp;
+
+use PayPalHttp\Serializer\Form;
+use PayPalHttp\Serializer\Json;
+use PayPalHttp\Serializer\Multipart;
+use PayPalHttp\Serializer\Text;
+
+/**
+ * Class Encoder
+ * @package PayPalHttp
+ *
+ * Encoding class for serializing and deserializing request/response.
+ */
+class Encoder
+{
+ private $serializers = [];
+
+ function __construct()
+ {
+ $this->serializers[] = new Json();
+ $this->serializers[] = new Text();
+ $this->serializers[] = new Multipart();
+ $this->serializers[] = new Form();
+ }
+
+
+
+ public function serializeRequest(HttpRequest $request)
+ {
+ if (!array_key_exists('content-type', $request->headers)) {
+ $message = "HttpRequest does not have Content-Type header set";
+ echo $message;
+ throw new \Exception($message);
+ }
+
+ $contentType = $request->headers['content-type'];
+ /** @var Serializer $serializer */
+ $serializer = $this->serializer($contentType);
+
+ if (is_null($serializer)) {
+ $message = sprintf("Unable to serialize request with Content-Type: %s. Supported encodings are: %s", $contentType, implode(", ", $this->supportedEncodings()));
+ echo $message;
+ throw new \Exception($message);
+ }
+
+ if (!(is_string($request->body) || is_array($request->body))) {
+ $message = "Body must be either string or array";
+ echo $message;
+ throw new \Exception($message);
+ }
+
+ $serialized = $serializer->encode($request);
+
+ if (array_key_exists("content-encoding", $request->headers) && $request->headers["content-encoding"] === "gzip") {
+ $serialized = gzencode($serialized);
+ }
+ return $serialized;
+ }
+
+
+ public function deserializeResponse($responseBody, $headers)
+ {
+
+ if (!array_key_exists('content-type', $headers)) {
+ $message = "HTTP response does not have Content-Type header set";
+ echo $message;
+ throw new \Exception($message);
+ }
+
+ $contentType = $headers['content-type'];
+ $contentType = strtolower($contentType);
+ /** @var Serializer $serializer */
+ $serializer = $this->serializer($contentType);
+
+ if (is_null($serializer)) {
+ throw new \Exception(sprintf("Unable to deserialize response with Content-Type: %s. Supported encodings are: %s", $contentType, implode(", ", $this->supportedEncodings())));
+ }
+
+ if (array_key_exists("content-encoding", $headers) && $headers["content-encoding"] === "gzip") {
+ $responseBody = gzdecode($responseBody);
+ }
+
+ return $serializer->decode($responseBody);
+ }
+
+ private function serializer($contentType)
+ {
+ /** @var Serializer $serializer */
+ foreach ($this->serializers as $serializer) {
+ try {
+ if (preg_match($serializer->contentType(), $contentType) == 1) {
+ return $serializer;
+ }
+ } catch (\Exception $ex) {
+ $message = sprintf("Error while checking content type of %s: %s", get_class($serializer), $ex->getMessage());
+ echo $message;
+ throw new \Exception($message, $ex->getCode(), $ex);
+ }
+ }
+
+ return NULL;
+ }
+
+ private function supportedEncodings()
+ {
+ $values = [];
+ /** @var Serializer $serializer */
+ foreach ($this->serializers as $serializer) {
+ $values[] = $serializer->contentType();
+ }
+ return $values;
+ }
+}
diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/Environment.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/Environment.php index 4eb0ce0..0910a44 100644 --- a/vendor/paypal/paypalhttp/lib/PayPalHttp/Environment.php +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/Environment.php @@ -1,18 +1,18 @@ -<?php - -namespace PayPalHttp; - -/** - * Interface Environment - * @package PayPalHttp - * - * Describes a domain that hosts a REST API, against which an HttpClient will make requests. - * @see HttpClient - */ -interface Environment -{ - /** - * @return string - */ - public function baseUrl(); -} +<?php
+
+namespace PayPalHttp;
+
+/**
+ * Interface Environment
+ * @package PayPalHttp
+ *
+ * Describes a domain that hosts a REST API, against which an HttpClient will make requests.
+ * @see HttpClient
+ */
+interface Environment
+{
+ /**
+ * @return string
+ */
+ public function baseUrl();
+}
diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpClient.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpClient.php index dbbdb79..412d6c7 100644 --- a/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpClient.php +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpClient.php @@ -1,231 +1,238 @@ -<?php - -namespace PayPalHttp; - -/** - * Class HttpClient - * @package PayPalHttp - * - * Client used to make HTTP requests. - */ -class HttpClient -{ - /** - * @var Environment - */ - public $environment; - - /** - * @var Injector[] - */ - public $injectors = []; - - /** - * @var Encoder - */ - public $encoder; - - /** - * HttpClient constructor. Pass the environment you wish to make calls to. - * - * @param $environment Environment - * @see Environment - */ - function __construct(Environment $environment) - { - $this->environment = $environment; - $this->encoder = new Encoder(); - $this->curlCls = Curl::class; - } - - /** - * Injectors are blocks that can be used for executing arbitrary pre-flight logic, such as modifying a request or logging data. - * Executed in first-in first-out order. - * - * @param Injector $inj - */ - public function addInjector(Injector $inj) - { - $this->injectors[] = $inj; - } - - /** - * The method that takes an HTTP request, serializes the request, makes a call to given environment, and deserialize response - * - * @param $httpRequest HttpRequest - * @return HttpResponse - */ - public function execute(HttpRequest $httpRequest) - { - $requestCpy = clone $httpRequest; - $curl = new Curl(); - - foreach ($this->injectors as $inj) { - $inj->inject($requestCpy); - } - - $url = $this->environment->baseUrl() . $requestCpy->path; - $formattedHeaders = $this->prepareHeaders($requestCpy->headers); - if (!array_key_exists("user-agent", $formattedHeaders)) { - $requestCpy->headers["user-agent"] = $this->userAgent(); - } - - $body = ""; - if (!is_null($requestCpy->body)) { - $rawHeaders = $requestCpy->headers; - $requestCpy->headers = $formattedHeaders; - $body = $this->encoder->serializeRequest($requestCpy); - $requestCpy->headers = $this->mapHeaders($rawHeaders,$requestCpy->headers); - } - - $curl->setOpt(CURLOPT_URL, $url); - $curl->setOpt(CURLOPT_CUSTOMREQUEST, $requestCpy->verb); - $curl->setOpt(CURLOPT_HTTPHEADER, $this->serializeHeaders($requestCpy->headers)); - $curl->setOpt(CURLOPT_RETURNTRANSFER, 1); - $curl->setOpt(CURLOPT_HEADER, 0); - - if (!is_null($requestCpy->body)) { - $curl->setOpt(CURLOPT_POSTFIELDS, $body); - } - - if (strpos($this->environment->baseUrl(), "https://") === 0) { - $curl->setOpt(CURLOPT_SSL_VERIFYPEER, true); - $curl->setOpt(CURLOPT_SSL_VERIFYHOST, 2); - } - - if ($caCertPath = $this->getCACertFilePath()) { - $curl->setOpt(CURLOPT_CAINFO, $caCertPath); - } - - $response = $this->parseResponse($curl); - $curl->close(); - - return $response; - } - - /** - * Returns an array representing headers with their keys - * to be lower case - * @param $headers - * @return array - */ - public function prepareHeaders($headers){ - return array_change_key_case($headers); - } - - /** - * Returns an array representing headers with their key in - * original cases and updated values - * @param $rawHeaders - * @param $formattedHeaders - * @return array - */ - public function mapHeaders($rawHeaders, $formattedHeaders){ - $rawHeadersKey = array_keys($rawHeaders); - foreach ($rawHeadersKey as $array_key) { - if(array_key_exists(strtolower($array_key), $formattedHeaders)){ - $rawHeaders[$array_key] = $formattedHeaders[strtolower($array_key)]; - } - } - return $rawHeaders; - } - - /** - * Returns default user-agent - * - * @return string - */ - public function userAgent() - { - return "PayPalHttp-PHP HTTP/1.1"; - } - - /** - * Return the filepath to your custom CA Cert if needed. - * @return string - */ - protected function getCACertFilePath() - { - return null; - } - - protected function setCurl(Curl $curl) - { - $this->curl = $curl; - } - - protected function setEncoder(Encoder $encoder) - { - $this->encoder = $encoder; - } - - private function serializeHeaders($headers) - { - $headerArray = []; - if ($headers) { - foreach ($headers as $key => $val) { - $headerArray[] = $key . ": " . $val; - } - } - - return $headerArray; - } - - private function parseResponse($curl) - { - $headers = []; - $curl->setOpt(CURLOPT_HEADERFUNCTION, - function($curl, $header) use (&$headers) - { - $len = strlen($header); - - $k = ""; - $v = ""; - - $this->deserializeHeader($header, $k, $v); - $headers[$k] = $v; - - return $len; - }); - - $responseData = $curl->exec(); - $statusCode = $curl->getInfo(CURLINFO_HTTP_CODE); - $errorCode = $curl->errNo(); - $error = $curl->error(); - - if ($errorCode > 0) { - throw new IOException($error, $errorCode); - } - - $body = $responseData; - - if ($statusCode >= 200 && $statusCode < 300) { - $responseBody = NULL; - - if (!empty($body)) { - $responseBody = $this->encoder->deserializeResponse($body, $this->prepareHeaders($headers)); - } - - return new HttpResponse( - $errorCode === 0 ? $statusCode : $errorCode, - $responseBody, - $headers - ); - } else { - throw new HttpException($body, $statusCode, $headers); - } - } - - private function deserializeHeader($header, &$key, &$value) - { - if (strlen($header) > 0) { - if (empty($header) || strpos($header, ':') === false) { - return NULL; - } - - list($k, $v) = explode(":", $header); - $key = trim($k); - $value = trim($v); - } - } -} +<?php
+
+namespace PayPalHttp;
+
+/**
+ * Class HttpClient
+ * @package PayPalHttp
+ *
+ * Client used to make HTTP requests.
+ */
+class HttpClient
+{
+ /**
+ * @var Environment
+ */
+ public $environment;
+
+ /**
+ * @var Injector[]
+ */
+ public $injectors = [];
+
+ /**
+ * @var Encoder
+ */
+ public $encoder;
+
+ /**
+ * HttpClient constructor. Pass the environment you wish to make calls to.
+ *
+ * @param Environment $environment
+ * @see Environment
+ */
+ function __construct(Environment $environment)
+ {
+ $this->environment = $environment;
+ $this->encoder = new Encoder();
+ $this->curlCls = Curl::class;
+ }
+
+ /**
+ * Injectors are blocks that can be used for executing arbitrary pre-flight logic, such as modifying a request or logging data.
+ * Executed in first-in first-out order.
+ *
+ * @param Injector $inj
+ */
+ public function addInjector(Injector $inj)
+ {
+ $this->injectors[] = $inj;
+ }
+
+ /**
+ * The method that takes an HTTP request, serializes the request, makes a call to given environment, and deserialize response
+ *
+ * @param HttpRequest $httpRequest
+ * @return HttpResponse
+ *
+ * @throws HttpException
+ * @throws IOException
+ */
+ public function execute(HttpRequest $httpRequest)
+ {
+ $requestCpy = clone $httpRequest;
+ $curl = new Curl();
+
+ foreach ($this->injectors as $inj) {
+ $inj->inject($requestCpy);
+ }
+
+ $url = $this->environment->baseUrl() . $requestCpy->path;
+ $formattedHeaders = $this->prepareHeaders($requestCpy->headers);
+ if (!array_key_exists("user-agent", $formattedHeaders)) {
+ $requestCpy->headers["user-agent"] = $this->userAgent();
+ }
+
+ $body = "";
+ if (!is_null($requestCpy->body)) {
+ $rawHeaders = $requestCpy->headers;
+ $requestCpy->headers = $formattedHeaders;
+ $body = $this->encoder->serializeRequest($requestCpy);
+ $requestCpy->headers = $this->mapHeaders($rawHeaders,$requestCpy->headers);
+ }
+
+ $curl->setOpt(CURLOPT_URL, $url);
+ $curl->setOpt(CURLOPT_CUSTOMREQUEST, $requestCpy->verb);
+ $curl->setOpt(CURLOPT_HTTPHEADER, $this->serializeHeaders($requestCpy->headers));
+ $curl->setOpt(CURLOPT_RETURNTRANSFER, 1);
+ $curl->setOpt(CURLOPT_HEADER, 0);
+
+ if (!is_null($requestCpy->body)) {
+ $curl->setOpt(CURLOPT_POSTFIELDS, $body);
+ }
+
+ if (strpos($this->environment->baseUrl(), "https://") === 0) {
+ $curl->setOpt(CURLOPT_SSL_VERIFYPEER, true);
+ $curl->setOpt(CURLOPT_SSL_VERIFYHOST, 2);
+ }
+
+ if ($caCertPath = $this->getCACertFilePath()) {
+ $curl->setOpt(CURLOPT_CAINFO, $caCertPath);
+ }
+
+ $response = $this->parseResponse($curl);
+ $curl->close();
+
+ return $response;
+ }
+
+ /**
+ * Returns an array representing headers with their keys
+ * to be lower case
+ * @param $headers
+ * @return array
+ */
+ public function prepareHeaders($headers){
+ $preparedHeaders = array_change_key_case($headers);
+ if (array_key_exists("content-type", $preparedHeaders)) {
+ $preparedHeaders["content-type"] = strtolower($preparedHeaders["content-type"]);
+ }
+ return $preparedHeaders;
+ }
+
+ /**
+ * Returns an array representing headers with their key in
+ * original cases and updated values
+ * @param $rawHeaders
+ * @param $formattedHeaders
+ * @return array
+ */
+ public function mapHeaders($rawHeaders, $formattedHeaders){
+ $rawHeadersKey = array_keys($rawHeaders);
+ foreach ($rawHeadersKey as $array_key) {
+ if(array_key_exists(strtolower($array_key), $formattedHeaders)){
+ $rawHeaders[$array_key] = $formattedHeaders[strtolower($array_key)];
+ }
+ }
+ return $rawHeaders;
+ }
+
+ /**
+ * Returns default user-agent
+ *
+ * @return string
+ */
+ public function userAgent()
+ {
+ return "PayPalHttp-PHP HTTP/1.1";
+ }
+
+ /**
+ * Return the filepath to your custom CA Cert if needed.
+ * @return string
+ */
+ protected function getCACertFilePath()
+ {
+ return null;
+ }
+
+ protected function setCurl(Curl $curl)
+ {
+ $this->curl = $curl;
+ }
+
+ protected function setEncoder(Encoder $encoder)
+ {
+ $this->encoder = $encoder;
+ }
+
+ private function serializeHeaders($headers)
+ {
+ $headerArray = [];
+ if ($headers) {
+ foreach ($headers as $key => $val) {
+ $headerArray[] = $key . ": " . $val;
+ }
+ }
+
+ return $headerArray;
+ }
+
+ private function parseResponse($curl)
+ {
+ $headers = [];
+ $curl->setOpt(CURLOPT_HEADERFUNCTION,
+ function($curl, $header) use (&$headers)
+ {
+ $len = strlen($header);
+
+ $k = "";
+ $v = "";
+
+ $this->deserializeHeader($header, $k, $v);
+ $headers[$k] = $v;
+
+ return $len;
+ });
+
+ $responseData = $curl->exec();
+ $statusCode = $curl->getInfo(CURLINFO_HTTP_CODE);
+ $errorCode = $curl->errNo();
+ $error = $curl->error();
+
+ if ($errorCode > 0) {
+ throw new IOException($error, $errorCode);
+ }
+
+ $body = $responseData;
+
+ if ($statusCode >= 200 && $statusCode < 300) {
+ $responseBody = NULL;
+
+ if (!empty($body)) {
+ $responseBody = $this->encoder->deserializeResponse($body, $this->prepareHeaders($headers));
+ }
+
+ return new HttpResponse(
+ $errorCode === 0 ? $statusCode : $errorCode,
+ $responseBody,
+ $headers
+ );
+ } else {
+ throw new HttpException($body, $statusCode, $headers);
+ }
+ }
+
+ private function deserializeHeader($header, &$key, &$value)
+ {
+ if (strlen($header) > 0) {
+ if (empty($header) || strpos($header, ':') === false) {
+ return NULL;
+ }
+
+ list($k, $v) = explode(":", $header);
+ $key = trim($k);
+ $value = trim($v);
+ }
+ }
+}
diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpException.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpException.php index 5f4d2db..3551786 100644 --- a/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpException.php +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpException.php @@ -1,23 +1,28 @@ -<?php - -namespace PayPalHttp; - -class HttpException extends IOException -{ - /** - * @var statusCode - */ - public $statusCode; - - public $headers; - - /** - * @param string $response - */ - public function __construct($message, $statusCode, $headers) - { - parent::__construct($message); - $this->statusCode = $statusCode; - $this->headers = $headers; - } -} +<?php
+
+namespace PayPalHttp;
+
+class HttpException extends IOException
+{
+ /**
+ * @var int
+ */
+ public $statusCode;
+
+ /**
+ * @var array
+ */
+ public $headers;
+
+ /**
+ * @param string $message
+ * @param int $statusCode
+ * @param array $headers
+ */
+ public function __construct($message, $statusCode, $headers)
+ {
+ parent::__construct($message);
+ $this->statusCode = $statusCode;
+ $this->headers = $headers;
+ }
+}
diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpRequest.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpRequest.php index 89b7480..656994a 100644 --- a/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpRequest.php +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpRequest.php @@ -1,42 +1,42 @@ -<?php - -namespace PayPalHttp; - -/** - * Class HttpRequest - * @package PayPalHttp - * - * Request object that holds all the necessary information required by HTTPClient - * - * @see HttpClient - */ -class HttpRequest -{ - /** - * @var string - */ - public $path; - - /** - * @var array | string - */ - public $body; - - /** - * @var string - */ - public $verb; - - /** - * @var array - */ - public $headers; - - function __construct($path, $verb) - { - $this->path = $path; - $this->verb = $verb; - $this->body = NULL; - $this->headers = []; - } -} +<?php
+
+namespace PayPalHttp;
+
+/**
+ * Class HttpRequest
+ * @package PayPalHttp
+ *
+ * Request object that holds all the necessary information required by HTTPClient
+ *
+ * @see HttpClient
+ */
+class HttpRequest
+{
+ /**
+ * @var string
+ */
+ public $path;
+
+ /**
+ * @var array | string
+ */
+ public $body;
+
+ /**
+ * @var string
+ */
+ public $verb;
+
+ /**
+ * @var array
+ */
+ public $headers;
+
+ function __construct($path, $verb)
+ {
+ $this->path = $path;
+ $this->verb = $verb;
+ $this->body = NULL;
+ $this->headers = [];
+ }
+}
diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpResponse.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpResponse.php index ef8fb35..7d46dd2 100644 --- a/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpResponse.php +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpResponse.php @@ -1,34 +1,34 @@ -<?php - -namespace PayPalHttp; - -/** - * Class HttpResponse - * @package PayPalHttp - * - * Object that holds your response details - */ -class HttpResponse -{ - /** - * @var integer - */ - public $statusCode; - - /** - * @var array | string - */ - public $result; - - /** - * @var array - */ - public $headers; - - public function __construct($statusCode, $body, $headers) - { - $this->statusCode = $statusCode; - $this->headers = $headers; - $this->result = $body; - } -} +<?php
+
+namespace PayPalHttp;
+
+/**
+ * Class HttpResponse
+ * @package PayPalHttp
+ *
+ * Object that holds your response details
+ */
+class HttpResponse
+{
+ /**
+ * @var int
+ */
+ public $statusCode;
+
+ /**
+ * @var array | string | object
+ */
+ public $result;
+
+ /**
+ * @var array
+ */
+ public $headers;
+
+ public function __construct($statusCode, $body, $headers)
+ {
+ $this->statusCode = $statusCode;
+ $this->headers = $headers;
+ $this->result = $body;
+ }
+}
diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/IOException.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/IOException.php index 7bfc91c..401b438 100644 --- a/vendor/paypal/paypalhttp/lib/PayPalHttp/IOException.php +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/IOException.php @@ -1,13 +1,13 @@ -<?php - -namespace PayPalHttp; - -use Throwable; - -class IOException extends \Exception -{ - public function __construct($message = "", $code = 0, Throwable $previous = null) - { - parent::__construct($message, $code, $previous); - } -} +<?php
+
+namespace PayPalHttp;
+
+use Throwable;
+
+class IOException extends \Exception
+{
+ public function __construct($message = "", $code = 0, Throwable $previous = null)
+ {
+ parent::__construct($message, $code, $previous);
+ }
+}
diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/Injector.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/Injector.php index 3ae23c7..2008707 100644 --- a/vendor/paypal/paypalhttp/lib/PayPalHttp/Injector.php +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/Injector.php @@ -1,19 +1,19 @@ -<?php - -namespace PayPalHttp; - -/** - * Interface Injector - * @package PayPalHttp - * - * Interface that can be implemented to apply injectors to Http client. - * - * @see HttpClient - */ -interface Injector -{ - /** - * @param $httpRequest HttpRequest - */ - public function inject($httpRequest); -} +<?php
+
+namespace PayPalHttp;
+
+/**
+ * Interface Injector
+ * @package PayPalHttp
+ *
+ * Interface that can be implemented to apply injectors to Http client.
+ *
+ * @see HttpClient
+ */
+interface Injector
+{
+ /**
+ * @param HttpRequest $httpRequest
+ */
+ public function inject($httpRequest);
+}
diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer.php index 2edcfe2..a3e88ad 100644 --- a/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer.php +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer.php @@ -1,29 +1,29 @@ -<?php - -namespace PayPalHttp; - -/** - * Interface Serializer - * @package PayPalHttp - * - * Used to implement different serializers for different content types - */ -interface Serializer -{ - /** - * @return string Regex that matches the content type it supports. - */ - public function contentType(); - - /** - * @param HttpRequest $request - * @return string representation of your data after being serialized. - */ - public function encode(HttpRequest $request); - - /** - * @param $body - * @return mixed object/string representing the de-serialized response body. - */ - public function decode($body); -} +<?php
+
+namespace PayPalHttp;
+
+/**
+ * Interface Serializer
+ * @package PayPalHttp
+ *
+ * Used to implement different serializers for different content types
+ */
+interface Serializer
+{
+ /**
+ * @return string Regex that matches the content type it supports.
+ */
+ public function contentType();
+
+ /**
+ * @param HttpRequest $request
+ * @return string representation of your data after being serialized.
+ */
+ public function encode(HttpRequest $request);
+
+ /**
+ * @param $body
+ * @return mixed object/string representing the de-serialized response body.
+ */
+ public function decode($body);
+}
diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Form.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Form.php index bead9d3..18aa064 100644 --- a/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Form.php +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Form.php @@ -1,46 +1,46 @@ -<?php - -namespace PayPalHttp\Serializer; - -use PayPalHttp\HttpRequest; -use PayPalHttp\Serializer; - -class Form implements Serializer -{ - /** - * @return string Regex that matches the content type it supports. - */ - public function contentType() - { - return "/^application\/x-www-form-urlencoded$/"; - } - - /** - * @param HttpRequest $request - * @return string representation of your data after being serialized. - */ - public function encode(HttpRequest $request) - { - if (!is_array($request->body) || !$this->isAssociative($request->body)) - { - throw new \Exception("HttpRequest body must be an associative array when Content-Type is: " . $request->headers["Content-Type"]); - } - - return http_build_query($request->body); - } - - /** - * @param $body - * @return mixed - * @throws \Exception as multipart does not support deserialization. - */ - public function decode($body) - { - throw new \Exception("CurlSupported does not support deserialization"); - } - - private function isAssociative(array $array) - { - return array_values($array) !== $array; - } -} +<?php
+
+namespace PayPalHttp\Serializer;
+
+use PayPalHttp\HttpRequest;
+use PayPalHttp\Serializer;
+
+class Form implements Serializer
+{
+ /**
+ * @return string Regex that matches the content type it supports.
+ */
+ public function contentType()
+ {
+ return "/^application\/x-www-form-urlencoded$/";
+ }
+
+ /**
+ * @param HttpRequest $request
+ * @return string representation of your data after being serialized.
+ */
+ public function encode(HttpRequest $request)
+ {
+ if (!is_array($request->body) || !$this->isAssociative($request->body))
+ {
+ throw new \Exception("HttpRequest body must be an associative array when Content-Type is: " . $request->headers["Content-Type"]);
+ }
+
+ return http_build_query($request->body);
+ }
+
+ /**
+ * @param $body
+ * @return mixed
+ * @throws \Exception as multipart does not support deserialization.
+ */
+ public function decode($body)
+ {
+ throw new \Exception("CurlSupported does not support deserialization");
+ }
+
+ private function isAssociative(array $array)
+ {
+ return array_values($array) !== $array;
+ }
+}
diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/FormPart.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/FormPart.php index 3779a9b..5c40026 100644 --- a/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/FormPart.php +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/FormPart.php @@ -1,25 +1,25 @@ -<?php - -namespace PayPalHttp\Serializer; - -class FormPart -{ - private $value; - private $headers; - - public function __construct($value, $headers) - { - $this->value = $value; - $this->headers = array_merge([], $headers); - } - - public function getValue() - { - return $this->value; - } - - public function getHeaders() - { - return $this->headers; - } -} +<?php
+
+namespace PayPalHttp\Serializer;
+
+class FormPart
+{
+ private $value;
+ private $headers;
+
+ public function __construct($value, $headers)
+ {
+ $this->value = $value;
+ $this->headers = array_merge([], $headers);
+ }
+
+ public function getValue()
+ {
+ return $this->value;
+ }
+
+ public function getHeaders()
+ {
+ return $this->headers;
+ }
+}
diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Json.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Json.php index 3f66314..a73897c 100644 --- a/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Json.php +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Json.php @@ -1,38 +1,38 @@ -<?php - -namespace PayPalHttp\Serializer; - -use PayPalHttp\HttpRequest; -use PayPalHttp\Serializer; - -/** - * Class Json - * @package PayPalHttp\Serializer - * - * Serializer for JSON content types. - */ -class Json implements Serializer -{ - - public function contentType() - { - return "/^application\\/json/"; - } - - public function encode(HttpRequest $request) - { - $body = $request->body; - if (is_string($body)) { - return $body; - } - if (is_array($body)) { - return json_encode($body); - } - throw new \Exception("Cannot serialize data. Unknown type"); - } - - public function decode($data) - { - return json_decode($data); - } -} +<?php
+
+namespace PayPalHttp\Serializer;
+
+use PayPalHttp\HttpRequest;
+use PayPalHttp\Serializer;
+
+/**
+ * Class Json
+ * @package PayPalHttp\Serializer
+ *
+ * Serializer for JSON content types.
+ */
+class Json implements Serializer
+{
+
+ public function contentType()
+ {
+ return "/^application\\/json/";
+ }
+
+ public function encode(HttpRequest $request)
+ {
+ $body = $request->body;
+ if (is_string($body)) {
+ return $body;
+ }
+ if (is_array($body)) {
+ return json_encode($body);
+ }
+ throw new \Exception("Cannot serialize data. Unknown type");
+ }
+
+ public function decode($data)
+ {
+ return json_decode($data);
+ }
+}
diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Multipart.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Multipart.php index a420205..b9142de 100644 --- a/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Multipart.php +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Multipart.php @@ -1,134 +1,134 @@ -<?php - -namespace PayPalHttp\Serializer; - -use finfo; -use PayPalHttp\HttpRequest; -use PayPalHttp\Serializer; -use PayPalHttp\Encoder; -use PayPalHttp\Serializer\FormPart; - -/** - * Class Multipart - * @package PayPalHttp\Serializer - * - * Serializer for multipart. - */ -class Multipart implements Serializer -{ - const LINEFEED = "\r\n"; - - public function contentType() - { - return "/^multipart\/.*$/"; - } - - public function encode(HttpRequest $request) - { - if (!is_array($request->body) || !$this->isAssociative($request->body)) - { - throw new \Exception("HttpRequest body must be an associative array when Content-Type is: " . $request->headers["content-type"]); - } - $boundary = "---------------------" . md5(mt_rand() . microtime()); - $contentTypeHeader = $request->headers["content-type"]; - $request->headers["content-type"] = "{$contentTypeHeader}; boundary={$boundary}"; - - $value_params = []; - $file_params = []; - - $disallow = ["\0", "\"", "\r", "\n"]; - - $body = []; - - foreach ($request->body as $k => $v) { - $k = str_replace($disallow, "_", $k); - if (is_resource($v)) { - $file_params[] = $this->prepareFilePart($k, $v, $boundary); - } else if ($v instanceof FormPart) { - $value_params[] = $this->prepareFormPart($k, $v, $boundary); - } else { - $value_params[] = $this->prepareFormField($k, $v, $boundary); - } - } - - $body = array_merge($value_params, $file_params); - - // add boundary for each parameters - array_walk($body, function (&$part) use ($boundary) { - $part = "--{$boundary}" . self::LINEFEED . "{$part}"; - }); - - // add final boundary - $body[] = "--{$boundary}--"; - $body[] = ""; - - return implode(self::LINEFEED, $body); - } - - public function decode($data) - { - throw new \Exception("Multipart does not support deserialization"); - } - - private function isAssociative(array $array) - { - return array_values($array) !== $array; - } - - private function prepareFormField($partName, $value, $boundary) - { - return implode(self::LINEFEED, [ - "Content-Disposition: form-data; name=\"{$partName}\"", - "", - filter_var($value), - ]); - } - - private function prepareFilePart($partName, $file, $boundary) - { - $fileInfo = new finfo(FILEINFO_MIME_TYPE); - $filePath = stream_get_meta_data($file)['uri']; - $data = file_get_contents($filePath); - $mimeType = $fileInfo->buffer($data); - - $splitFilePath = explode(DIRECTORY_SEPARATOR, $filePath); - $filePath = end($splitFilePath); - $disallow = ["\0", "\"", "\r", "\n"]; - $filePath = str_replace($disallow, "_", $filePath); - return implode(self::LINEFEED, [ - "Content-Disposition: form-data; name=\"{$partName}\"; filename=\"{$filePath}\"", - "Content-Type: {$mimeType}", - "", - $data, - ]); - } - - private function prepareFormPart($partName, $formPart, $boundary) - { - $contentDisposition = "Content-Disposition: form-data; name=\"{$partName}\""; - - $partHeaders = $formPart->getHeaders(); - $formattedheaders = array_change_key_case($partHeaders); - if (array_key_exists("content-type", $formattedheaders)) { - if ($formattedheaders["content-type"] === "application/json") { - $contentDisposition .= "; filename=\"{$partName}.json\""; - } - $tempRequest = new HttpRequest('/', 'POST'); - $tempRequest->headers = $formattedheaders; - $tempRequest->body = $formPart->getValue(); - $encoder = new Encoder(); - $partValue = $encoder->serializeRequest($tempRequest); - } else { - $partValue = $formPart->getValue(); - } - - $finalPartHeaders = []; - foreach ($partHeaders as $k => $v) { - $finalPartHeaders[] = "{$k}: {$v}"; - } - - $body = array_merge([$contentDisposition], $finalPartHeaders, [""], [$partValue]); - - return implode(self::LINEFEED, $body); - } -} +<?php
+
+namespace PayPalHttp\Serializer;
+
+use finfo;
+use PayPalHttp\HttpRequest;
+use PayPalHttp\Serializer;
+use PayPalHttp\Encoder;
+use PayPalHttp\Serializer\FormPart;
+
+/**
+ * Class Multipart
+ * @package PayPalHttp\Serializer
+ *
+ * Serializer for multipart.
+ */
+class Multipart implements Serializer
+{
+ const LINEFEED = "\r\n";
+
+ public function contentType()
+ {
+ return "/^multipart\/.*$/";
+ }
+
+ public function encode(HttpRequest $request)
+ {
+ if (!is_array($request->body) || !$this->isAssociative($request->body))
+ {
+ throw new \Exception("HttpRequest body must be an associative array when Content-Type is: " . $request->headers["content-type"]);
+ }
+ $boundary = "---------------------" . md5(mt_rand() . microtime());
+ $contentTypeHeader = $request->headers["content-type"];
+ $request->headers["content-type"] = "{$contentTypeHeader}; boundary={$boundary}";
+
+ $value_params = [];
+ $file_params = [];
+
+ $disallow = ["\0", "\"", "\r", "\n"];
+
+ $body = [];
+
+ foreach ($request->body as $k => $v) {
+ $k = str_replace($disallow, "_", $k);
+ if (is_resource($v)) {
+ $file_params[] = $this->prepareFilePart($k, $v, $boundary);
+ } else if ($v instanceof FormPart) {
+ $value_params[] = $this->prepareFormPart($k, $v, $boundary);
+ } else {
+ $value_params[] = $this->prepareFormField($k, $v, $boundary);
+ }
+ }
+
+ $body = array_merge($value_params, $file_params);
+
+ // add boundary for each parameters
+ array_walk($body, function (&$part) use ($boundary) {
+ $part = "--{$boundary}" . self::LINEFEED . "{$part}";
+ });
+
+ // add final boundary
+ $body[] = "--{$boundary}--";
+ $body[] = "";
+
+ return implode(self::LINEFEED, $body);
+ }
+
+ public function decode($data)
+ {
+ throw new \Exception("Multipart does not support deserialization");
+ }
+
+ private function isAssociative(array $array)
+ {
+ return array_values($array) !== $array;
+ }
+
+ private function prepareFormField($partName, $value, $boundary)
+ {
+ return implode(self::LINEFEED, [
+ "Content-Disposition: form-data; name=\"{$partName}\"",
+ "",
+ filter_var($value),
+ ]);
+ }
+
+ private function prepareFilePart($partName, $file, $boundary)
+ {
+ $fileInfo = new finfo(FILEINFO_MIME_TYPE);
+ $filePath = stream_get_meta_data($file)['uri'];
+ $data = file_get_contents($filePath);
+ $mimeType = $fileInfo->buffer($data);
+
+ $splitFilePath = explode(DIRECTORY_SEPARATOR, $filePath);
+ $filePath = end($splitFilePath);
+ $disallow = ["\0", "\"", "\r", "\n"];
+ $filePath = str_replace($disallow, "_", $filePath);
+ return implode(self::LINEFEED, [
+ "Content-Disposition: form-data; name=\"{$partName}\"; filename=\"{$filePath}\"",
+ "Content-Type: {$mimeType}",
+ "",
+ $data,
+ ]);
+ }
+
+ private function prepareFormPart($partName, $formPart, $boundary)
+ {
+ $contentDisposition = "Content-Disposition: form-data; name=\"{$partName}\"";
+
+ $partHeaders = $formPart->getHeaders();
+ $formattedheaders = array_change_key_case($partHeaders);
+ if (array_key_exists("content-type", $formattedheaders)) {
+ if ($formattedheaders["content-type"] === "application/json") {
+ $contentDisposition .= "; filename=\"{$partName}.json\"";
+ }
+ $tempRequest = new HttpRequest('/', 'POST');
+ $tempRequest->headers = $formattedheaders;
+ $tempRequest->body = $formPart->getValue();
+ $encoder = new Encoder();
+ $partValue = $encoder->serializeRequest($tempRequest);
+ } else {
+ $partValue = $formPart->getValue();
+ }
+
+ $finalPartHeaders = [];
+ foreach ($partHeaders as $k => $v) {
+ $finalPartHeaders[] = "{$k}: {$v}";
+ }
+
+ $body = array_merge([$contentDisposition], $finalPartHeaders, [""], [$partValue]);
+
+ return implode(self::LINEFEED, $body);
+ }
+}
diff --git a/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Text.php b/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Text.php index e2ce0ca..d6fa3cd 100644 --- a/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Text.php +++ b/vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Text.php @@ -1,38 +1,38 @@ -<?php - -namespace PayPalHttp\Serializer; - -use PayPalHttp\HttpRequest; -use PayPalHttp\Serializer; - -/** - * Class Text - * @package PayPalHttp\Serializer - * - * Serializer for Text content types. - */ -class Text implements Serializer -{ - - public function contentType() - { - return "/^text\\/.*/"; - } - - public function encode(HttpRequest $request) - { - $body = $request->body; - if (is_string($body)) { - return $body; - } - if (is_array($body)) { - return json_encode($body); - } - return implode(" ", $body); - } - - public function decode($data) - { - return $data; - } -} +<?php
+
+namespace PayPalHttp\Serializer;
+
+use PayPalHttp\HttpRequest;
+use PayPalHttp\Serializer;
+
+/**
+ * Class Text
+ * @package PayPalHttp\Serializer
+ *
+ * Serializer for Text content types.
+ */
+class Text implements Serializer
+{
+
+ public function contentType()
+ {
+ return "/^text\\/.*/";
+ }
+
+ public function encode(HttpRequest $request)
+ {
+ $body = $request->body;
+ if (is_string($body)) {
+ return $body;
+ }
+ if (is_array($body)) {
+ return json_encode($body);
+ }
+ return implode(" ", $body);
+ }
+
+ public function decode($data)
+ {
+ return $data;
+ }
+}
diff --git a/vendor/paypal/paypalhttp/phpunit.xml b/vendor/paypal/paypalhttp/phpunit.xml index ea84278..649fcd9 100644 --- a/vendor/paypal/paypalhttp/phpunit.xml +++ b/vendor/paypal/paypalhttp/phpunit.xml @@ -1,10 +1,10 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<phpunit bootstrap="./vendor/autoload.php"> - - <testsuites> - <testsuite name="unit"> - <directory>./tests/unit</directory> - </testsuite> - </testsuites> - -</phpunit> +<?xml version="1.0" encoding="UTF-8" ?>
+<phpunit bootstrap="./vendor/autoload.php">
+
+ <testsuites>
+ <testsuite name="unit">
+ <directory>./tests/unit</directory>
+ </testsuite>
+ </testsuites>
+
+</phpunit>
|