RedisProxy.php 915 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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 Symfony\Component\Messenger\Bridge\Redis\Transport;
  11. /**
  12. * Allow to delay connection to Redis.
  13. *
  14. * @author Tobias Nyholm <tobias.nyholm@gmail.com>
  15. * @author Nicolas Grekas <p@tchwork.com>
  16. *
  17. * @internal
  18. */
  19. class RedisProxy
  20. {
  21. private $redis;
  22. private $initializer;
  23. private $ready = false;
  24. public function __construct(\Redis $redis, \Closure $initializer)
  25. {
  26. $this->redis = $redis;
  27. $this->initializer = $initializer;
  28. }
  29. public function __call(string $method, array $args)
  30. {
  31. $this->ready ?: $this->ready = $this->initializer->__invoke($this->redis);
  32. return $this->redis->{$method}(...$args);
  33. }
  34. }