1 | <?php |
||
12 | class Styler |
||
13 | { |
||
14 | /** |
||
15 | * @var Style[] |
||
16 | */ |
||
17 | private $styles = array(); |
||
18 | |||
19 | /** |
||
20 | * @var Font[] |
||
21 | */ |
||
22 | private $fonts = array(); |
||
23 | |||
24 | /** |
||
25 | * @var Fill[] |
||
26 | */ |
||
27 | private $fills = array(); |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | private $hashes = array(); |
||
33 | |||
34 | /** |
||
35 | * Styler constructor. |
||
36 | */ |
||
37 | 4 | public function __construct() |
|
38 | { |
||
39 | 4 | $this->addStyle(new Style()); |
|
40 | 4 | $grey = new Style(); |
|
41 | 4 | $this->addStyle($grey->setFillPattern('grey125')); |
|
42 | 4 | } |
|
43 | |||
44 | /** |
||
45 | * Add a new style, if it doesnt exists yet. |
||
46 | * |
||
47 | * @param Style $style |
||
48 | */ |
||
49 | 4 | public function addStyle(Style $style) |
|
50 | { |
||
51 | 4 | if (null === $style->getId()) { |
|
52 | 4 | $this->register($style->getFont(), $this->fonts); |
|
53 | 4 | $this->register($style->getFill(), $this->fills); |
|
54 | 4 | $this->register($style, $this->styles); |
|
55 | 4 | $style->lock(); |
|
56 | 4 | } |
|
57 | 4 | } |
|
58 | |||
59 | /** |
||
60 | * Register a new Style compoment its compoments to account |
||
61 | * for reusable styles, fills, fonts, ... |
||
62 | * |
||
63 | * @param Component $component |
||
64 | * @param array $collection |
||
65 | */ |
||
66 | 4 | private function register(Component $component, &$collection) |
|
79 | |||
80 | /** |
||
81 | * @param int $id |
||
82 | * @return Style |
||
83 | */ |
||
84 | 1 | public function getStyleById($id) |
|
88 | |||
89 | /** |
||
90 | * Return entire xml string for the style sheet. |
||
91 | * |
||
92 | * @return string |
||
93 | */ |
||
94 | 2 | public function getStyleSheetXml() |
|
115 | } |
||
116 |