vendor/contao-bootstrap/grid/src/GridIterator.php line 22

Open in your IDE?
  1. <?php
  2. /**
  3.  * Contao Bootstrap grid.
  4.  *
  5.  * @filesource
  6.  */
  7. declare(strict_types=1);
  8. namespace ContaoBootstrap\Grid;
  9. use ContaoBootstrap\Grid\Definition\Grid;
  10. use Iterator;
  11. use function assert;
  12. use function is_string;
  13. /**
  14.  * GridIterator to iterate over the grid columns.
  15.  */
  16. final class GridIterator implements Iterator
  17. {
  18.     /**
  19.      * Grid.
  20.      */
  21.     private Grid $grid;
  22.     /**
  23.      * Current index.
  24.      */
  25.     private int $index 0;
  26.     /**
  27.      * @param Grid $grid The grid.
  28.      */
  29.     public function __construct(Grid $grid)
  30.     {
  31.         $this->grid $grid;
  32.     }
  33.     /**
  34.      * Build a row.
  35.      */
  36.     public function row(): string
  37.     {
  38.         $row $this->grid->buildRow(true);
  39.         assert(is_string($row));
  40.         return $row;
  41.     }
  42.     /**
  43.      * Get all resets.
  44.      *
  45.      * @return list<string>
  46.      */
  47.     public function resets(): array
  48.     {
  49.         return $this->grid->buildResets($this->index);
  50.     }
  51.     public function current(): string
  52.     {
  53.         $column $this->grid->buildColumn($this->indextrue);
  54.         assert(is_string($column));
  55.         return $column;
  56.     }
  57.     public function next(): void
  58.     {
  59.         $this->index++;
  60.     }
  61.     /**
  62.      * {@inheritdoc}
  63.      */
  64.     public function key()
  65.     {
  66.         return $this->index;
  67.     }
  68.     public function valid(): bool
  69.     {
  70.         return true;
  71.     }
  72.     public function rewind(): void
  73.     {
  74.         $this->index 0;
  75.     }
  76. }