PHPackages                             zjkiza/tmp-storage-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. zjkiza/tmp-storage-bundle

ActiveSymfony-bundle[Caching](/categories/caching)

zjkiza/tmp-storage-bundle
=========================

The bundle for temporary storage data which needs to be preserved between stateless requests.

v0.6.2(1y ago)01MITPHPPHP &gt;=8.1

Since Dec 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/zjkiza/tmp-storage-bundle)[ Packagist](https://packagist.org/packages/zjkiza/tmp-storage-bundle)[ RSS](/packages/zjkiza-tmp-storage-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (30)Versions (6)Used By (0)

TMP Storage Bundle
==================

[](#tmp-storage-bundle)

The TMP Storage Bundle is used to store temporary state between two stateless requests. Common use cases include:

- **SSO Login**: During single sign-on, user data can be temporarily stored as an object in TMP Storage. A generated ID links the data, ensuring sensitive user information is not exposed in the URL. The ID is verified upon login, and the stored object is retrieved to complete the process.
- **Password Reset**: User data can be saved as an object in TMP Storage, and a reset link is generated with a unique ID. When the user clicks the link, they are directed to a page where the ID is verified, and the stored object is retrieved to facilitate password reset.
- **Unsubscribe Links**: User information is stored temporarily in TMP Storage, and an unsubscribe link is generated with a unique ID. When the user clicks the link, they are directed to the unsubscribe page, where the ID is verified, and the object is retrieved to process the request.

This bundle allows you to securely store objects in a temporary storage database, retrievable using randomly generated keys.

---

About the Bundle
================

[](#about-the-bundle)

The bundle defines the interface `Zjk\TmpStorage\Contract\TmpStorageInterface` with the following methods:

- **`public function storage(object $tmp, int $ttl = 604800): string`**
    Stores an object in the database. The `$ttl` parameter specifies the object's time-to-live in seconds (default: one week).
- **`public function fetch(string $id, bool $remove = true): object`**
    Retrieves an object from the database by its ID. The `$remove` parameter determines whether the object is deleted immediately after retrieval. Set `$remove` to `false` to keep the object.
- **`public function remove(string $id): void`**
    Removes an object from the database if `$remove` was previously set to `false`.
- **`public function clearGarbage(): void`**
    Performs maintenance to remove invalid or expired records, ensuring database cleanliness.

### Maintenance Command

[](#maintenance-command)

A terminal command is available for manual or scheduled garbage collection. It invokes the `clearGarbage` method:

```
bin/console zjkiza:tmp-storage:maintenance
```

Installation
============

[](#installation)

Add the bundle to your project using Composer:

```
composer require zjkiza/tmp-storage-bundle
```

Symfony integration
-------------------

[](#symfony-integration)

The bundle integrates seamlessly with Symfony, wiring up all necessary classes. Follow these steps to set it up:

1. **Register the Bundle**

```
