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