spout/src/Spout/Writer/Common/Manager/RowManager.php
Adrien Loison 5dec5a3a76 Row objects and Cell styling
This commit introduces Row and Cell entities, that will replace the arrays passed in previously.
It also adds support for Cell styling (instead of Row styling only).
2017-11-05 01:41:48 +01:00

60 lines
1.3 KiB
PHP

<?php
namespace Box\Spout\Writer\Common\Manager;
use Box\Spout\Writer\Common\Entity\Row;
use Box\Spout\Writer\Common\Entity\Style\Style;
use Box\Spout\Writer\Common\Manager\Style\StyleMerger;
class RowManager
{
/**
* @var StyleMerger
*/
protected $styleMerger;
/**
* @param StyleMerger $styleMerger
*/
public function __construct(StyleMerger $styleMerger)
{
$this->styleMerger = $styleMerger;
}
/**
* @param Row $row
* @param Style $style
* @return $this
*/
public function applyStyle(Row $row, Style $style)
{
$mergedStyle = $this->styleMerger->merge($row->getStyle(), $style);
$row->setStyle($mergedStyle);
}
/**
* Returns whether a row has cells
*
* @param Row $row
* @return bool
*/
public function hasCells(Row $row)
{
return count($row->getCells()) !== 0;
}
/**
* Detect whether a row is considered empty.
* An empty row has either no cells at all - or only one empty cell
*
* @param Row $row
* @return bool
*/
public function isEmpty(Row $row)
{
$cells = $row->getCells();
return count($cells) === 0 || (count($cells) === 1 && $cells[0]->isEmpty());
}
}