‪TYPO3CMS  ‪main
Typo3XmlParserOptions.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
24 {
25  public const ‪FORMAT = 'format';
26  public const ‪FORMAT_INLINE = -1;
27  public const ‪FORMAT_PRETTY_WITH_TAB = 0;
28  public const ‪NAMESPACE_PREFIX = 'namespace_prefix';
29  public const ‪ROOT_NODE_NAME = 'root_node_name';
30 
31  protected array ‪$options = [
32  // Format XML with
33  // - "-1" is inline XML
34  // - "0" is pretty XML with tabs
35  // - "1...x" is pretty XML with x spaces.
36  self::FORMAT => ‪self::FORMAT_PRETTY_WITH_TAB,
37  // This XML namespace is prepended to each XML node, for example "T3:".
38  self::NAMESPACE_PREFIX => '',
39  // Wrap the XML with a root node of that name or set it to '' to skip wrapping.
40  self::ROOT_NODE_NAME => 'phparray',
41  ];
42 
43  public function ‪__construct(array ‪$options = [])
44  {
45  $this->options = array_merge($this->options, ‪$options);
46  }
47 
48  public function ‪getRootNodeName(): string
49  {
50  return $this->options[‪self::ROOT_NODE_NAME];
51  }
52 
53  public function ‪getNewlineChar(): string
54  {
55  return $this->options[‪self::FORMAT] === self::FORMAT_INLINE ? '' : LF;
56  }
57 
58  public function ‪getIndentationStep(): string
59  {
60  return match ($this->options[self::FORMAT]) {
61  self::FORMAT_INLINE => '',
62  self::FORMAT_PRETTY_WITH_TAB => "\t",
63  default => str_repeat(' ', max(0, $this->options[self::FORMAT])),
64  };
65  }
66 
67  public function ‪getNamespacePrefix(): string
68  {
69  return $this->options[‪self::NAMESPACE_PREFIX];
70  }
71 }
‪TYPO3\CMS\Core\Serializer\Typo3XmlParserOptions\ROOT_NODE_NAME
‪const ROOT_NODE_NAME
Definition: Typo3XmlParserOptions.php:29
‪TYPO3\CMS\Core\Serializer\Typo3XmlParserOptions\FORMAT_INLINE
‪const FORMAT_INLINE
Definition: Typo3XmlParserOptions.php:26
‪TYPO3\CMS\Core\Serializer\Typo3XmlParserOptions\getNewlineChar
‪getNewlineChar()
Definition: Typo3XmlParserOptions.php:53
‪TYPO3\CMS\Core\Serializer\Typo3XmlParserOptions\getRootNodeName
‪getRootNodeName()
Definition: Typo3XmlParserOptions.php:48
‪TYPO3\CMS\Core\Serializer\Typo3XmlParserOptions\getIndentationStep
‪getIndentationStep()
Definition: Typo3XmlParserOptions.php:58
‪TYPO3\CMS\Core\Serializer\Typo3XmlParserOptions\$options
‪array $options
Definition: Typo3XmlParserOptions.php:31
‪TYPO3\CMS\Core\Serializer\Typo3XmlParserOptions
Definition: Typo3XmlParserOptions.php:24
‪TYPO3\CMS\Core\Serializer\Typo3XmlParserOptions\FORMAT
‪const FORMAT
Definition: Typo3XmlParserOptions.php:25
‪TYPO3\CMS\Core\Serializer\Typo3XmlParserOptions\FORMAT_PRETTY_WITH_TAB
‪const FORMAT_PRETTY_WITH_TAB
Definition: Typo3XmlParserOptions.php:27
‪TYPO3\CMS\Core\Serializer
‪TYPO3\CMS\Core\Serializer\Typo3XmlParserOptions\getNamespacePrefix
‪getNamespacePrefix()
Definition: Typo3XmlParserOptions.php:67
‪TYPO3\CMS\Core\Serializer\Typo3XmlParserOptions\NAMESPACE_PREFIX
‪const NAMESPACE_PREFIX
Definition: Typo3XmlParserOptions.php:28
‪TYPO3\CMS\Core\Serializer\Typo3XmlParserOptions\__construct
‪__construct(array $options=[])
Definition: Typo3XmlParserOptions.php:43