Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/salamek/nette-tempnam
Create files in %tempDir%/tempnam
https://github.com/salamek/nette-tempnam
nette temporary
Last synced: about 1 month ago
JSON representation
Create files in %tempDir%/tempnam
- Host: GitHub
- URL: https://github.com/salamek/nette-tempnam
- Owner: Salamek
- License: lgpl-3.0
- Created: 2017-07-25T16:45:31.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-03-04T14:23:21.000Z (almost 3 years ago)
- Last Synced: 2024-10-14T13:21:53.209Z (3 months ago)
- Topics: nette, temporary
- Language: PHP
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Nette tempnam
This is a simple tempnam extension for [Nette Framework](http://nette.org/)
It creates temp files in %tempDir%/tempnam## Why ?
Sometines you just need to create tempfile such as PDF, Latte templates etc... and you dont want to put them into `sys_get_temp_dir()` (/tmp) and keep them in your Nette project %tempDir%... or just acces same temp file multiple times## Instalation
The best way to install salamek/nette-tempnam is using [Composer](http://getcomposer.org/):
```sh
$ composer require salamek/nette-tempnam:@dev
```Then you have to register extension in `config.neon`.
```yaml
extensions:
tempnam: Salamek\Tempnam\DI\TempnamExtension
```If you wish to change tempnam path just add this to your config:
```yaml
tempnam:
tempDir: %tempDir%/tempnam
```## Usage example
```php
/** @var Salamek\Tempnam\Tempnam @inject */
public $tempnam;$key = 'my_tempnam_key_1'; // Lets say ID of record in database
$data = 'My File COntent'; // Lets say record from database we want as file
$updatedAt = new \DateTime('YYYY-mm-dd'); // Lets say updatedAt column from database to expire tempnam file when record in database is changed// Load temFile Path or null
$tempFile = $this->tempnam->load($key, $updatedAt);if ($tempFile === null)
{
$tempFile = $this->tempnam->save($key, $data, $updatedAt);
}echo file_get_contents($tempFile); // My File COntent
```
## Methods
```php
$this->tempnam->getTempDir(); //Returns tempDir
$this->tempnam->remove($key); //Removes tempnam file by its $key
$this->tempnam->load($key, \DateTimeInterface $updatedAt = null); //Returns tempnam file path by its key if updatedAt matches or returns null
$this->tempnam->save($key, $data, \DateTimeInterface $updatedAt = null) //Saves tempnam file by $key with $data content, returns tempnam path
```