Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eztemplateexecuteoperator.php
Go to the documentation of this file.
1 <?php
17 class eZTemplateExecuteOperator
18 {
25 public function __construct( $fetchName = 'fetch', $fetchAliasName = 'fetch_alias' )
26 {
27 $this->Operators = array( $fetchName, $fetchAliasName );
28 $this->Fetch = $fetchName;
29 $this->FetchAlias = $fetchAliasName;
30 }
31
35 function operatorList()
36 {
37 return $this->Operators;
38 }
39
43 function namedParameterPerOperator()
44 {
45 return true;
46 }
47
48 function operatorTemplateHints()
49 {
50 return array( $this->Fetch => array( 'input' => false,
51 'output' => true,
52 'parameters' => true,
53 'element-transformation' => true,
54 'transform-parameters' => true,
55 'element-transformation-func' => 'fetchTransform' ),
56 $this->FetchAlias => array( 'input' => false,
57 'output' => true,
58 'parameters' => true,
59 'element-transformation' => true,
60 'transform-parameters' => true,
61 'element-transformation-func' => 'fetchTransform' )
62 );
63 }
64
65 function fetchTransform( $operatorName, &$node, $tpl, &$resourceData,
66 $element, $lastElement, $elementList, $elementTree, &$parameters )
67 {
68 $parameterTranslation = false;
69 $constParameters = array();
70
71 if ( $operatorName == $this->Fetch )
72 {
73 if ( !eZTemplateNodeTool::isConstantElement( $parameters[0] ) ||
74 !eZTemplateNodeTool::isConstantElement( $parameters[1] ) )
75 {
76 return false;
77 }
78
79 $moduleName = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
80 $functionName = eZTemplateNodeTool::elementConstantValue( $parameters[1] );
81
82 $moduleFunctionInfo = eZFunctionHandler::moduleFunctionInfo( $moduleName );
83 if ( !$moduleFunctionInfo->isValid() )
84 {
85 eZDebug::writeError( "Cannot execute module '$moduleName', no module found", __METHOD__ );
86 return array();
87 }
88 $fetchParameters = array();
89 if ( isset( $parameters[2] ) )
90 $fetchParameters = $parameters[2];
91 }
92 else if ( $operatorName == $this->FetchAlias )
93 {
94 if ( !eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
95 {
96 return false;
97 }
98
99 $aliasFunctionName = eZTemplateNodeTool::elementConstantValue( $parameters[0] );
100
101 $aliasSettings = eZINI::instance( 'fetchalias.ini' );
102 if ( $aliasSettings->hasSection( $aliasFunctionName ) )
103 {
104 $moduleFunctionInfo = eZFunctionHandler::moduleFunctionInfo( $aliasSettings->variable( $aliasFunctionName, 'Module' ) );
105 if ( !$moduleFunctionInfo->isValid() )
106 {
107 eZDebug::writeError( "Cannot execute function '$aliasFunctionName' in module '$moduleName', no valid data", __METHOD__ );
108 return array();
109 }
110
111 $functionName = $aliasSettings->variable( $aliasFunctionName, 'FunctionName' );
112
113 $functionArray = array();
114 if ( $aliasSettings->hasVariable( $aliasFunctionName, 'Parameter' ) )
115 {
116 $parameterTranslation = $aliasSettings->variable( $aliasFunctionName, 'Parameter' );
117 }
118
119 if ( $aliasSettings->hasVariable( $aliasFunctionName, 'Constant' ) )
120 {
121 $constantParameterArray = $aliasSettings->variable( $aliasFunctionName, 'Constant' );
122 if ( is_array( $constantParameterArray ) )
123 {
124 foreach ( array_keys( $constantParameterArray ) as $constKey )
125 {
126 if ( $moduleFunctionInfo->isParameterArray( $functionName, $constKey ) )
127 $constParameters[$constKey] = explode( ';', $constantParameterArray[$constKey] );
128 else
129 $constParameters[$constKey] = $constantParameterArray[$constKey];
130 }
131 }
132 }
133 }
134 else
135 {
136 $placement = eZTemplateNodeTool::extractFunctionNodePlacement( $node );
137 $tpl->warning( 'fetch_alias', "Fetch alias '$aliasFunctionName' is not defined in fetchalias.ini", $placement );
138 return array();
139 }
140
141 $fetchParameters = array();
142 if ( isset( $parameters[1] ) )
143 $fetchParameters = $parameters[1];
144 }
145 else
146 {
147 return false;
148 }
149
150 $functionDefinition = $moduleFunctionInfo->preExecute( $functionName );
151 if ( $functionDefinition === false )
152 {
153 return false;
154 }
155
156 $isDynamic = false;
157 $isVariable = false;
158 if ( eZTemplateNodeTool::isConstantElement( $fetchParameters ) )
159 {
160 $staticParameters = eZTemplateNodeTool::elementConstantValue( $fetchParameters );
161 $functionKeys = array_keys( $staticParameters );
162 }
163 else if ( eZTemplateNodeTool::isDynamicArrayElement( $fetchParameters ) )
164 {
165 $isDynamic = true;
166 $dynamicParameters = eZTemplateNodeTool::elementDynamicArray( $fetchParameters );
167 $functionKeys = eZTemplateNodeTool::elementDynamicArrayKeys( $fetchParameters );
168 }
169 else if ( eZTemplateNodeTool::isVariableElement( $fetchParameters ) or
170 eZTemplateNodeTool::isInternalCodePiece( $fetchParameters ) )
171 {
172 $isVariable = true;
173 }
174 else
175 {
176 $functionKeys = array();
177 }
178
179 $paramCount = 0;
180 $values = array();
181 if ( $isVariable )
182 {
183 $values[] = $fetchParameters;
184
185 $parametersCode = 'array( ';
186 foreach( $functionDefinition['parameters'] as $parameterDefinition )
187 {
188 if ( $paramCount != 0 )
189 {
190 $parametersCode .= ',' . "\n";
191 }
192 ++$paramCount;
193
194 $parameterName = $parameterDefinition['name'];
195
196 if ( $parameterTranslation )
197 {
198 if ( in_array( $parameterName, array_keys( $parameterTranslation ) ) )
199 {
200 $parameterName = $parameterTranslation[$parameterName];
201 }
202 }
203
204 $defaultValue = 'null';
205 if ( !$parameterDefinition['required'] )
206 $defaultValue = eZPHPCreator::variableText( $parameterDefinition['default'], 0, 0, false );
207
208 $parametersSelection = '%1%[\'' . $parameterName . '\']';
209 $parametersCode .= '( isset( ' . $parametersSelection . ' ) ? ' . $parametersSelection . " : $defaultValue )";
210 }
211
212 $parametersCode .= ' )';
213
214 }
215 else
216 {
217 $parametersCode = 'array( ';
218 if ( count( $functionDefinition['parameters'] ) )
219 {
220 foreach( $functionDefinition['parameters'] as $parameterDefinition )
221 {
222 if ( $paramCount != 0 )
223 {
224 $parametersCode .= ',' . "\n";
225 }
226 ++$paramCount;
227
228 $parameterName = $parameterDefinition['name'];
229
230 if ( $parameterTranslation )
231 {
232 if ( in_array( $parameterName, array_keys( $parameterTranslation ) ) )
233 {
234 $parameterName = $parameterTranslation[$parameterName];
235 }
236 }
237
238 $parametersCode .= ' \'' . $parameterName . '\' => ';
239
240 if ( in_array( $parameterName, $functionKeys ) )
241 {
242 if ( $isDynamic )
243 {
244 if ( eZTemplateNodeTool::isConstantElement( $dynamicParameters[$parameterName] ) )
245 {
246 $parametersCode .= eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $dynamicParameters[$parameterName] ), 0, 0, false );
247 }
248 else
249 {
250 $values[] = $dynamicParameters[$parameterName];
251 $parametersCode .= '%' . count( $values ) . '%';
252 }
253 }
254 else
255 {
256 $parametersCode .= eZPHPCreator::variableText( $staticParameters[$parameterName], 0, 0, false );
257 }
258 }
259 else if( $constParameters &&
260 isset( $constParameters[$parameterName] ) )
261 {
262 $parametersCode .= eZPHPCreator::variableText( $constParameters[$parameterName], 0, 0, false );
263 }
264 else
265 {
266 if ( $parameterDefinition['required'] )
267 {
268 return false;
269 }
270 else if ( isset( $parameterDefinition['default'] ) )
271 {
272 $parametersCode .= eZPHPCreator::variableText( $parameterDefinition['default'], 0, 0, false );
273 }
274 else
275 {
276 $parametersCode .= 'null';
277 }
278 }
279 }
280 }
281
282 $parametersCode .= ' )';
283 }
284
285 $code = '%output% = call_user_func_array( array( new ' . $functionDefinition['call_method']['class'] . '(), \'' . $functionDefinition['call_method']['method'] . '\' ),' . "\n" .
286 ' array_values( ' . $parametersCode . ' ) );';
287 $code .= "\n";
288
289 $code .= '%output% = isset( %output%[\'result\'] ) ? %output%[\'result\'] : null;' . "\n";
290
291 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) );
292 }
293
297 function namedParameterList()
298 {
299 return array( 'fetch' => array( 'module_name' => array( 'type' => 'string',
300 'required' => true,
301 'default' => false ),
302 'function_name' => array( 'type' => 'string',
303 'required' => true,
304 'default' => false ),
305 'function_parameters' => array( 'type' => 'array',
306 'required' => false,
307 'default' => array() ) ),
308 'fetch_alias' => array( 'function_name' => array( 'type' => 'string',
309 'required' => true,
310 'default' => false ),
311 'function_parameters' => array( 'type' => 'array',
312 'required' => false,
313 'default' => array() ) ) );
314 }
315
319 function modify( $tpl, $operatorName, $operatorParameters,
320 $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement )
321 {
322 $functionName = $namedParameters['function_name'];
323 $functionParameters = $namedParameters['function_parameters'];
324
325 if ( $operatorName == $this->Fetch )
326 {
327 $moduleName = $namedParameters['module_name'];
328 $result = eZFunctionHandler::execute( $moduleName, $functionName, $functionParameters );
329 $operatorValue = $result;
330 }
331 else if ( $operatorName == $this->FetchAlias )
332 {
333 $result = eZFunctionHandler::executeAlias( $functionName, $functionParameters );
334 $operatorValue = $result;
335 }
336 }
337
339 public $Operators;
340
341 public $Fetch;
342 public $FetchAlias;
343 }
344
345 ?>
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZFunctionHandler\executeAlias
static executeAlias( $aliasFunctionName, $functionParameters)
Definition: ezfunctionhandler.php:39
eZFunctionHandler\execute
static execute( $moduleName, $functionName, $functionParameters)
Definition: ezfunctionhandler.php:137
eZFunctionHandler\moduleFunctionInfo
static moduleFunctionInfo( $moduleName)
Definition: ezfunctionhandler.php:19
eZTemplateExecuteOperator
The class eZTemplateExecuteOperator does.
Definition: eztemplateexecuteoperator.php:18
eZTemplateExecuteOperator\__construct
__construct( $fetchName='fetch', $fetchAliasName='fetch_alias')
Definition: eztemplateexecuteoperator.php:25
eZTemplateExecuteOperator\fetchTransform
fetchTransform( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: eztemplateexecuteoperator.php:65
eZTemplateExecuteOperator\$Fetch
$Fetch
Definition: eztemplateexecuteoperator.php:341
eZTemplateExecuteOperator\namedParameterPerOperator
namedParameterPerOperator()
Definition: eztemplateexecuteoperator.php:43
eZTemplateExecuteOperator\$Operators
$Operators
Definition: eztemplateexecuteoperator.php:339
eZTemplateExecuteOperator\operatorTemplateHints
operatorTemplateHints()
Definition: eztemplateexecuteoperator.php:48
eZTemplateExecuteOperator\modify
modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement)
Definition: eztemplateexecuteoperator.php:319
eZTemplateExecuteOperator\$FetchAlias
$FetchAlias
Definition: eztemplateexecuteoperator.php:342
eZTemplateExecuteOperator\operatorList
operatorList()
Definition: eztemplateexecuteoperator.php:35
eZTemplateExecuteOperator\namedParameterList
namedParameterList()
Definition: eztemplateexecuteoperator.php:297
eZTemplateNodeTool\isVariableElement
static isVariableElement( $elements)
Definition: eztemplatenodetool.php:265
eZTemplateNodeTool\elementConstantValue
static elementConstantValue( $elements)
Definition: eztemplatenodetool.php:197
eZTemplateNodeTool\isDynamicArrayElement
static isDynamicArrayElement( $elements)
Definition: eztemplatenodetool.php:361
eZTemplateNodeTool\createCodePieceElement
static createCodePieceElement( $codePiece, $values=false, $placement=false, $tmpValues=false, $knownTypes=true)
Definition: eztemplatenodetool.php:437
eZTemplateNodeTool\elementDynamicArrayKeys
static elementDynamicArrayKeys( $elements)
Definition: eztemplatenodetool.php:208
eZTemplateNodeTool\elementDynamicArray
static elementDynamicArray( $elements)
Definition: eztemplatenodetool.php:218
eZTemplateNodeTool\extractFunctionNodePlacement
static extractFunctionNodePlacement(&$node)
Definition: eztemplatenodetool.php:660
eZTemplateNodeTool\isInternalCodePiece
static isInternalCodePiece( $elements)
Definition: eztemplatenodetool.php:257
eZTemplateNodeTool\isConstantElement
static isConstantElement( $elements)
Definition: eztemplatenodetool.php:233
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.