first commit
This commit is contained in:
248
lib/Internal/DefaultRequest.php
Normal file
248
lib/Internal/DefaultRequest.php
Normal file
@@ -0,0 +1,248 @@
|
||||
<?php
|
||||
|
||||
namespace Yeepay\Yop\Sdk\Internal;
|
||||
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Yeepay\Yop\Sdk\Http\Headers;
|
||||
|
||||
class DefaultRequest implements Request
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $resourcePath;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $parameters = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $multipartFiles = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $headers = [];
|
||||
|
||||
/**
|
||||
* @var Uri
|
||||
*/
|
||||
private $endpoint;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $serviceName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $httpMethod;
|
||||
|
||||
/**
|
||||
* @var StreamInterface
|
||||
*/
|
||||
private $content;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $yosAssigned;
|
||||
|
||||
/**
|
||||
* DefaultRequest constructor.
|
||||
* @param string $serviceName
|
||||
*/
|
||||
public function __construct($serviceName)
|
||||
{
|
||||
$this->serviceName = $serviceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getHeaders()
|
||||
{
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $headers
|
||||
*/
|
||||
public function setHeaders(array $headers)
|
||||
{
|
||||
$this->headers = $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public function addHeader($name, $value)
|
||||
{
|
||||
$this->headers[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getResourcePath()
|
||||
{
|
||||
return $this->resourcePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*/
|
||||
public function setResourcePath($path)
|
||||
{
|
||||
$this->resourcePath = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getParameters()
|
||||
{
|
||||
return $this->parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $parameters
|
||||
*/
|
||||
public function setParameters($parameters)
|
||||
{
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $values
|
||||
*/
|
||||
public function addParameters($name, array $values)
|
||||
{
|
||||
$this->parameters[$name] = $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public function addParameter($name, $value)
|
||||
{
|
||||
if (isset($this->parameters[$name])) {
|
||||
$values = $this->parameters[$name];
|
||||
$values[] = $value;
|
||||
} else {
|
||||
$this->parameters[$name] = [$value];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|MultiPartFile
|
||||
*/
|
||||
public function getMultipartFiles()
|
||||
{
|
||||
return $this->multipartFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string|resource $file
|
||||
*/
|
||||
public function addMultiPartFile($name, $file)
|
||||
{
|
||||
if (isset($this->multipartFiles[$name])) {
|
||||
$values = $this->multipartFiles[$name];
|
||||
$values[] = new MultiPartFile($file);
|
||||
} else {
|
||||
$this->multipartFiles[$name] = [new MultiPartFile($file)];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Uri
|
||||
*/
|
||||
public function getEndpoint()
|
||||
{
|
||||
return $this->endpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Uri $endpoint
|
||||
*/
|
||||
public function setEndpoint(Uri $endpoint)
|
||||
{
|
||||
$this->endpoint = $endpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHttpMethod()
|
||||
{
|
||||
return $this->httpMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $httpMethod
|
||||
*/
|
||||
public function setHttpMethod($httpMethod)
|
||||
{
|
||||
$this->httpMethod = $httpMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getContentType()
|
||||
{
|
||||
return $this->headers[Headers::CONTENT_TYPE];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return StreamInterface
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $content StreamInterface
|
||||
*/
|
||||
public function setContent($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getServiceName()
|
||||
{
|
||||
return $this->serviceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getYosFlag()
|
||||
{
|
||||
return $this->yosAssigned;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $flag bool
|
||||
*/
|
||||
public function setYosFlag($flag)
|
||||
{
|
||||
$this->yosAssigned = $flag;
|
||||
}
|
||||
|
||||
}
|
||||
75
lib/Internal/MultiPartFile.php
Normal file
75
lib/Internal/MultiPartFile.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Yeepay\Yop\Sdk\Internal;
|
||||
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Yeepay\Yop\Sdk\Utils\ObjectSerializer;
|
||||
|
||||
class MultiPartFile
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $fileName;
|
||||
|
||||
/**
|
||||
* @var StreamInterface
|
||||
*/
|
||||
private $content;
|
||||
|
||||
/**
|
||||
* MultiPartFile constructor.
|
||||
* @param string|resource $file
|
||||
*/
|
||||
public function __construct($file)
|
||||
{
|
||||
if (is_string($file)) {
|
||||
$this->fileName = ObjectSerializer::sanitizeFilename($file);
|
||||
$this->content = \GuzzleHttp\Psr7\Utils::streamFor($file);
|
||||
} else {
|
||||
$meta_data = stream_get_meta_data($file);
|
||||
$this->fileName = ObjectSerializer::sanitizeFilename($meta_data['uri']);
|
||||
$this->content = \GuzzleHttp\Psr7\Utils::streamFor($file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFileName()
|
||||
{
|
||||
return $this->fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fileName
|
||||
* @return MultiPartFile
|
||||
*/
|
||||
public function setFileName($fileName)
|
||||
{
|
||||
$this->fileName = $fileName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return StreamInterface
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StreamInterface $content
|
||||
* @return MultiPartFile
|
||||
*/
|
||||
public function setContent($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
120
lib/Internal/Request.php
Normal file
120
lib/Internal/Request.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace Yeepay\Yop\Sdk\Internal;
|
||||
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
|
||||
interface Request
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getHeaders();
|
||||
|
||||
/**
|
||||
* @param array $headers
|
||||
*/
|
||||
public function setHeaders(array $headers);
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public function addHeader($name, $value);
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getResourcePath();
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*/
|
||||
public function setResourcePath($path);
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getParameters();
|
||||
|
||||
/**
|
||||
* @param array $parameters
|
||||
*/
|
||||
public function setParameters($parameters);
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $values
|
||||
*/
|
||||
public function addParameters($name, array $values);
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public function addParameter($name, $value);
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getMultipartFiles();
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string|resource $file
|
||||
*/
|
||||
public function addMultiPartFile($name, $file);
|
||||
|
||||
/**
|
||||
* @return Uri
|
||||
*/
|
||||
public function getEndpoint();
|
||||
|
||||
/**
|
||||
* @param Uri $endpoint
|
||||
*/
|
||||
public function setEndpoint(Uri $endpoint);
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHttpMethod();
|
||||
|
||||
/**
|
||||
* @param string $httpMethod
|
||||
*/
|
||||
public function setHttpMethod($httpMethod);
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getContentType();
|
||||
|
||||
/**
|
||||
* @return StreamInterface
|
||||
*/
|
||||
public function getContent();
|
||||
|
||||
/**
|
||||
* @param StreamInterface $content
|
||||
*/
|
||||
public function setContent($content);
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getServiceName();
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getYosFlag();
|
||||
|
||||
/**
|
||||
* @param bool $flag
|
||||
*/
|
||||
public function setYosFlag($flag);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user