@@ 119-163 (lines=45) @@ | ||
116 | * |
|
117 | * @todo same as OrRule |
|
118 | */ |
|
119 | public function toArray(array $options=[]) |
|
120 | { |
|
121 | $default_options = [ |
|
122 | 'show_instance' => false, |
|
123 | 'sort_operands' => false, |
|
124 | 'semantic' => false, |
|
125 | ]; |
|
126 | foreach ($default_options as $default_option => &$default_value) { |
|
127 | if ( ! isset($options[ $default_option ])) { |
|
128 | $options[ $default_option ] = $default_value; |
|
129 | } |
|
130 | } |
|
131 | ||
132 | if ( ! $options['show_instance'] && ! empty($this->cache['array'])) { |
|
133 | return $this->cache['array']; |
|
134 | } |
|
135 | ||
136 | $operands_as_array = [ |
|
137 | $options['show_instance'] ? $this->getInstanceId() : self::operator, |
|
138 | ]; |
|
139 | ||
140 | $operands = $this->operands; |
|
141 | if ($options['semantic']) { |
|
142 | // Semantic array: ['operator', 'semantic_id_of_operand1', 'semantic_id_of_operand2', ...] |
|
143 | // with sorted semantic ids |
|
144 | $operands_semantic_ids = array_keys($operands); |
|
145 | sort($operands_semantic_ids); |
|
146 | return array_merge( |
|
147 | [self::operator], |
|
148 | $operands_semantic_ids |
|
149 | ); |
|
150 | } |
|
151 | else { |
|
152 | foreach ($operands as $operand) { |
|
153 | $operands_as_array[] = $operand->toArray($options); |
|
154 | } |
|
155 | ||
156 | if ( ! $options['show_instance']) { |
|
157 | return $this->cache['array'] = $operands_as_array; |
|
158 | } |
|
159 | else { |
|
160 | return $operands_as_array; |
|
161 | } |
|
162 | } |
|
163 | } |
|
164 | ||
165 | /** |
|
166 | */ |
@@ 83-127 (lines=45) @@ | ||
80 | * |
|
81 | * @return array |
|
82 | */ |
|
83 | public function toArray(array $options=[]) |
|
84 | { |
|
85 | $default_options = [ |
|
86 | 'show_instance' => false, |
|
87 | 'sort_operands' => false, |
|
88 | 'semantic' => false, |
|
89 | ]; |
|
90 | foreach ($default_options as $default_option => &$default_value) { |
|
91 | if ( ! isset($options[ $default_option ])) { |
|
92 | $options[ $default_option ] = $default_value; |
|
93 | } |
|
94 | } |
|
95 | ||
96 | if ( ! $options['show_instance'] && ! empty($this->cache['array'])) { |
|
97 | return $this->cache['array']; |
|
98 | } |
|
99 | ||
100 | $operands_as_array = [ |
|
101 | $options['show_instance'] ? $this->getInstanceId() : self::operator, |
|
102 | ]; |
|
103 | ||
104 | $operands = $this->operands; |
|
105 | if ($options['semantic']) { |
|
106 | // Semantic array: ['operator', 'semantic_id_of_operand1', 'semantic_id_of_operand2', ...] |
|
107 | // with sorted semantic ids |
|
108 | $operands_semantic_ids = array_keys($operands); |
|
109 | sort($operands_semantic_ids); |
|
110 | return array_merge( |
|
111 | [self::operator], |
|
112 | $operands_semantic_ids |
|
113 | ); |
|
114 | } |
|
115 | else { |
|
116 | foreach ($operands as $operand) { |
|
117 | $operands_as_array[] = $operand->toArray($options); |
|
118 | } |
|
119 | ||
120 | if ( ! $options['show_instance']) { |
|
121 | return $this->cache['array'] = $operands_as_array; |
|
122 | } |
|
123 | else { |
|
124 | return $operands_as_array; |
|
125 | } |
|
126 | } |
|
127 | } |
|
128 | ||
129 | /** |
|
130 | */ |