laminas/laminas-cache-storage-deprecated-factory
Install the Package
Add to your composer.json:
composer require laminas/laminas-cache-storage-deprecated-factory
Ensure your project uses laminas/laminas-cache:^3.0 (not v4+).
Locate Legacy Usage Search your codebase for:
use Laminas\Cache\StorageFactory;
or instantiations like:
$factory = new \Laminas\Cache\StorageFactory();
First Use Case: Replace the Factory Replace the deprecated factory with the temporary one:
use Laminas\Cache\Storage\DeprecatedFactory;
$factory = new DeprecatedFactory();
Verify Adapter Compatibility
Test with your existing adapter configurations (e.g., Apcu, Redis, Filesystem). Example:
$options = [
'adapter' => [
'name' => 'filesystem',
'options' => [
'cache_dir' => storage_path('framework/cache'),
],
],
];
$cache = $factory->createService($options);
Service Provider Integration Bind the deprecated factory in a Laravel service provider to replace legacy instantiations:
use Laminas\Cache\Storage\DeprecatedFactory;
use Illuminate\Support\ServiceProvider;
class CacheServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton('laminas.cache.deprecated_factory', function () {
return new DeprecatedFactory();
});
}
}
Facade Wrapper (Optional) Create a facade to abstract Laminas Cache usage:
// app/Facades/LaminasCache.php
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class LaminasCache extends Facade
{
protected static function getFacadeAccessor()
{
return 'laminas.cache.deprecated_factory';
}
}
Configuration-Driven Cache Setup Use Laravel’s config to define cache adapters and inject them via the factory:
// config/laminas-cache.php
'adapters' => [
'default' => [
'adapter' => 'filesystem',
'options' => [
'cache_dir' => storage_path('framework/cache'),
],
],
],
Then resolve in a service:
$factory = app('laminas.cache.deprecated_factory');
$cache = $factory->createService(config('laminas-cache.adapters.default'));
Migration Workflow
StorageFactory with DeprecatedFactory in all instantiations.laminas-cache v3.x APIs in your codebase.Leveraging Laminas Service Manager (Optional) If your Laravel app uses Laminas Service Manager (e.g., for microservices), configure the factory in the Laminas DI container:
$container->setFactory('Laminas\Cache\Storage\Factory', DeprecatedFactory::class);
Not a Long-Term Solution
laminas-cache v4+. Plan to migrate away once all dependencies support v3.x.Adapter-Specific Quirks
Apcu, Redis) may have subtle behavioral differences between v2.x and v3.x. Test thoroughly:
// Example: Redis adapter may require updated options
$options = [
'adapter' => [
'name' => 'redis',
'options' => [
'host' => '127.0.0.1',
'port' => 6379,
'database' => 0,
// v3.x may require additional options like 'serializer'
],
],
];
PHP Version Lock-In
Laminas Dependency Bloat
laminas-servicemanager and laminas-stdlib as dependencies. Audit your composer.json for conflicts.Facade Collisions
Cache facade and Laminas Cache, ensure namespaces are distinct to avoid ambiguity.Verify Factory Instantiation
$factory = new \Laminas\Cache\Storage\DeprecatedFactory();
\Log::debug(get_class($factory)); // Should output: Laminas\Cache\Storage\DeprecatedFactory
Check Adapter Creation
$cache = $factory->createService($options);
\Log::debug(get_class($cache)); // Should output: Laminas\Cache\Storage\Adapter\PluginManager
Test Cache Operations
$cache->setItem('key', 'value');
$item = $cache->getItem('key');
\Log::debug($item->getData()); // Should output: 'value'
Handle Deprecation Warnings
error_reporting(E_ALL & ~E_DEPRECATED);
Custom Factory Extensions
DeprecatedFactory to add pre/post-processing logic:
class CustomDeprecatedFactory extends \Laminas\Cache\Storage\DeprecatedFactory
{
public function createService(array $options)
{
$service = parent::createService($options);
// Add custom logic (e.g., logging, metrics)
return $service;
}
}
Adapter-Specific Overrides
$factory = new DeprecatedFactory();
$options['adapter']['options']['custom_key'] = 'custom_value';
$cache = $factory->createService($options);
Integration with Laravel Events
cache.hit, cache.miss) to log or monitor usage:
\Event::listen('cache.hit', function ($key, $item) {
\Log::info("Cache hit for key: {$key}");
});
Fallback to Laravel Cache
try {
$cache = $factory->createService($options);
} catch (\Exception $e) {
$cache = \Cache::store('file'); // Fallback to Laravel's cache
}
Adapter Naming
// Correct:
'adapter' => ['name' => 'filesystem']
// Incorrect (will fail):
'adapter' => ['name' => 'Filesystem']
Option Validation
laminas-cache v3.x may enforce stricter option validation. Refer to the Laminas Cache v3 docs for required options.Service Manager Configuration
Laravel Caching Conflicts
file, redis). Use unique names like laminas_filesystem.How can I help you explore Laravel packages today?