ClientConnectionFactory.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /*
  3. * This file is part of the Predis package.
  4. *
  5. * (c) Daniele Alessandri <suppakilla@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Predis\Options;
  11. use Predis\IConnectionFactory;
  12. use Predis\ConnectionFactory;
  13. /**
  14. * Option class that returns a connection factory to be used by a client.
  15. *
  16. * @author Daniele Alessandri <suppakilla@gmail.com>
  17. */
  18. class ClientConnectionFactory extends Option
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function validate($value)
  24. {
  25. if ($value instanceof IConnectionFactory) {
  26. return $value;
  27. }
  28. if (is_array($value)) {
  29. $factory = $this->getDefault();
  30. foreach ($value as $scheme => $initializer) {
  31. $factory->define($scheme, $initializer);
  32. }
  33. return $factory;
  34. }
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function getDefault()
  40. {
  41. return new ConnectionFactory();
  42. }
  43. }