Subiendo proyecto completo sin restricciones de git ignore
This commit is contained in:
46
vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Form.php
vendored
Normal file
46
vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Form.php
vendored
Normal file
@@ -0,0 +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;
|
||||
}
|
||||
}
|
||||
25
vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/FormPart.php
vendored
Normal file
25
vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/FormPart.php
vendored
Normal file
@@ -0,0 +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;
|
||||
}
|
||||
}
|
||||
38
vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Json.php
vendored
Normal file
38
vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Json.php
vendored
Normal file
@@ -0,0 +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);
|
||||
}
|
||||
}
|
||||
134
vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Multipart.php
vendored
Normal file
134
vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Multipart.php
vendored
Normal file
@@ -0,0 +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);
|
||||
}
|
||||
}
|
||||
38
vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Text.php
vendored
Normal file
38
vendor/paypal/paypalhttp/lib/PayPalHttp/Serializer/Text.php
vendored
Normal file
@@ -0,0 +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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user