ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Style.php
Go to the documentation of this file.
1 <?php
2 
4 
6 
7 class Style
8 {
14  protected $styles = [];
15 
16  public function parseStyles(SimpleXMLElement $xml, array $namespaces): array
17  {
18  if (!isset($xml->Styles)) {
19  return [];
20  }
21 
22  $alignmentStyleParser = new Style\Alignment();
23  $borderStyleParser = new Style\Border();
24  $fontStyleParser = new Style\Font();
25  $fillStyleParser = new Style\Fill();
26  $numberFormatStyleParser = new Style\NumberFormat();
27 
28  foreach ($xml->Styles[0] as $style) {
29  $style_ss = self::getAttributes($style, $namespaces['ss']);
30  $styleID = (string) $style_ss['ID'];
31  $this->styles[$styleID] = $this->styles['Default'] ?? [];
32 
33  $alignment = $border = $font = $fill = $numberFormat = [];
34 
35  foreach ($style as $styleType => $styleDatax) {
36  $styleData = $styleDatax ?? new SimpleXMLElement('<xml></xml>');
37  $styleAttributes = $styleData->attributes($namespaces['ss']);
38  switch ($styleType) {
39  case 'Alignment':
40  $alignment = $alignmentStyleParser->parseStyle($styleAttributes);
41 
42  break;
43  case 'Borders':
44  $border = $borderStyleParser->parseStyle($styleData, $namespaces);
45 
46  break;
47  case 'Font':
48  $font = $fontStyleParser->parseStyle($styleAttributes);
49 
50  break;
51  case 'Interior':
52  $fill = $fillStyleParser->parseStyle($styleAttributes);
53 
54  break;
55  case 'NumberFormat':
56  $numberFormat = $numberFormatStyleParser->parseStyle($styleAttributes);
57 
58  break;
59  }
60  }
61 
62  $this->styles[$styleID] = array_merge($alignment, $border, $font, $fill, $numberFormat);
63  }
64 
65  return $this->styles;
66  }
67 
68  protected static function getAttributes(?SimpleXMLElement $simple, string $node): SimpleXMLElement
69  {
70  return ($simple === null)
71  ? new SimpleXMLElement('<xml></xml>')
72  : ($simple->attributes($node) ?? new SimpleXMLElement('<xml></xml>'));
73  }
74 }
$style
Definition: example_012.php:70
$border
parseStyles(SimpleXMLElement $xml, array $namespaces)
Definition: Style.php:16
static getAttributes(?SimpleXMLElement $simple, string $node)
Definition: Style.php:68