PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.25
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.25
1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 All 49 releases
fluent-cart / vendor / openspout / openspout / src / Writer / Common / Manager / Style / StyleManager.php

StyleManager.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.25, at vendor/openspout/openspout/src/Writer/Common/Manager/Style/StyleManager.php

74 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\OpenSpout\Writer\Common\Manager\Style;
4
5 use FluentCart\OpenSpout\Common\Entity\Cell;
6 use FluentCart\OpenSpout\Common\Entity\Style\Style;
7 /**
8 * Manages styles to be applied to a cell.
9 */
10 class StyleManager implements StyleManagerInterface
11 {
12 /** @var StyleRegistry Registry for all used styles */
13 protected $styleRegistry;
14 public function __construct(StyleRegistry $styleRegistry)
15 {
16 $this->styleRegistry = $styleRegistry;
17 }
18 /**
19 * Registers the given style as a used style.
20 * Duplicate styles won't be registered more than once.
21 *
22 * @param Style $style The style to be registered
23 *
24 * @return Style the registered style, updated with an internal ID
25 */
26 public function registerStyle($style)
27 {
28 return $this->styleRegistry->registerStyle($style);
29 }
30 /**
31 * Apply additional styles if the given row needs it.
32 * Typically, set "wrap text" if a cell contains a new line.
33 *
34 * @return PossiblyUpdatedStyle The eventually updated style
35 */
36 public function applyExtraStylesIfNeeded(Cell $cell) : PossiblyUpdatedStyle
37 {
38 return $this->applyWrapTextIfCellContainsNewLine($cell);
39 }
40 /**
41 * Returns the default style.
42 *
43 * @return Style Default style
44 */
45 protected function getDefaultStyle()
46 {
47 // By construction, the default style has ID 0
48 return $this->styleRegistry->getRegisteredStyles()[0];
49 }
50 /**
51 * Set the "wrap text" option if a cell of the given row contains a new line.
52 *
53 * @NOTE: There is a bug on the Mac version of Excel (2011 and below) where new lines
54 * are ignored even when the "wrap text" option is set. This only occurs with
55 * inline strings (shared strings do work fine).
56 * A workaround would be to encode "\n" as "_x000D_" but it does not work
57 * on the Windows version of Excel...
58 *
59 * @param Cell $cell The cell the style should be applied to
60 *
61 * @return PossiblyUpdatedStyle The eventually updated style
62 */
63 protected function applyWrapTextIfCellContainsNewLine(Cell $cell) : PossiblyUpdatedStyle
64 {
65 $cellStyle = $cell->getStyle();
66 // if the "wrap text" option is already set, no-op
67 if (!$cellStyle->hasSetWrapText() && $cell->isString() && \false !== \strpos($cell->getValue(), "\n")) {
68 $cellStyle->setShouldWrapText();
69 return new PossiblyUpdatedStyle($cellStyle, \true);
70 }
71 return new PossiblyUpdatedStyle($cellStyle, \false);
72 }
73 }
74