Getting Started
Manager provides an abstract pattern for managing multiple connections or drivers in PHP applications, commonly used for databases, caches, queues, and external services.
Installation
Section titled “Installation”composer require cline/managerBasic Usage
Section titled “Basic Usage”use Cline\Manager\AbstractManager;
class CacheManager extends AbstractManager{ protected function createRedisConnector(): CacheInterface { return new RedisCache($this->config['redis']); }
protected function createMemcachedConnector(): CacheInterface { return new MemcachedCache($this->config['memcached']); }}
// Usage$manager = new CacheManager($config);$cache = $manager->connection('redis');$cache->set('key', 'value');Concepts
Section titled “Concepts”Manager
Section titled “Manager”The manager maintains a pool of connections and provides access to them by name. It handles instantiation and caching of connections.
Connector
Section titled “Connector”A connector creates a specific type of connection. Each driver (redis, memcached, etc.) has its own connector.
Connection
Section titled “Connection”The actual connection instance that does the work. Created by connectors and cached by the manager.
Configuration
Section titled “Configuration”$config = [ 'default' => 'redis', 'connections' => [ 'redis' => [ 'driver' => 'redis', 'host' => '127.0.0.1', 'port' => 6379, ], 'memcached' => [ 'driver' => 'memcached', 'servers' => ['127.0.0.1:11211'], ], ],];
$manager = new CacheManager($config);Next Steps
Section titled “Next Steps”- Abstract Manager - Implement your own manager
- Connector Interface - Create custom connectors
- Manager Interface - Manager API reference