mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
Hyperf\Utils\Resource
will be deprecated in v2.3. (#3636)
* `Hyperf\Utils\Resource` will be deprecated in v2.3, please use `Hyperf\Utils\ResourceGenerator` instead. * Update composer.json
This commit is contained in:
parent
90623860ab
commit
7af798f8fa
@ -15,6 +15,10 @@
|
||||
- Changed the default priority of aspect to 0.
|
||||
- Changed the consumer tag of amqp to empty string.
|
||||
|
||||
## Deprecated
|
||||
|
||||
- `Hyperf\Utils\Resource` will be deprecated in v2.3, please use `Hyperf\Utils\ResourceGenerator` instead.
|
||||
|
||||
## Added
|
||||
|
||||
- [#3589](https://github.com/hyperf/hyperf/pull/3589) Added DAG component.
|
||||
|
@ -16,7 +16,7 @@ use GuzzleHttp\Ring\Exception\RingException;
|
||||
use GuzzleHttp\Ring\Future\CompletedFutureArray;
|
||||
use Hyperf\Engine\Http\Client;
|
||||
use Hyperf\Engine\Http\RawResponse;
|
||||
use Hyperf\Utils\Resource;
|
||||
use Hyperf\Utils\ResourceGenerator;
|
||||
|
||||
/**
|
||||
* Http handler that uses Swoole Coroutine as a transport layer.
|
||||
@ -147,7 +147,7 @@ class CoroutineHandler
|
||||
'effective_url' => $effectiveUrl,
|
||||
'headers' => $response->headers,
|
||||
'status' => $response->statusCode,
|
||||
'body' => Resource::from($response->body),
|
||||
'body' => ResourceGenerator::from($response->body),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,8 @@
|
||||
"symfony/var-dumper": "Required to use the dd function (^5.0).",
|
||||
"symfony/serializer": "Required to use SymfonyNormalizer (^5.0)",
|
||||
"symfony/property-access": "Required to use SymfonyNormalizer (^5.0)",
|
||||
"hyperf/di": "Required to use ExceptionNormalizer"
|
||||
"hyperf/di": "Required to use ExceptionNormalizer",
|
||||
"nikic/php-parser": "Required to use PhpParser. (^4.0)"
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
|
@ -11,6 +11,9 @@ declare(strict_types=1);
|
||||
*/
|
||||
namespace Hyperf\Utils;
|
||||
|
||||
/**
|
||||
* @deprecated v2.3, please use ResourceGenerator instead.
|
||||
*/
|
||||
class Resource
|
||||
{
|
||||
/**
|
||||
|
34
src/utils/src/ResourceGenerator.php
Normal file
34
src/utils/src/ResourceGenerator.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
namespace Hyperf\Utils;
|
||||
|
||||
class ResourceGenerator
|
||||
{
|
||||
/**
|
||||
* TODO: Swoole file hook does not support `php://temp` and `php://memory`.
|
||||
*/
|
||||
public static function from(string $body, string $filename = 'php://temp')
|
||||
{
|
||||
$resource = fopen($filename, 'r+');
|
||||
if ($body !== '') {
|
||||
fwrite($resource, $body);
|
||||
fseek($resource, 0);
|
||||
}
|
||||
|
||||
return $resource;
|
||||
}
|
||||
|
||||
public static function fromMemory(string $body)
|
||||
{
|
||||
return static::from($body, 'php://memory');
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ declare(strict_types=1);
|
||||
*/
|
||||
namespace HyperfTest\Utils;
|
||||
|
||||
use Hyperf\Utils\Resource;
|
||||
use Hyperf\Utils\ResourceGenerator;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
@ -23,7 +23,7 @@ class ResourceTest extends TestCase
|
||||
public function testFrom()
|
||||
{
|
||||
$data = '123123';
|
||||
$resource = Resource::from($data);
|
||||
$resource = ResourceGenerator::from($data);
|
||||
$this->assertSame('1', fread($resource, 1));
|
||||
$this->assertSame('23', fread($resource, 2));
|
||||
$this->assertSame('123', fread($resource, 10));
|
||||
@ -34,7 +34,7 @@ class ResourceTest extends TestCase
|
||||
$data = str_repeat('1', 1024 * 1024);
|
||||
$memory = memory_get_usage(true);
|
||||
for ($i = 0; $i < 100; ++$i) {
|
||||
Resource::fromMemory($data);
|
||||
ResourceGenerator::fromMemory($data);
|
||||
$current = memory_get_usage(true);
|
||||
$leak = $current - $memory;
|
||||
$memory = $current;
|
||||
|
Loading…
Reference in New Issue
Block a user