Skip to content

Commit fdda815

Browse files
committed
Indented EncoderOptions with tabs
1 parent 9faccb2 commit fdda815

File tree

1 file changed

+91
-90
lines changed

1 file changed

+91
-90
lines changed

src/PE/options/EncoderOptions.php

Lines changed: 91 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -10,142 +10,143 @@ class EncoderOptions {
1010

1111
private $cached;
1212

13-
const ROOT = "%%root%%";
13+
const ROOT = "%%root%%";
1414

15-
const CHILDREN_ALL = "all_children";
15+
const CHILDREN_ALL = "all_children";
1616

1717
function __construct($options) {
1818
$this->options = (empty($options) ? array() : $options);
1919
$this->cached = array();
2020
}
2121

22-
protected function resetCache($nodeName = null) {
23-
if ($nodeName === null) {
24-
unset($this->cached[self::ROOT]);
22+
public function getRawOptions() {
23+
return $this->options;
24+
}
25+
26+
public function option($optionName, $node = null) {
27+
$options = null;
28+
if ($node === null || is_string($node)) {
29+
$options = $this->_processOptions($node);
2530
}
2631
else {
27-
$this->cached = array();
32+
$options = $this->processOptionsFromNode($node);
2833
}
34+
return $this->_option($options, $optionName);
2935
}
3036

31-
public function getRawOptions() {
32-
return $this->options;
33-
}
34-
public function getRootOptions() {
35-
return $this->_processOptions(self::ROOT);
36-
}
37-
38-
public function nodeExists($nodeName) {
39-
return $this->rawNodeExists($nodeName) && EncoderNode::nodeExists($nodeName);
40-
}
41-
public function rawNodeExists($nodeName) {
42-
return isset($this->options[$nodeName]) && is_array($this->options[$nodeName]);
43-
}
44-
public function getRawNode($nodeName) {
45-
return $this->options[$nodeName];
46-
}
37+
protected function _option($options, $optionName) {
38+
if (isset($options[$optionName])) {
39+
return $options[$optionName];
40+
}
41+
return null;
42+
}
43+
44+
public function getRootOptions() {
45+
return $this->_processOptions(self::ROOT);
46+
}
47+
48+
public function nodeExists($nodeName) {
49+
return $this->rawNodeExists($nodeName) && EncoderNode::nodeExists($nodeName);
50+
}
51+
public function rawNodeExists($nodeName) {
52+
return isset($this->options[$nodeName]) && is_array($this->options[$nodeName]);
53+
}
54+
public function getRawNode($nodeName) {
55+
return $this->options[$nodeName];
56+
}
4757

4858
public function hasOption($optionName, $nodeName = null) {
4959
return $this->option($optionName, $nodeName) !== null;
5060
}
5161

52-
protected function _decodeNodeName($nodeName) {
53-
$node = array();
62+
protected function _decodeNodeName($nodeName) {
63+
$node = array();
5464

55-
$levels = explode(':', $nodeName);
56-
foreach ($levels as $level) {
57-
$levelArr = array();
65+
$levels = explode(':', $nodeName);
66+
foreach ($levels as $level) {
67+
$levelArr = array();
5868

59-
$match = '/\[([^"])\]+/';
60-
preg_match($match, $level, $id);
61-
if (count($id)) {
62-
$levelArr['nodeId'] = $id[1];
63-
}
64-
$levelArr['node'] = preg_replace($match, '', $level);
69+
$match = '/\[([^"])\]+/';
70+
preg_match($match, $level, $id);
71+
if (count($id)) {
72+
$levelArr['nodeId'] = $id[1];
73+
}
74+
$levelArr['node'] = preg_replace($match, '', $level);
6575

66-
$node[] = $levelArr;
67-
}
68-
return $node;
69-
}
76+
$node[] = $levelArr;
77+
}
78+
return $node;
79+
}
7080

7181
public function setOptions($options, $nodeName = null) {
7282
if ($nodeName === null) {
7383
$this->options = array_merge($this->options, $options);
7484
$this->resetCache();
7585
}
7686
else {
77-
$newOptions = (isset($this->options[$nodeName]) ? array_merge($this->options[$nodeName], $options) : $options);
87+
$newOptions = (isset($this->options[$nodeName]) ? array_merge($this->options[$nodeName], $options) : $options);
7888
$this->options[$nodeName] = $newOptions;
7989
$this->resetCache($nodeName);
8090
}
8191
}
8292

83-
public function option($optionName, $node = null) {
84-
$options = null;
85-
if ($node === null || is_string($node)) {
86-
$options = $this->_processOptions($node);
87-
}
88-
else {
89-
$options = $this->processOptionsFromNode($node);
90-
}
91-
return $this->_option($options, $optionName);
92-
}
93-
94-
protected function _option($options, $optionName) {
95-
if (isset($options[$optionName])) {
96-
return $options[$optionName];
97-
}
98-
return null;
99-
}
100-
10193
public function processOptionsFromNode(EncoderNode $node) {
10294
return array_merge($this->_processOptions($node->getNodeName(), $this->_processOptions($node->getNodeNameSingle())));
10395
}
10496

105-
protected function _processOptions($nodeName = null) {
97+
protected function _processOptions($nodeName = null) {
10698

107-
$nodeName = ($nodeName === null ? self::ROOT : $nodeName);
99+
$nodeName = ($nodeName === null ? self::ROOT : $nodeName);
108100

109-
if (isset($this->cached[$nodeName])) {
110-
return $this->cached[$nodeName];
111-
}
101+
if (isset($this->cached[$nodeName])) {
102+
return $this->cached[$nodeName];
103+
}
112104

113-
$decodedNode = $this->_decodeNodeName($nodeName);
105+
$decodedNode = $this->_decodeNodeName($nodeName);
114106

115-
$lastChild = $decodedNode[count($decodedNode) - 1];
116-
$lastChildNode = $lastChild['node'];
107+
$lastChild = $decodedNode[count($decodedNode) - 1];
108+
$lastChildNode = $lastChild['node'];
117109

118110

119-
$optionPaths = (array(self::ROOT, $lastChildNode, $nodeName));
111+
$optionPaths = (array(self::ROOT, $lastChildNode, $nodeName));
120112

121-
$mergedOptions = array();
122-
foreach ($optionPaths as $optionPath) {
113+
$mergedOptions = array();
114+
foreach ($optionPaths as $optionPath) {
123115

124-
$pathOptions = array();
116+
$pathOptions = array();
125117

126-
if (isset($this->cached[$optionPath])) {
127-
$mergedOptions = array_merge($mergedOptions, $this->cached[$optionPath]);
128-
continue;
129-
}
130-
else {
131-
if ($optionPath == self::ROOT) {
132-
$rootOptions = array();
133-
foreach ($this->getRawOptions() as $key => $value) {
134-
if (!is_array($value)) {
135-
$rootOptions[$key] = $value;
136-
}
137-
}
138-
$pathOptions = $rootOptions;
139-
} else if ($this->rawNodeExists($optionPath)) {
140-
$pathOptions = $this->getRawNode($optionPath);
141-
}
118+
if (isset($this->cached[$optionPath])) {
119+
$mergedOptions = array_merge($mergedOptions, $this->cached[$optionPath]);
120+
continue;
121+
}
122+
else {
123+
if ($optionPath == self::ROOT) {
124+
$rootOptions = array();
125+
foreach ($this->getRawOptions() as $key => $value) {
126+
if (!is_array($value)) {
127+
$rootOptions[$key] = $value;
128+
}
129+
}
130+
$pathOptions = $rootOptions;
131+
} else if ($this->rawNodeExists($optionPath)) {
132+
$pathOptions = $this->getRawNode($optionPath);
133+
}
142134

143-
$mergedOptions = array_merge($mergedOptions, $pathOptions);
135+
$mergedOptions = array_merge($mergedOptions, $pathOptions);
144136

145-
$this->cached[$optionPath] = $mergedOptions;
146-
}
147-
}
137+
$this->cached[$optionPath] = $mergedOptions;
138+
}
139+
}
148140

149-
return $mergedOptions;
150-
}
141+
return $mergedOptions;
142+
}
143+
144+
protected function resetCache($nodeName = null) {
145+
if ($nodeName === null) {
146+
unset($this->cached[self::ROOT]);
147+
}
148+
else {
149+
$this->cached = array();
150+
}
151+
}
151152
}

0 commit comments

Comments
 (0)