ConnectionFactoryOption.php 1.3 KB

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