ClientClusterType.php 866 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace Predis\Options;
  3. use Predis\ClientException;
  4. class ClientClusterType extends Option {
  5. const CLUSTER_INTERFACE = '\Predis\Network\IConnectionCluster';
  6. const CLUSTER_PREDIS = '\Predis\Network\ConnectionCluster';
  7. public function validate($value) {
  8. switch ($value) {
  9. case 'client':
  10. return self::CLUSTER_PREDIS;
  11. default:
  12. return $this->checkClass($value);
  13. }
  14. }
  15. private function checkClass($class) {
  16. $reflection = new \ReflectionClass($class);
  17. if (!$reflection->isSubclassOf(self::CLUSTER_INTERFACE)) {
  18. throw new ClientException(
  19. "The class $class is not a valid cluster connection"
  20. );
  21. }
  22. return $class;
  23. }
  24. public function getDefault() {
  25. return self::CLUSTER_PREDIS;
  26. }
  27. }