Skip to content

Commit

Permalink
Updated readme and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVanderbist committed Feb 1, 2017
1 parent 8ea2b4a commit f56c851
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ All notable changes to `temporary-directory` will be documented in this file
## 0.0.2 - 2017-01-30

- removed create method, use constructor instead

## 0.0.3 - 2017-02-01

- added chainable methods for creating a temporary directory
39 changes: 23 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Here's a quick example on how to create a temporary file and delete it:
```php
use Spatie\TemporaryDirectory\TemporaryDirectory;

$temporaryDirectory = TemporaryDirectory::create($basePath);
$temporaryDirectory = (new TemporaryDirectory())->create();

// Get a path inside the temporary directory
$temporaryDirectory->path('temporaryfile.txt');
Expand All @@ -36,25 +36,41 @@ composer require spatie/temporary-directory

### Creating a temporary directory

To create a temporary directory simply use the static `create` method of the `TemporaryDirectory` and optionally pass in a `$path`. If a `$path` is not provided `TemporaryDirectory` will use a timestamp as the directory name.
To create a temporary directory simply call the `create` method of the `TemporaryDirectory`. By default the temporary directory will be created in a timestamped directory in your system's temporary directory (usually `/tmp`).

```php
TemporaryDirectory::create(string $path);
(new TemporaryDirectory())->create();
```

By default an exception will be thrown when if a directory already exists at the given `$path`. You can override this behaviour by using the `forceCreate` method.
### Naming your temporary directory

If you want to use a custom name for your temporary directory instead of the timestamp call the `name` method before the `create` method.

```php
(new TemporaryDirectory())->name(string $name)->create();
```

By default an exception will be thrown when if a directory already exists with the given `$name`. You can override this behaviour by calling the `force` method in combination with the `name` method.

```php
(new TemporaryDirectory())->name(string $name)->force()->create();
```

### Setting a custom location for a temporary directory

You can set a custom location in which your temporary directory will be created by calling the `location` method and providing the `$path` argument.

```php
TemporaryDirectory::forceCreate(string $path);
(new TemporaryDirectory())->location(string $path)->create();
```

### Determining paths within the temporary directory

You can use the `path` method to determine the full path to a file or directory in the temporary directory:

```php
$temporaryDirectory = TemporaryDirectory::create('temporary');
$temporaryDirectory->path('dumps/datadump.dat'); // return /tmp/temporary/dumps/datadump.dat
$temporaryDirectory = (new TemporaryDirectory())->create();
$temporaryDirectory->path('dumps/datadump.dat'); // return /tmp/1485941876276/dumps/datadump.dat
```

### Emptying a temporary folder
Expand All @@ -73,15 +89,6 @@ Once you're done processing your temporary data you can delete the entire tempor
$temporaryDirectory->delete();
```

Please note when calling `delete` on an instance of `TemporaryDirectory` it will only delete the deepest nested subdirectory of the original path. For example:

```php
$temporaryDirectory = TemporaryDirectory::create('storage/temporary/data');

// Will only delete the `data` directory, `storage` and `temporary` still exist
$temporaryDirectory->delete();
```

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
Expand Down

0 comments on commit f56c851

Please sign in to comment.