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

Allow overriding default implementation of TemporaryDirectory #1846

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jonerickson
Copy link

@jonerickson jonerickson commented Sep 29, 2024

This PR arises out of the need to change the default implementation of the TemporaryDirectory service. In our story, serving a multi-tenant application and using this package to backup each individual tenant's DB, we needed the ability to customize the temporary directory's location. Because we have a large number of tenants, we elected to create a batch job to backup each tenant's DB. Because of this, we are running into the issue where multiple jobs are trying to use the same temporary directory. As you can imagine, this creates chaos. We now have the ability to set the file path based on the tenant allowing each tenant to use their own temporary directory.

Because the package relies on Spatie's temporary directory package, we needed to create an adapter to extend the new TemporaryDirectory interface. This adapter just simply creates a new instance of TemporaryDirectory and then passes all calls to the default implementation.

With this PR, we can now do the following. This allows use to set the location in our own implementation's constructor.

$this->app->extend(TemporaryDirectory::class, function () {
    return new TenantTemporaryDirectory();
});

I chose not to include all the methods in the contract from the spatie/temporary-directory package as this would create a cross-package dependency that I think would not be the best choice.

@jonerickson jonerickson marked this pull request as draft September 29, 2024 22:00
@jonerickson jonerickson marked this pull request as ready for review October 1, 2024 03:12
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.

1 participant