-
-
Notifications
You must be signed in to change notification settings - Fork 205
Symfony Integration
Ankit Pokhrel edited this page Sep 25, 2018
·
8 revisions
-
Add
ankitpokhrel/tus-php
as your dependency.$ composer require ankitpokhrel/tus-php
-
Create a service, say
TusService
insrc/Service
.<?php namespace App\Service; use TusPhp\Tus\Server as TusServer; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; class TusService { /** @var ParameterBagInterface */ protected $params; /** * TusService constructor. * * @param ParameterBagInterface $params */ public function __construct(ParameterBagInterface $params) { $this->params = $params; } /** * Configure and get TusServer instance. * * @return TusServer */ public function getServer() { $server = new TusServer('redis'); $server ->setApiPath('/tus') // tus server endpoint. ->setUploadDir($this->params->get('kernel.project_dir') . '/public/uploads'); // uploads dir. return $server; } }
-
Create a controller, say
TusController
, and add a route to serve the request.<?php namespace App\Controller; use App\Service\TusService; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class TusController extends Controller { // ... /** * Create tus server. Route matches /tus/, /tus and /tus/* endpoints. * * @Route("/tus/", name="tus_post") * @Route("/tus/{token?}", name="tus", requirements={"token"=".+"}) * * @param TusService $tusService * * @return Response */ public function server(TusService $tusService) { $response = $tusService->getServer()->serve(); return $response->send(); } // ... }
Note that the route matches
/tus/
,/tus
and/tus/*
endpoints. You can now access tus server endpoints athttp://yourapp.dev/tus
orhttp://yourapp.dev/tus/
.