ClientProfile.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\Options;
  11. use Predis\Profiles\ServerProfile;
  12. use Predis\Profiles\IServerProfile;
  13. /**
  14. * Option class that handles server profiles to be used by a client.
  15. *
  16. * @author Daniele Alessandri <suppakilla@gmail.com>
  17. */
  18. class ClientProfile extends Option
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function filter(IClientOptions $options, $value)
  24. {
  25. if (is_string($value)) {
  26. $value = ServerProfile::get($value);
  27. if (isset($options->prefix)) {
  28. $value->setProcessor($options->prefix);
  29. }
  30. }
  31. if (!$value instanceof IServerProfile) {
  32. throw new \InvalidArgumentException('Invalid value for the profile option');
  33. }
  34. return $value;
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function getDefault(IClientOptions $options)
  40. {
  41. $profile = ServerProfile::getDefault();
  42. if (isset($options->prefix)) {
  43. $profile->setProcessor($options->prefix);
  44. }
  45. return $profile;
  46. }
  47. }