RedisAdapter.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /*
  3. * This file is part of Packagist.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  6. * Nils Adermann <naderman@naderman.de>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Packagist\WebBundle\Model;
  12. use Pagerfanta\Adapter\AdapterInterface;
  13. /**
  14. * @author Jordi Boggiano <j.boggiano@seld.be>
  15. */
  16. class RedisAdapter implements AdapterInterface
  17. {
  18. protected $model;
  19. protected $instance;
  20. protected $fetchMethod;
  21. protected $countMethod;
  22. public function __construct($model, $instance, $fetchMethod, $countMethod)
  23. {
  24. $this->model = $model;
  25. $this->instance = $instance;
  26. $this->fetchMethod = $fetchMethod;
  27. $this->countMethod = $countMethod;
  28. }
  29. /**
  30. * {@inheritDoc}
  31. */
  32. public function getNbResults()
  33. {
  34. return $this->model->{$this->countMethod}($this->instance);
  35. }
  36. /**
  37. * {@inheritDoc}
  38. */
  39. public function getSlice($offset, $length)
  40. {
  41. return $this->model->{$this->fetchMethod}($this->instance, $length, $offset);
  42. }
  43. }