he426100 / tus-php-hyperf
The Hyperf Tus-php package.
Installs: 22
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/he426100/tus-php-hyperf
Requires
- php: >=8.1
 - ext-json: *
 - ext-swoole: >=4.5
 - hyperf/cache: ~3.1.0
 - hyperf/context: ~3.1.0
 - hyperf/di: ~3.1.0
 - hyperf/event: ~3.1.0
 - hyperf/guzzle: ~3.1.0
 - hyperf/http-server: ~3.1.0
 - hyperf/redis: ~3.1.0
 - hyperf/utils: ~3.1.0
 - nesbot/carbon: ^1.26.3 || ^2.0
 - ramsey/uuid: ^3.7 || ^4.0
 - symfony/console: ^7.2
 - symfony/http-foundation: ^6.0 | ^7.0
 - symfony/mime: ^7.2
 
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
 - phpstan/phpstan: ^2.1
 - swoole/ide-helper: dev-master
 
README
该组件移植了 Tus-php 组件(Tus-php)相对完整的功能特性。
- Swoole无法获取 
php://input,用Swoole\Http\Request->getContent()代替 
安装
composer require he426100/tus-php-hyperf
发布配置
php bin/hyperf.php vendor:publish he426100/tus-php-hyperf
文件位于
config/autoload/tus.php。
使用示例
- hyperf/app/Controller/TusController.php
 
<?php
declare(strict_types=1);
namespace App\Controller;
use Tus\Tus\Server;
class TusController extends AbstractController
{
    public function index()
    {
        $server = (new Server($this->request, $this->response))->setUploadDir(\dirname(__DIR__, 3) . '/public/' . 'uploads');
        return $server->serve();
    }
}
- nano/index.php
 
<?php
use Tus\Tus\Server;
use Hyperf\Nano\Factory\AppFactory;
require __DIR__ . '/vendor/autoload.php';
$app = AppFactory::create();
$app->config([
    'cache.default' => [
        'driver' => \Hyperf\Cache\Driver\RedisDriver::class,
        'packer' => \Hyperf\Utils\Packer\PhpSerializerPacker::class,
        'prefix' => 'c:',
    ],
]);
$app->addRoute(['HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE'], '/', function() {
    $server = new Server($this->request, $this->response);
    return $server->serve();
});
$app->run();
- uppy.html
 
<!doctype html>
<html>
    <head>
    <meta charset="utf-8">
    <title>Uppy</title>
    <link href="https://releases.transloadit.com/uppy/v2.7.0/uppy.min.css" rel="stylesheet">
    </head>
    <body>
    <div id="drag-drop-area"></div>
    <script src="https://releases.transloadit.com/uppy/v2.7.0/uppy.min.js"></script>
    <script>
        var uppy = new Uppy.Core()
        .use(Uppy.Dashboard, {
            inline: true,
            target: '#drag-drop-area'
        })
        .use(Uppy.Tus, { 
            endpoint: 'http://localhost:9501',
            chunkSize: 1 * 1024 * 1024
        })
        uppy.on('complete', (result) => {
        console.log('Upload complete! We’ve uploaded these files:', result.successful)
        })
    </script>
    </body>
</html>