From d70bffdf361c8d3a5aa163af2fa7e533a043ba2c Mon Sep 17 00:00:00 2001 From: Luke Kuzmish <42181698+cosmastech@users.noreply.github.com> Date: Mon, 25 Sep 2023 07:54:15 -0400 Subject: [PATCH] DeleteWhenDestroyed documentation --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 44681d6..4a0e297 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,28 @@ Once you're done processing your temporary data you can delete the entire tempor $temporaryDirectory->delete(); ``` +### Deleting a temporary directory when the object is destroyed + +If you want to automatically have the filesystem directory deleted when the object instance has no more references in +its defined scope, you can enable `deleteWhenDestroyed()` on the TemporaryDirectory object. + +```php +function handleTemporaryFiles() +{ + $temporaryDirectory = (new TemporaryDirectory()) + ->deleteWhenDestroyed() + ->create(); + + // ... use the temporary directory + + return; // no need to manually call $temporaryDirectory->delete()! +} + +handleTemporaryFiles(); +``` + +You can also call `unset()` on an object instance. + ## Testing ```bash