1 | <?php |
||
13 | class SheetManager |
||
14 | { |
||
15 | /** Sheet name should not exceed 31 characters */ |
||
16 | const MAX_LENGTH_SHEET_NAME = 31; |
||
17 | |||
18 | /** @var array Invalid characters that cannot be contained in the sheet name */ |
||
19 | private static $INVALID_CHARACTERS_IN_SHEET_NAME = ['\\', '/', '?', '*', ':', '[', ']']; |
||
20 | |||
21 | /** @var array Associative array [WORKBOOK_ID] => [[SHEET_INDEX] => [SHEET_NAME]] keeping track of sheets' name to enforce uniqueness per workbook */ |
||
22 | private static $SHEETS_NAME_USED = []; |
||
23 | |||
24 | /** @var StringHelper */ |
||
25 | private $stringHelper; |
||
26 | |||
27 | /** |
||
28 | * SheetManager constructor. |
||
29 | * |
||
30 | * @param StringHelper $stringHelper |
||
31 | */ |
||
32 | 98 | public function __construct(StringHelper $stringHelper) |
|
36 | |||
37 | /** |
||
38 | * Throws an exception if the given sheet's name is not valid. |
||
39 | * @see Sheet::setName for validity rules. |
||
40 | * |
||
41 | * @param string $name |
||
42 | * @param Sheet $sheet The sheet whose future name is checked |
||
43 | * @throws \Box\Spout\Writer\Exception\InvalidSheetNameException If the sheet's name is invalid. |
||
44 | * @return void |
||
45 | */ |
||
46 | 98 | public function throwIfNameIsInvalid($name, Sheet $sheet) |
|
83 | |||
84 | /** |
||
85 | * Returns whether the given name contains at least one invalid character. |
||
86 | * @see Sheet::$INVALID_CHARACTERS_IN_SHEET_NAME for the full list. |
||
87 | * |
||
88 | * @param string $name |
||
89 | * @return bool TRUE if the name contains invalid characters, FALSE otherwise. |
||
90 | */ |
||
91 | 98 | private function doesContainInvalidCharacters($name) |
|
95 | |||
96 | /** |
||
97 | * Returns whether the given name starts or ends with a single quote |
||
98 | * |
||
99 | * @param string $name |
||
100 | * @return bool TRUE if the name starts or ends with a single quote, FALSE otherwise. |
||
101 | */ |
||
102 | 98 | private function doesStartOrEndWithSingleQuote($name) |
|
109 | |||
110 | /** |
||
111 | * Returns whether the given name is unique. |
||
112 | * |
||
113 | * @param string $name |
||
114 | * @param Sheet $sheet The sheet whose future name is checked |
||
115 | * @return bool TRUE if the name is unique, FALSE otherwise. |
||
116 | */ |
||
117 | 98 | private function isNameUnique($name, Sheet $sheet) |
|
127 | |||
128 | /** |
||
129 | * @param int $workbookId Workbook ID associated to a Sheet |
||
130 | * @return void |
||
131 | */ |
||
132 | 98 | public function markWorkbookIdAsUsed($workbookId) |
|
138 | |||
139 | /** |
||
140 | * @param Sheet $sheet |
||
141 | * @return void |
||
142 | */ |
||
143 | 98 | public function markSheetNameAsUsed(Sheet $sheet) |
|
147 | } |
||
148 |