12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace Predis\Profile;
- use InvalidArgumentException;
- use ReflectionClass;
- use Predis\ClientException;
- final class Factory
- {
- private static $profiles = array(
- '1.2' => 'Predis\Profile\RedisVersion120',
- '2.0' => 'Predis\Profile\RedisVersion200',
- '2.2' => 'Predis\Profile\RedisVersion220',
- '2.4' => 'Predis\Profile\RedisVersion240',
- '2.6' => 'Predis\Profile\RedisVersion260',
- '2.8' => 'Predis\Profile\RedisVersion280',
- 'default' => 'Predis\Profile\RedisVersion280',
- 'dev' => 'Predis\Profile\RedisUnstable',
- );
-
- private function __construct()
- {
-
- }
-
- public static function getDefault()
- {
- return self::get('default');
- }
-
- public static function getDevelopment()
- {
- return self::get('dev');
- }
-
- public static function define($alias, $profileClass)
- {
- $reflection = new ReflectionClass($profileClass);
- if (!$reflection->isSubclassOf('Predis\Profile\ProfileInterface')) {
- throw new InvalidArgumentException("Cannot register '$profileClass' as it is not a valid profile class");
- }
- self::$profiles[$alias] = $profileClass;
- }
-
- public static function get($version)
- {
- if (!isset(self::$profiles[$version])) {
- throw new ClientException("Unknown server profile: $version");
- }
- $profile = self::$profiles[$version];
- return new $profile();
- }
- }
|