### Package Installation Source: https://github.com/spatie/temporary-directory/blob/main/README.md Provides the Composer command to install the spatie/temporary-directory package. ```bash composer require spatie/temporary-directory ``` -------------------------------- ### Determining Paths within Temporary Directory Source: https://github.com/spatie/temporary-directory/blob/main/README.md Shows how to get the full path to a file or subdirectory within the created temporary directory using the `path` method. ```php $temporaryDirectory = (new TemporaryDirectory())->create(); $temporaryDirectory->path('dumps/datadump.dat'); // return /tmp/1485941876276/dumps/datadump.dat ``` -------------------------------- ### Creating a Temporary Directory Source: https://github.com/spatie/temporary-directory/blob/main/README.md Shows two ways to create a temporary directory: using the `create` method or the static `make` method. ```php (new TemporaryDirectory())->create(); ``` ```php TemporaryDirectory::make(); ``` -------------------------------- ### Running Tests Source: https://github.com/spatie/temporary-directory/blob/main/README.md Shows the Composer command to execute the package's test suite. ```bash composer test ``` -------------------------------- ### Basic Temporary Directory Usage Source: https://github.com/spatie/temporary-directory/blob/main/README.md Demonstrates the fundamental usage of creating a temporary directory, accessing a path within it, and deleting the directory. ```php use Spatie\TemporaryDirectory\TemporaryDirectory; $temporaryDirectory = (new TemporaryDirectory())->create(); // Get a path inside the temporary directory $temporaryDirectory->path('temporaryfile.txt'); // Delete the temporary directory and all the files inside it $temporaryDirectory->delete(); ``` -------------------------------- ### Setting Custom Location for Temporary Directory Source: https://github.com/spatie/temporary-directory/blob/main/README.md Demonstrates how to specify a custom directory where the temporary directory will be created, using the constructor, `make` method, or `location` method. ```php (new TemporaryDirectory($location)) ->create(); ``` ```php TemporaryDirectory::make($location); ``` ```php (new TemporaryDirectory()) ->location($location) ->create(); ``` -------------------------------- ### Naming a Temporary Directory Source: https://github.com/spatie/temporary-directory/blob/main/README.md Illustrates how to assign a custom name to a temporary directory and how to force creation if a directory with that name already exists. ```php (new TemporaryDirectory()) ->name($name) ->create(); ``` ```php (new TemporaryDirectory()) ->name($name) ->force() ->create(); ``` -------------------------------- ### Deleting a Temporary Directory Source: https://github.com/spatie/temporary-directory/blob/main/README.md Demonstrates how to completely remove the temporary directory and all its contents using the `delete` method. ```php $temporaryDirectory->delete(); ``` -------------------------------- ### Emptying a Temporary Directory Source: https://github.com/spatie/temporary-directory/blob/main/README.md Explains how to remove all files and subdirectories within the temporary directory using the `empty` method, while keeping the directory itself. ```php $temporaryDirectory->empty(); ``` -------------------------------- ### Automatic Deletion on Object Destruction Source: https://github.com/spatie/temporary-directory/blob/main/README.md Shows how to configure the temporary directory to be automatically deleted when the object goes out of scope, using `deleteWhenDestroyed()` or `unset()`. ```php function handleTemporaryFiles() { $temporaryDirectory = (new TemporaryDirectory()) ->deleteWhenDestroyed() ->create(); // ... use the temporary directory return; // no need to manually call $temporaryDirectory->delete()! } handleTemporaryFiles(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.