updated a couple packages (#1567)
[openemr.git] / vendor / phpoffice / phpspreadsheet / src / PhpSpreadsheet / Style / Borders.php
bloba1d6759b936df56296615920da09ab9b0330cb1c
1 <?php
3 namespace PhpOffice\PhpSpreadsheet\Style;
5 use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
7 class Borders extends Supervisor
9 // Diagonal directions
10 const DIAGONAL_NONE = 0;
11 const DIAGONAL_UP = 1;
12 const DIAGONAL_DOWN = 2;
13 const DIAGONAL_BOTH = 3;
15 /**
16 * Left.
18 * @var Border
20 protected $left;
22 /**
23 * Right.
25 * @var Border
27 protected $right;
29 /**
30 * Top.
32 * @var Border
34 protected $top;
36 /**
37 * Bottom.
39 * @var Border
41 protected $bottom;
43 /**
44 * Diagonal.
46 * @var Border
48 protected $diagonal;
50 /**
51 * DiagonalDirection.
53 * @var int
55 protected $diagonalDirection;
57 /**
58 * All borders pseudo-border. Only applies to supervisor.
60 * @var Border
62 protected $allBorders;
64 /**
65 * Outline pseudo-border. Only applies to supervisor.
67 * @var Border
69 protected $outline;
71 /**
72 * Inside pseudo-border. Only applies to supervisor.
74 * @var Border
76 protected $inside;
78 /**
79 * Vertical pseudo-border. Only applies to supervisor.
81 * @var Border
83 protected $vertical;
85 /**
86 * Horizontal pseudo-border. Only applies to supervisor.
88 * @var Border
90 protected $horizontal;
92 /**
93 * Create a new Borders.
95 * @param bool $isSupervisor Flag indicating if this is a supervisor or not
96 * Leave this value at default unless you understand exactly what
97 * its ramifications are
98 * @param bool $isConditional Flag indicating if this is a conditional style or not
99 * Leave this value at default unless you understand exactly what
100 * its ramifications are
102 public function __construct($isSupervisor = false, $isConditional = false)
104 // Supervisor?
105 parent::__construct($isSupervisor);
107 // Initialise values
108 $this->left = new Border($isSupervisor, $isConditional);
109 $this->right = new Border($isSupervisor, $isConditional);
110 $this->top = new Border($isSupervisor, $isConditional);
111 $this->bottom = new Border($isSupervisor, $isConditional);
112 $this->diagonal = new Border($isSupervisor, $isConditional);
113 $this->diagonalDirection = self::DIAGONAL_NONE;
115 // Specially for supervisor
116 if ($isSupervisor) {
117 // Initialize pseudo-borders
118 $this->allBorders = new Border(true);
119 $this->outline = new Border(true);
120 $this->inside = new Border(true);
121 $this->vertical = new Border(true);
122 $this->horizontal = new Border(true);
124 // bind parent if we are a supervisor
125 $this->left->bindParent($this, 'left');
126 $this->right->bindParent($this, 'right');
127 $this->top->bindParent($this, 'top');
128 $this->bottom->bindParent($this, 'bottom');
129 $this->diagonal->bindParent($this, 'diagonal');
130 $this->allBorders->bindParent($this, 'allBorders');
131 $this->outline->bindParent($this, 'outline');
132 $this->inside->bindParent($this, 'inside');
133 $this->vertical->bindParent($this, 'vertical');
134 $this->horizontal->bindParent($this, 'horizontal');
139 * Get the shared style component for the currently active cell in currently active sheet.
140 * Only used for style supervisor.
142 * @return Borders
144 public function getSharedComponent()
146 return $this->parent->getSharedComponent()->getBorders();
150 * Build style array from subcomponents.
152 * @param array $array
154 * @return array
156 public function getStyleArray($array)
158 return ['borders' => $array];
162 * Apply styles from array.
164 * <code>
165 * $spreadsheet->getActiveSheet()->getStyle('B2')->getBorders()->applyFromArray(
167 * 'bottom' => [
168 * 'borderStyle' => Border::BORDER_DASHDOT,
169 * 'color' => [
170 * 'rgb' => '808080'
172 * ],
173 * 'top' => [
174 * 'borderStyle' => Border::BORDER_DASHDOT,
175 * 'color' => [
176 * 'rgb' => '808080'
180 * );
181 * </code>
183 * <code>
184 * $spreadsheet->getActiveSheet()->getStyle('B2')->getBorders()->applyFromArray(
186 * 'allBorders' => [
187 * 'borderStyle' => Border::BORDER_DASHDOT,
188 * 'color' => [
189 * 'rgb' => '808080'
193 * );
194 * </code>
196 * @param array $pStyles Array containing style information
198 * @throws PhpSpreadsheetException
200 * @return Borders
202 public function applyFromArray(array $pStyles)
204 if ($this->isSupervisor) {
205 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
206 } else {
207 if (isset($pStyles['left'])) {
208 $this->getLeft()->applyFromArray($pStyles['left']);
210 if (isset($pStyles['right'])) {
211 $this->getRight()->applyFromArray($pStyles['right']);
213 if (isset($pStyles['top'])) {
214 $this->getTop()->applyFromArray($pStyles['top']);
216 if (isset($pStyles['bottom'])) {
217 $this->getBottom()->applyFromArray($pStyles['bottom']);
219 if (isset($pStyles['diagonal'])) {
220 $this->getDiagonal()->applyFromArray($pStyles['diagonal']);
222 if (isset($pStyles['diagonalDirection'])) {
223 $this->setDiagonalDirection($pStyles['diagonalDirection']);
225 if (isset($pStyles['allBorders'])) {
226 $this->getLeft()->applyFromArray($pStyles['allBorders']);
227 $this->getRight()->applyFromArray($pStyles['allBorders']);
228 $this->getTop()->applyFromArray($pStyles['allBorders']);
229 $this->getBottom()->applyFromArray($pStyles['allBorders']);
233 return $this;
237 * Get Left.
239 * @return Border
241 public function getLeft()
243 return $this->left;
247 * Get Right.
249 * @return Border
251 public function getRight()
253 return $this->right;
257 * Get Top.
259 * @return Border
261 public function getTop()
263 return $this->top;
267 * Get Bottom.
269 * @return Border
271 public function getBottom()
273 return $this->bottom;
277 * Get Diagonal.
279 * @return Border
281 public function getDiagonal()
283 return $this->diagonal;
287 * Get AllBorders (pseudo-border). Only applies to supervisor.
289 * @throws PhpSpreadsheetException
291 * @return Border
293 public function getAllBorders()
295 if (!$this->isSupervisor) {
296 throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.');
299 return $this->allBorders;
303 * Get Outline (pseudo-border). Only applies to supervisor.
305 * @throws PhpSpreadsheetException
307 * @return Border
309 public function getOutline()
311 if (!$this->isSupervisor) {
312 throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.');
315 return $this->outline;
319 * Get Inside (pseudo-border). Only applies to supervisor.
321 * @throws PhpSpreadsheetException
323 * @return Border
325 public function getInside()
327 if (!$this->isSupervisor) {
328 throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.');
331 return $this->inside;
335 * Get Vertical (pseudo-border). Only applies to supervisor.
337 * @throws PhpSpreadsheetException
339 * @return Border
341 public function getVertical()
343 if (!$this->isSupervisor) {
344 throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.');
347 return $this->vertical;
351 * Get Horizontal (pseudo-border). Only applies to supervisor.
353 * @throws PhpSpreadsheetException
355 * @return Border
357 public function getHorizontal()
359 if (!$this->isSupervisor) {
360 throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.');
363 return $this->horizontal;
367 * Get DiagonalDirection.
369 * @return int
371 public function getDiagonalDirection()
373 if ($this->isSupervisor) {
374 return $this->getSharedComponent()->getDiagonalDirection();
377 return $this->diagonalDirection;
381 * Set DiagonalDirection.
383 * @param int $pValue see self::DIAGONAL_*
385 * @return Borders
387 public function setDiagonalDirection($pValue)
389 if ($pValue == '') {
390 $pValue = self::DIAGONAL_NONE;
392 if ($this->isSupervisor) {
393 $styleArray = $this->getStyleArray(['diagonalDirection' => $pValue]);
394 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
395 } else {
396 $this->diagonalDirection = $pValue;
399 return $this;
403 * Get hash code.
405 * @return string Hash code
407 public function getHashCode()
409 if ($this->isSupervisor) {
410 return $this->getSharedComponent()->getHashcode();
413 return md5(
414 $this->getLeft()->getHashCode() .
415 $this->getRight()->getHashCode() .
416 $this->getTop()->getHashCode() .
417 $this->getBottom()->getHashCode() .
418 $this->getDiagonal()->getHashCode() .
419 $this->getDiagonalDirection() .
420 __CLASS__