The clean & modern RSS server that doesn't give you any crap. https://thearsse.com/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ResultAggregate.php 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /** @license MIT
  3. * Copyright 2017 J. King, Dustin Wilson et al.
  4. * See LICENSE and AUTHORS files for details */
  5. declare(strict_types=1);
  6. namespace JKingWeb\Arsse\Db;
  7. use JKingWeb\Arsse\Db\Exception;
  8. class ResultAggregate extends AbstractResult {
  9. protected $data;
  10. protected $index = 0;
  11. protected $cur = null;
  12. // actual public methods
  13. public function changes(): int {
  14. return array_reduce($this->data, function($sum, $value) {
  15. return $sum + $value->changes();
  16. }, 0);
  17. }
  18. public function lastId(): int {
  19. return $this->data[sizeof($this->data) - 1]->lastId();
  20. }
  21. // constructor/destructor
  22. public function __construct(Result ...$result) {
  23. $this->data = $result;
  24. }
  25. public function __destruct() {
  26. $max = sizeof($this->data);
  27. for ($a = 0; $a < $max; $a++) {
  28. unset($this->data[$a]);
  29. }
  30. }
  31. // PHP iterator methods
  32. public function valid() {
  33. while (!$this->cur && isset($this->data[$this->index])) {
  34. $this->cur = $this->data[$this->index]->getRow();
  35. if (!$this->cur) {
  36. $this->index++;
  37. }
  38. }
  39. return (bool) $this->cur;
  40. }
  41. }