Advertisement
Guest User

Untitled

a guest
May 21st, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. <?php
  2.  
  3. final class ListOfId implements \Iterator, \Countable
  4. {
  5.     private $values;
  6.  
  7.     public function __construct(array $values = [])
  8.     {
  9.         $this->values = array_values(array_filter(array_unique(array_map('intval', $values))));
  10.     }
  11.  
  12.     public function count()
  13.     {
  14.         return \count($this->values);
  15.     }
  16.  
  17.     public function isEmpty()
  18.     {
  19.         return $this->count() > 0;
  20.     }
  21.  
  22.     public function toArray()
  23.     {
  24.         return $this->values;
  25.     }
  26.  
  27.     public function current()
  28.     {
  29.         return \current($this->values);
  30.     }
  31.  
  32.     public function next()
  33.     {
  34.         return \next($this->values);
  35.     }
  36.  
  37.     public function key()
  38.     {
  39.         return \key($this->values);
  40.     }
  41.  
  42.     public function valid()
  43.     {
  44.         return \key($this->values) !== null;
  45.     }
  46.  
  47.     public function rewind()
  48.     {
  49.         return \reset($this->values);
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement