Skip to content

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.

Terminal window
composer require cline/manager
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');

The manager maintains a pool of connections and provides access to them by name. It handles instantiation and caching of connections.

A connector creates a specific type of connection. Each driver (redis, memcached, etc.) has its own connector.

The actual connection instance that does the work. Created by connectors and cached by the manager.

$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);