Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / caxy / php-htmldiff / lib / Caxy / HtmlDiff / Table / TableRow.php
1 <?php
2
3 namespace Caxy\HtmlDiff\Table;
4
5 /**
6  * Class TableRow.
7  */
8 class TableRow extends AbstractTableElement
9 {
10     /**
11      * @var Table
12      */
13     protected $table;
14
15     /**
16      * @var TableCell[]
17      */
18     protected $cells = array();
19
20     /**
21      * @return Table
22      */
23     public function getTable()
24     {
25         return $this->table;
26     }
27
28     /**
29      * @param Table|null $table
30      *
31      * @return $this
32      */
33     public function setTable(Table $table = null)
34     {
35         $this->table = $table;
36
37         if ($table && !in_array($this, $table->getRows())) {
38             $table->addRow($this);
39         }
40
41         return $this;
42     }
43
44     /**
45      * @return TableCell[]
46      */
47     public function getCells()
48     {
49         return $this->cells;
50     }
51
52     /**
53      * @param TableCell $cell
54      *
55      * @return $this
56      */
57     public function addCell(TableCell $cell)
58     {
59         $this->cells[] = $cell;
60
61         if (!$cell->getRow()) {
62             $cell->setRow($this);
63         }
64
65         return $this;
66     }
67
68     /**
69      * @param TableCell $cell
70      */
71     public function removeCell(TableCell $cell)
72     {
73         $key = array_search($cell, $this->cells, true);
74
75         if ($key !== false) {
76             unset($this->cells[$key]);
77             if ($cell->getRow()) {
78                 $cell->setRow(null);
79             }
80         }
81     }
82
83     /**
84      * @param int $index
85      *
86      * @return TableCell|null
87      */
88     public function getCell($index)
89     {
90         return isset($this->cells[$index]) ? $this->cells[$index] : null;
91     }
92
93     /**
94      * @param TableCell[] $cells
95      * @param null|int    $position
96      */
97     public function insertCells($cells, $position = null)
98     {
99         if ($position === null) {
100             $this->cells = array_merge($this->cells, $cells);
101         } else {
102             array_splice($this->cells, $position, 0, $cells);
103         }
104     }
105 }