zf1/zend-registry
Provides the Zend_Registry component from Zend Framework 1 as a standalone Composer package. Use it as a global registry to store and retrieve shared objects and configuration across legacy ZF1 apps, aiding modernization and dependency management.
Installation:
composer require zf1/zend-registry
(Note: This is a legacy Zend Framework 1 package. Modern Laravel developers should use Laravel's built-in app() helper or Illuminate\Support\Facades\Facade for similar functionality.)
First Use Case:
use Zend_Registry as Registry;
// Set a value
Registry::set('config', ['debug' => true]);
// Retrieve a value
$config = Registry::get('config');
Where to Look First:
app() helper (modern alternative):
$value = app('config')->get('debug');
Global State Management:
// Store a service instance
Registry::set('db', new PDO(...));
// Retrieve later
$db = Registry::get('db');
Configuration Centralization:
// Merge configs
$appConfig = Registry::get('app.config', []);
$appConfig['debug'] = env('APP_DEBUG');
Registry::set('app.config', $appConfig);
Middleware/Service Integration:
// In a Laravel service provider
public function register()
{
Registry::set('logger', $this->app->make('logger'));
}
// Use Laravel’s container instead
$this->app->singleton('registry', function () {
return new Registry();
});
No Namespacing:
'config' and 'Config' are treated as distinct.'app.config').No Type Safety:
$config = Registry::get('config');
if (!is_array($config)) {
throw new \RuntimeException('Invalid config type');
}
Memory Leaks:
Registry::unset('unneeded.key');
Laravel Conflicts:
'app').$keys = Registry::getKeys();
Registry::clear();
Registry::set('debug', true); // Enable debug mode (if available)
class AppRegistry extends Registry {
public static function set($key, $val, $namespace = 'app') { ... }
}
public function boot()
{
$this->app->resolving('registry', function ($registry) {
// Hook into registry events
});
}
How can I help you explore Laravel packages today?