PHPackages                             kikiloaw/nativephp-secure-storage-faker - 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. kikiloaw/nativephp-secure-storage-faker

ActiveLibrary

kikiloaw/nativephp-secure-storage-faker
=======================================

A faker implementation of NativePHP SecureStorage for web compatibility

03PHP

Since Oct 6Pushed 7mo agoCompare

[ Source](https://github.com/kikiloaw/nativephp-secure-storage-faker)[ Packagist](https://packagist.org/packages/kikiloaw/nativephp-secure-storage-faker)[ RSS](/packages/kikiloaw-nativephp-secure-storage-faker/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

NativePHP SecureStorage Faker
=============================

[](#nativephp-securestorage-faker)

A faker implementation of NativePHP SecureStorage for web compatibility. This package provides the same interface as the native SecureStorage but uses a robust file-based cache system when running in web environments.

[![Latest Version](https://camo.githubusercontent.com/abd64f3edeffe8cb5ff0f81ea5860cedc92b074cbe3c41ce10dd2c951e381e60/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6b696b696c6f61772f6e61746976657068702d7365637572652d73746f726167652d66616b6572)](https://github.com/kikiloaw/nativephp-secure-storage-faker/releases)[![Total Downloads](https://camo.githubusercontent.com/858ff6a58d6cc0f9472611852820bd29a847956a7dfb80b67cf2f26b036c75b8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b696b696c6f61772f6e61746976657068702d7365637572652d73746f726167652d66616b6572)](https://packagist.org/packages/kikiloaw/nativephp-secure-storage-faker)[![License](https://camo.githubusercontent.com/f35dae9ec996d77c695b1e29a542ce6b03110aba57cf96d67c9fd03f08e7b228/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6b696b696c6f61772f6e61746976657068702d7365637572652d73746f726167652d66616b6572)](https://github.com/kikiloaw/nativephp-secure-storage-faker/blob/main/LICENSE)

Quick Start
-----------

[](#quick-start)

```
# Install the package
composer require kikiloaw/nativephp-secure-storage-faker

# Use in your code (no changes needed!)
use Native\Mobile\Facades\SecureStorage;

SecureStorage::set('auth_token', 'your-token-here');
$token = SecureStorage::get('auth_token');
```

That's it! The package automatically detects your environment and uses the appropriate implementation.

Features
--------

[](#features)

- **Automatic Environment Detection**: Automatically detects if you're running in a NativePHP environment or web environment
- **Seamless Fallback**: Falls back to file-based cache storage when native SecureStorage is not available
- **Same Interface**: Provides the exact same interface as the native SecureStorage
- **File-Based Cache**: Uses a robust file-based cache system that works even when Laravel cache is not available
- **Debug Logging**: Includes debug logging for development environments
- **Error Handling**: Robust error handling with fallbacks
- **No Code Changes Required**: Works with existing code without modifications
- **Testing Support**: Includes methods for testing and debugging

Installation
------------

[](#installation)

### Option 1: Install from GitHub (Recommended)

[](#option-1-install-from-github-recommended)

```
composer require kikiloaw/nativephp-secure-storage-faker
```

### Option 2: Local Package Development

[](#option-2-local-package-development)

Add the package to your main project's `composer.json`:

```
{
    "repositories": [
        {
            "type": "path",
            "url": "./packages/nativephp-secure-storage-faker"
        }
    ],
    "require": {
        "kikiloaw/nativephp-secure-storage-faker": "dev-main"
    }
}
```

Then run:

```
composer require kikiloaw/nativephp-secure-storage-faker
```

### Option 3: Install from Packagist (Coming Soon)

[](#option-3-install-from-packagist-coming-soon)

Once published to Packagist, you can install it with:

```
composer require kikiloaw/nativephp-secure-storage-faker
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

The package automatically detects your environment and uses the appropriate implementation:

```
use Native\Mobile\Facades\SecureStorage;

// These methods work the same whether you're in native or web environment
SecureStorage::set('auth_token', 'your-token-here');
$token = SecureStorage::get('auth_token');
SecureStorage::delete('auth_token');

// Additional methods available
$exists = SecureStorage::has('auth_token');
SecureStorage::clear(); // Clear all data
$keys = SecureStorage::keys(); // Get all keys
```

### Manual Control

[](#manual-control)

You can also use the manager directly for more control:

```
use NativePHP\SecureStorageFaker\SecureStorageManager;

// Force using faker implementation (useful for testing)
SecureStorageManager::forceFaker(true);

// Reset environment detection
SecureStorageManager::reset();
```

How It Works
------------

[](#how-it-works)

### Environment Detection

[](#environment-detection)

The package automatically detects the environment using several methods:

1. Checks for NativePHP environment variables
2. Tests if the native SecureStorage class exists and is functional
3. Falls back to the faker implementation if native is not available

### Storage Backend

[](#storage-backend)

- **Native Environment**: Uses the actual NativePHP SecureStorage
- **Web Environment**: Uses a file-based cache system with automatic fallback

### Cache Configuration

[](#cache-configuration)

The faker implementation uses a robust file-based cache system that:

- Works independently of Laravel's cache configuration
- Stores data in the system's temporary directory
- Includes an index system for efficient key management
- Automatically handles serialization/deserialization
- Provides consistent behavior across different environments

Configuration
-------------

[](#configuration)

### Environment Variables

[](#environment-variables)

You can set these environment variables to control behavior:

```
# Force NativePHP detection (optional)
NATIVEPHP=true

# Enable debug logging
APP_DEBUG=true
```

### File Cache Location

[](#file-cache-location)

The file-based cache is stored in the system's temporary directory:

- **Windows**: `C:\Users\{username}\AppData\Local\Temp\nativephp-secure-storage-faker\`
- **Linux/Mac**: `/tmp/nativephp-secure-storage-faker/`

You can customize this by setting the `NATIVEPHP_SECURE_STORAGE_FAKER_CACHE_PATH` environment variable.

API Reference
-------------

[](#api-reference)

### Methods

[](#methods)

All methods have the same signature as the native SecureStorage:

#### `get(string $key): mixed`

[](#getstring-key-mixed)

Retrieves a value from secure storage.

#### `set(string $key, mixed $value): void`

[](#setstring-key-mixed-value-void)

Stores a value in secure storage.

#### `delete(string $key): void`

[](#deletestring-key-void)

Removes a value from secure storage.

#### `has(string $key): bool`

[](#hasstring-key-bool)

Checks if a key exists in secure storage.

#### `clear(): void`

[](#clear-void)

Clears all data from secure storage.

#### `keys(): array`

[](#keys-array)

Returns all keys in secure storage.

### Manager Methods

[](#manager-methods)

#### `forceFaker(bool $force = true): void`

[](#forcefakerbool-force--true-void)

Forces the use of faker implementation (useful for testing).

#### `reset(): void`

[](#reset-void)

Resets environment detection cache.

Migration from Existing Code
----------------------------

[](#migration-from-existing-code)

If you're already using SecureStorage in your controllers with try-catch blocks, you can simplify your code:

### Before (with try-catch):

[](#before-with-try-catch)

```
try {
    $token = SecureStorage::get('auth_token');
} catch (\Throwable $e) {
    $token = Cache::get('native_auth_token');
}
```

### After (simplified):

[](#after-simplified)

```
$token = SecureStorage::get('auth_token');
```

The package handles the fallback automatically!

Testing
-------

[](#testing)

The package includes methods to help with testing:

```
use NativePHP\SecureStorageFaker\SecureStorageManager;

// Force faker mode for testing
SecureStorageManager::forceFaker(true);

// Test your code
$result = SecureStorage::get('test_key');

// Reset after tests
SecureStorageManager::reset();
```

Troubleshooting
---------------

[](#troubleshooting)

### Common Issues

[](#common-issues)

1. **File permissions**: Ensure the system temp directory is writable
2. **Native detection failing**: Check your NativePHP environment setup
3. **Debug logs**: Enable `APP_DEBUG=true` to see detailed logs
4. **Class alias conflicts**: The package automatically handles class aliasing

### Debug Information

[](#debug-information)

When `APP_DEBUG=true`, the package will log:

- Environment detection results
- File cache operations
- Fallback usage
- Error messages
- Native SecureStorage test results

Check your Laravel logs for detailed information.

### Testing the Package

[](#testing-the-package)

You can test if the package is working correctly:

```
use NativePHP\SecureStorageFaker\SecureStorageManager;

// Force faker mode and test
SecureStorageManager::forceFaker(true);
SecureStorageManager::set('test', 'value');
$result = SecureStorageManager::get('test');

if ($result === 'value') {
    echo "Package is working correctly!";
}
```

Contributing
------------

[](#contributing)

1. Fork the repository
2. Create your feature branch
3. Make your changes
4. Add tests
5. Submit a pull request

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- Laravel 10.x, 11.x, or 12.x
- NativePHP Mobile package (optional, for native environments)

Changelog
---------

[](#changelog)

### v1.0.0

[](#v100)

- Initial release
- Automatic environment detection
- File-based cache system
- Full API compatibility with native SecureStorage
- Comprehensive testing support

Roadmap
-------

[](#roadmap)

- Packagist publication
- Configuration file publishing
- Additional storage backends (Redis, Database)
- Performance optimizations
- Extended debugging features

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

Credits
-------

[](#credits)

Created by [kikiloaw](https://github.com/kikiloaw) for the NativePHP community.

Support
-------

[](#support)

If you encounter any issues or have questions:

1. Check the [troubleshooting section](#troubleshooting)
2. Enable debug logging with `APP_DEBUG=true`
3. Open an [issue](https://github.com/kikiloaw/nativephp-secure-storage-faker/issues) on GitHub
4. Check the [examples](examples/) directory for usage patterns

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance47

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a638639c58403e4b38b5cde19f7f42436d512c8de8162026d0c078ed8b635c1f?d=identicon)[kikiloaw](/maintainers/kikiloaw)

---

Top Contributors

[![kikiloaw](https://avatars.githubusercontent.com/u/34835540?v=4)](https://github.com/kikiloaw "kikiloaw (1 commits)")

### Embed Badge

![Health badge](/badges/kikiloaw-nativephp-secure-storage-faker/health.svg)

```
[![Health](https://phpackages.com/badges/kikiloaw-nativephp-secure-storage-faker/health.svg)](https://phpackages.com/packages/kikiloaw-nativephp-secure-storage-faker)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
