1 | <?php |
||
19 | class DefaultCellBuilder implements CellBuilderInterface |
||
20 | { |
||
21 | /** |
||
22 | * A-Z character array to build cell ids. |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | private $characters = array(); |
||
27 | |||
28 | /** |
||
29 | * Array of control characters that should be escaped. |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | private $controlCharacters = array(); |
||
34 | |||
35 | /** |
||
36 | * Array of escape characters to replace control characters. |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | private $escapeCharacters = array(); |
||
41 | |||
42 | /** |
||
43 | * CellBuilder constructor to instantiate character properties. |
||
44 | */ |
||
45 | 4 | public function __construct() |
|
46 | { |
||
47 | 4 | $this->characters = range('A', 'Z'); |
|
48 | |||
49 | 4 | foreach(range(chr(0), chr(31)) as $key => $char) { |
|
50 | 4 | if (!in_array($char, array("\n", "\r", "\t"))) { |
|
51 | 4 | $this->controlCharacters[] = $char; |
|
52 | 4 | $this->escapeCharacters[] = sprintf('_x%04s_', strtoupper(dechex($key))); |
|
53 | 4 | } |
|
54 | 4 | } |
|
55 | 4 | } |
|
56 | |||
57 | /** |
||
58 | * Build and return the string for a single cell. |
||
59 | * |
||
60 | * @param int $rowNumber |
||
61 | * @param int $cellNumber |
||
62 | * @param string $value |
||
63 | * @param int $styleId |
||
64 | * @return string |
||
65 | */ |
||
66 | 2 | public function build($rowNumber, $cellNumber, $value, $styleId = 0) |
|
80 | |||
81 | /** |
||
82 | * Turn a integer cell number + row number into a valid cell identifier |
||
83 | * like e.g. A1, Z1, AA1 etc and return it. |
||
84 | * |
||
85 | * @param int $cellNumber |
||
86 | * @param int|null $rowNumber |
||
87 | * @return string |
||
88 | */ |
||
89 | 2 | private function getCellId($cellNumber, $rowNumber = null) |
|
97 | |||
98 | /** |
||
99 | * Determine if the string requires additional escaping. |
||
100 | * |
||
101 | * @param string $value |
||
102 | * @return bool |
||
103 | */ |
||
104 | 2 | private function isWordCharacter($value) |
|
108 | |||
109 | /** |
||
110 | * Replace control characters with escape characters. |
||
111 | * |
||
112 | * @param string $value |
||
113 | * @return string |
||
114 | */ |
||
115 | 1 | private function escapeControlCharacters($value) |
|
119 | } |
||
120 |