ConnectionFactoryOption.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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\Configuration;
  11. use InvalidArgumentException;
  12. use Predis\Connection\Factory;
  13. use Predis\Connection\FactoryInterface;
  14. /**
  15. * Configures a connection factory used by the client to create new connection
  16. * instances for single Redis nodes.
  17. *
  18. * @author Daniele Alessandri <suppakilla@gmail.com>
  19. */
  20. class ConnectionFactoryOption implements OptionInterface
  21. {
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public function filter(OptionsInterface $options, $value)
  26. {
  27. if ($value instanceof FactoryInterface) {
  28. return $value;
  29. } else if (is_array($value)) {
  30. $factory = $this->getDefault($options);
  31. foreach ($value as $scheme => $initializer) {
  32. $factory->define($scheme, $initializer);
  33. }
  34. return $factory;
  35. } else {
  36. throw new InvalidArgumentException(
  37. 'Invalid value provided for the connections option.'
  38. );
  39. }
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function getDefault(OptionsInterface $options)
  45. {
  46. return new Factory();
  47. }
  48. }