pnz / tus-hook-handler
dev-master / 0.1.x-dev
2018-04-25 18:01 UTC
Requires
- php: ^7.1
- symfony/event-dispatcher: ^3.0 || ^4.0
- symfony/http-foundation: ^3.0 || ^4.0
Requires (Dev)
- symfony/phpunit-bridge: ^3.4 || ^4.0
This package is auto-updated.
Last update: 2024-08-27 02:55:42 UTC
README
一个处理 TUSd HTTP 钩子的快速助手。处理器通过使用事件调度器暴露了两种方法来处理钩子数据并分派 TUSd 事件。
触发事件的示例
tus.hook.pre-create
:预创建事件(https://github.com/tus/tusd/blob/master/docs/hooks.md#pre-create)tus.hook-post-create
:后创建事件(见:https://github.com/tus/tusd/blob/master/docs/hooks.md#post-create)tus.hook-post-finish
:后完成事件(见:https://github.com/tus/tusd/blob/master/docs/hooks.md#post-finish)tus.hook-post-receive
:后接收事件(见:https://github.com/tus/tusd/blob/master/docs/hooks.md#post-receive)tus.hook-post-terminate
:后终止事件(见:https://github.com/tus/tusd/blob/master/docs/hooks.md#post-terminate)
由于 TUSd 钩子实现,您的控制器 必须 对 pre-create
http 钩子做出适当的响应,以确认上传(响应代码 200),或拒绝它(响应代码 400)。
钩子控制器示例
public function tusdHookAction(Request $request): Response { try { $data = $this->tusHookHandler->buildHookData($request); } catch (TusException $e) { // Do not proceed, as the the request is invalid. // The TUSd server will abort the upload return new Response('Invalid request: '.$e->getMessage(), 400); } if (HookData::HOOK_PRE_CREATE === $data->hookName) { if (!$this->isValidUpload($data)) { // Return a failure response, TUSd server will abort the upload return new Response('Invalid request: invalid token', 400); } } // Let the handler dispatch the event $this->tusHookHandler->handleHook($data); // Return an empty response, TUSd server will handle it as a positive answer. return new Response(); } private function isValidUpload(HookData $data): bool { ... }