A simple library used to create temporary files and automatically delete them when they are no longer needed.
Find a file
2023-02-25 01:57:54 -05:00
.idea Updated tempfile.iml 2023-02-25 01:01:18 -05:00
src/TempFile Added \TempFile\TempFile 2023-02-25 00:52:11 -05:00
tests Added test 2023-02-25 00:53:58 -05:00
.gitignore Initial Commit 2023-02-25 00:05:03 -05:00
.gitlab-ci.yml Initial Commit 2023-02-25 00:05:03 -05:00
CHANGELOG.md Added CHANGELOG.md 2023-02-25 01:57:54 -05:00
LICENSE Initial Commit 2023-02-25 00:05:03 -05:00
Makefile Initial Commit 2023-02-25 00:05:03 -05:00
project.json Updated project.json 2023-02-25 01:00:41 -05:00
README.md Updated README.md 2023-02-25 00:59:52 -05:00

TempFile

TempFile is a very simple library used for creating temporary files without having to write code to delete them once you're done with them.

Installation

The library can be installed using ncc:

ncc install -p "nosial/libs.tempfile=latest@n64"

or by adding the following to your project.json file under the build.dependencies section:

{
  "name": "net.nosial.tempfile",
  "version": "latest",
  "source_type": "remote",
  "source": "nosial/libs.tempfile=latest@n64"
}

If you don't have the n64 source configured you can add it by running the following command:

ncc source add --name n64 --type gitlab --host git.n64.cc

Compiling from source

The library can be compiled from source using ncc:

ncc build --config release

or by running the following command:

make release

Usage

Just create a class object, optionally specifying a file extension to use (without the dot). And that's all, an Exception will be thrown if the file could not be created.

require_once('ncc');
import('net.nosial.tempfile');

$file1 = new TempFile();
$file2 = new TempFile('txt');

You can obtain the file path by using the getFilepath() method or by using the object as a string.

echo $file1->getFilepath() . PHP_EOL;
file_put_contents($file2, 'Hello World!');

Files are automatically deleted when the object is destroyed, if for some reason the __destruct() method was not properly called, a shutdown function is automatically registered to delete all the temporary files that were created.

License

This library is licensed under the MIT license, see the LICENSE file for more information.