Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable a way to provide a custom configured Tus library. #249

Closed
wants to merge 2 commits into from

Conversation

cjsaylor
Copy link

@cjsaylor cjsaylor commented Mar 23, 2020

This PR gives the ability to provide a TusClient factory to the Vimeo client. When performing an upload action the factory is used to create a TusClient instead of having a tus client created directly in a private method.

The developer if wanting to inject their own factory would need to implement the factory interface provided in this PR and pass into the Vimeo client constructor.

This allows customization of the TusClient by users of the Vimeo api client. For example, the default caching behavior of the TusClient library is a FileStore that creates temporary files within the vendor include directory. In my case, it is not desirable to allow write access to that directory from php runtime.

Example use:

<?php declare(strict_types = 1);

namespace My\Namespace;

use TusPhp\Cache\FileStore;
use Vimeo\Upload\TusClient;
use Vimeo\Upload\TusClientFactoryInterface;

class TusClientFactory implements TusClientFactoryInterface {

	/**
	 * @var \TusPhp\Cache\FileStore
	 */
	private $fileCache;

	/**
	 * Constructor.
	 */
	public function __construct() {
		$this->fileCache = new FileStore('/tmp');
	}

	/**
	 * Create a tus php client given a baes URL.
	 */
	public function fromBaseUrl(string $baseUrl) : TusClient {
		$client = new TusClient($baseUrl);
		$client->setCache($this->fileCache);
		return $client;
	}
}

Then, where I create a Vimeo client:

$client = new Vimeo(
	'client_id', 
	'client_secret', 
	'access_token',
	new \My\Namespace\TusClientFactory()
);

A default implementation that does what the library did before has been implemented and is utilized when the developer does not provide it to the constructor.

This will help enable providing a tus client to the vimeo client with customization.
@cjsaylor cjsaylor closed this Apr 16, 2020
@cjsaylor cjsaylor reopened this Apr 16, 2020
@kezek
Copy link

kezek commented Aug 19, 2020

+1 , having the same issue.

The cacheDir is by default /vendor/ankitpokhrel/tus-php/.cache/, which is not writable in a sane environment.

@nyavo
Copy link

nyavo commented Nov 29, 2020

I have the same issue, with the cacheDir vendor/ankitpokhrel/tus-php/.cache/ not writable. So the tus upload failed everytime.
The ankitpokhrel/tus-php bundle works perfectly, il would be perfect if we can override this cache folder, or use Redis instead.

@IgorSuhorukov
Copy link

Same issue here - can't upload, due to /vendor/ankitpokhrel/tus-php/.cache/ is not writable and can't be changed.

@harpreetsb
Copy link

is there an update on this?

@aaronm67
Copy link
Collaborator

aaronm67 commented Feb 3, 2022

Thank you for the suggestion!

We modified this slightly to our standards, and added some examples and test for it, so going to close this, but we appreciate the contribution!

@aaronm67 aaronm67 closed this Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants