Skip to content

Commit

Permalink
新增兼容swoole client addFile其他参数,支持文件分片上传
Browse files Browse the repository at this point in the history
  • Loading branch information
tioncico committed Jul 23, 2020
1 parent ddd4c47 commit 96c67b9
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 1 deletion.
124 changes: 124 additions & 0 deletions src/Bean/CURLFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php
/**
* Created by PhpStorm.
* User: tioncico
* Date: 2020-07-23
* Time: 15:33
*/

namespace EasySwoole\HttpClient\Bean;


class CURLFile
{
protected $path;
protected $name;
protected $type;
protected $filename;
protected $offset;
protected $length;

function __construct(string $filename,string $name,string $mimetype=null)
{
$this->name = $name;
$this->path = $filename;
$this->type = $mimetype;
$this->filename = $filename;
}

/**
* @return mixed
*/
public function getPath()
{
return $this->path;
}

/**
* @param mixed $path
*/
public function setPath($path): void
{
$this->path = $path;
}

/**
* @return mixed
*/
public function getName()
{
return $this->name;
}

/**
* @param mixed $name
*/
public function setName($name): void
{
$this->name = $name;
}

/**
* @return mixed
*/
public function getType()
{
return $this->type;
}

/**
* @param mixed $type
*/
public function setType($type): void
{
$this->type = $type;
}

/**
* @return mixed
*/
public function getFilename()
{
return $this->filename;
}

/**
* @param mixed $filename
*/
public function setFilename($filename): void
{
$this->filename = $filename;
}

/**
* @return mixed
*/
public function getOffset()
{
return $this->offset;
}

/**
* @param mixed $offset
*/
public function setOffset($offset): void
{
$this->offset = $offset;
}

/**
* @return mixed
*/
public function getLength()
{
return $this->length;
}

/**
* @param mixed $length
*/
public function setLength($length): void
{
$this->length = $length;
}
}
7 changes: 6 additions & 1 deletion src/Handler/Swoole/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace EasySwoole\HttpClient\Handler\Swoole;


use EasySwoole\HttpClient\Bean\CURLFile;
use EasySwoole\HttpClient\Bean\Response;
use EasySwoole\HttpClient\Handler\AbstractClient;
use EasySwoole\HttpClient\HttpClient;
Expand Down Expand Up @@ -114,6 +115,10 @@ public function rawRequest($httpMethod = HttpClient::METHOD_GET, $rawData = null
$client->addFile($item->getFilename(), $key, $item->getMimeType(), $item->getPostFilename());
unset($rawData[$key]);
}
if ($item instanceof CURLFile) {
$client->addFile($item->getPath(), $item->getName(), $item->getType(), $item->getFilename(),$item->getOffset(),$item->getLength());
unset($rawData[$key]);
}
}
$client->setData($rawData);
} else if ($rawData !== null) {
Expand Down Expand Up @@ -157,4 +162,4 @@ public function rawRequest($httpMethod = HttpClient::METHOD_GET, $rawData = null
}
return $this->createHttpResponse($client);
}
}
}

0 comments on commit 96c67b9

Please sign in to comment.