Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eztemplateoptimizer.php
Go to the documentation of this file.
1 <?php
17 class eZTemplateOptimizer
18 {
22 static function optimizeResourceAcquisition( $useComments, &$php, $tpl, &$var, &$node, &$resourceData )
23 {
24 $data = $var[2];
25 /* Check if the variable node has the correct format */
26 if ( ( $var[1] == 'attributeAccess' ) and
27 ( count( $data ) == 5 ) and
28 ( $data[0][0] == eZTemplate::TYPE_VARIABLE ) and
29 ( $data[0][1][2] == 'node' ) and
30 ( $data[1][0] == eZTemplate::TYPE_ATTRIBUTE ) and
31 ( $data[1][1][0][1] == 'object' ) and
32 ( $data[2][0] == eZTemplate::TYPE_ATTRIBUTE ) and
33 ( $data[2][1][0][1] == 'data_map' ) and
34 ( $data[3][0] == eZTemplate::TYPE_ATTRIBUTE ) and
35 ( $data[4][0] == eZTemplate::TYPE_ATTRIBUTE ) and
36 ( $data[4][1][0][1] == 'view_template' ) and
37 ( $node[9] == 'attributeAccess' ) and
38 ( isset( $resourceData['class-info'] ) ) )
39 {
40 $attribute = $data[3][1][0][1];
41 if ( isset( $resourceData['class-info'][$attribute] ) and
42 isset( $node[2][$resourceData['class-info'][$attribute]] ) )
43 {
44 $file = $node[2][$resourceData['class-info'][$attribute]];
45 $node[0] = eZTemplate::NODE_OPTIMIZED_RESOURCE_ACQUISITION;
46 $node[10] = $resourceData['class-info'][$attribute];
47 $node[2] = array( $node[10] => $file );
48
49 return true;
50 }
51 else /* If we can't find it in the lookup table then it's simply
52 * not there, so we can just kill the array. */
53 {
54 $node[2] = array( 'dummy' => 'foo' );
55 return false;
56 }
57 /* Added as an extra fall back, this point should never be reached,
58 * but if it does then we make sure not to mess up the original
59 * array in the calling function. */
60 return false;
61 }
62 else
63 {
64 return false;
65 }
66 }
67
71 static function optimizeFunction( $useComments, &$php, $tpl, &$node, &$resourceData )
72 {
73 $ret = 0;
74 /* Just run the optimizer over all parameters */
75 if ( isset( $node[3] ) and is_array( $node[3] ) )
76 {
77 foreach ( $node[3] as $key => $parameter )
78 {
79 $ret = $ret | eZTemplateOptimizer::optimizeVariable( $useComments, $php, $tpl, $node[3][$key], $resourceData );
80 }
81 }
82 return $ret;
83 }
84
88 static function optimizeVariable( $useComments, &$php, $tpl, &$data, &$resourceData )
89 {
90 $ret = 0;
91 if( !is_array( $data ) )
92 {
93 $data = array();
94 }
95 /* node.object.data_map optimization */
96 if ( is_countable( $data ) and ( count( $data ) >= 3 ) and
97 ( $data[0][0] == eZTemplate::TYPE_VARIABLE ) and
98 ( $data[0][1][2] == 'node' ) and
99 ( $data[1][0] == eZTemplate::TYPE_ATTRIBUTE ) and
100 ( $data[1][1][0][1] == 'object' ) and
101 ( $data[2][0] == eZTemplate::TYPE_ATTRIBUTE ) and
102 ( $data[2][1][0][1] == 'data_map' ) )
103 {
104 /* Modify the next two nodes in the array too as we know for sure
105 * what type it is. This fixes the dependency on
106 * compiledFetchAttribute */
107 if ( ( count( $data ) >= 5 ) and
108 ( $data[3][0] == eZTemplate::TYPE_ATTRIBUTE ) and
109 ( $data[4][0] == eZTemplate::TYPE_ATTRIBUTE ) )
110 {
111 $data[3][0] = eZTemplate::TYPE_OPTIMIZED_ARRAY_LOOKUP;
112 if ( $data[4][1][0][1] == "content")
113 {
114 $data[4][0] = eZTemplate::TYPE_OPTIMIZED_CONTENT_CALL;
115 }
116 else
117 {
118 $data[4][0] = eZTemplate::TYPE_OPTIMIZED_ATTRIBUTE_LOOKUP;
119 }
120 }
121
122 /* Create a new node representing the optimization */
123 array_unshift( $data, array( eZTemplate::TYPE_OPTIMIZED_NODE, null, 2 ) );
124 $ret = 1;
125 }
126
127 /* node.object.data_map optimization through function */
128 if ( isset( $data[0] ) and
129 $data[0][0] == eZTemplate::NODE_INTERNAL_CODE_PIECE )
130 {
131 $functionRet = eZTemplateOptimizer::optimizeFunction( $useComments, $php, $tpl, $data[0], $resourceData );
132 // Merge settings
133 $ret = $ret | $functionRet;
134 }
135 return $ret;
136 }
137
141 static function optimize( $useComments, &$php, $tpl, &$tree, &$resourceData )
142 {
143 /* If for some reason we don't have elements, simply return */
144 if (! is_array( $tree[1] ) )
145 return;
146
147 $addNodeInit = false;
148
149 /* Loop through the children of the root */
150 foreach ( $tree[1] as $key => $kiddie )
151 {
152 /* Analyse per node type */
153 switch ( $kiddie[0] )
154 {
155 case eZTemplate::NODE_INTERNAL_OUTPUT_SPACING_INCREASE:
156 case eZTemplate::NODE_INTERNAL_SPACING_DECREASE:
157 /* Removing unnecessary whitespace changes */
158 unset( $tree[1][$key] );
159 break;
160 case 3: /* Variable */
161 if ( isset( $tree[1][$key + 1] ) and
162 ( $tree[1][$key + 1][0] == eZTemplate::NODE_INTERNAL_RESOURCE_ACQUISITION ) and
163 isset( $resourceData['class-info'] ) )
164 {
165 $ret = eZTemplateOptimizer::optimizeResourceAcquisition(
166 $useComments, $php, $tpl,
167 $tree[1][$key], $tree[1][$key + 1], $resourceData );
168 /* We only unset the tree node when the optimization
169 * function returns false, as that means that the
170 * optimization could not be made. */
171 if ($ret)
172 {
173 unset( $tree[1][$key] );
174 }
175 }
176 else
177 {
178 $ret = eZTemplateOptimizer::optimizeVariable( $useComments, $php, $tpl, $tree[1][$key][2], $resourceData );
179 if ( $ret & 1 )
180 $addNodeInit = true;
181 }
182 break;
183 }
184 }
185 if ( $addNodeInit )
186 {
187 $initializer = array( eZTemplate::NODE_OPTIMIZED_INIT, null, false );
188 array_unshift( $tree[1], $initializer );
189 }
190 }
191
192 static function fetchClassDeclaration( $classID )
193 {
194 $contentClass = eZContentClass::fetch( $classID );
195 $attributeArray = array();
196 $attributes = is_object( $contentClass ) ? $contentClass->fetchAttributes() : array();
197 foreach ( $attributes as $attribute )
198 {
199 $attributeArray[ $attribute->Identifier ] = $attribute->DataTypeString;
200 }
201 return $attributeArray;
202 }
203 }
204 ?>
eZContentClass\fetch
static fetch( $id, $asObject=true, $version=eZContentClass::VERSION_STATUS_DEFINED, $user_id=false, $parent_id=null)
Definition: ezcontentclass.php:1116
eZTemplateOptimizer
Analyses a compiled template tree and tries to optimize certain parts of it.
Definition: eztemplateoptimizer.php:18
eZTemplateOptimizer\optimize
static optimize( $useComments, &$php, $tpl, &$tree, &$resourceData)
Definition: eztemplateoptimizer.php:141
eZTemplateOptimizer\optimizeVariable
static optimizeVariable( $useComments, &$php, $tpl, &$data, &$resourceData)
Definition: eztemplateoptimizer.php:88
eZTemplateOptimizer\optimizeResourceAcquisition
static optimizeResourceAcquisition( $useComments, &$php, $tpl, &$var, &$node, &$resourceData)
Definition: eztemplateoptimizer.php:22
eZTemplateOptimizer\optimizeFunction
static optimizeFunction( $useComments, &$php, $tpl, &$node, &$resourceData)
Definition: eztemplateoptimizer.php:71
eZTemplateOptimizer\fetchClassDeclaration
static fetchClassDeclaration( $classID)
Definition: eztemplateoptimizer.php:192
eZTemplate\NODE_INTERNAL_RESOURCE_ACQUISITION
const NODE_INTERNAL_RESOURCE_ACQUISITION
Definition: eztemplate.php:229
eZTemplate\TYPE_VARIABLE
const TYPE_VARIABLE
Definition: eztemplate.php:250
eZTemplate\NODE_INTERNAL_SPACING_DECREASE
const NODE_INTERNAL_SPACING_DECREASE
Definition: eztemplate.php:238
eZTemplate\NODE_INTERNAL_CODE_PIECE
const NODE_INTERNAL_CODE_PIECE
Definition: eztemplate.php:218
eZTemplate\TYPE_OPTIMIZED_ARRAY_LOOKUP
const TYPE_OPTIMIZED_ARRAY_LOOKUP
Definition: eztemplate.php:262
eZTemplate\TYPE_OPTIMIZED_CONTENT_CALL
const TYPE_OPTIMIZED_CONTENT_CALL
Definition: eztemplate.php:263
eZTemplate\NODE_OPTIMIZED_INIT
const NODE_OPTIMIZED_INIT
Definition: eztemplate.php:240
eZTemplate\NODE_OPTIMIZED_RESOURCE_ACQUISITION
const NODE_OPTIMIZED_RESOURCE_ACQUISITION
Definition: eztemplate.php:230
eZTemplate\TYPE_OPTIMIZED_NODE
const TYPE_OPTIMIZED_NODE
Definition: eztemplate.php:261
eZTemplate\TYPE_ATTRIBUTE
const TYPE_ATTRIBUTE
Definition: eztemplate.php:251
eZTemplate\NODE_INTERNAL_OUTPUT_SPACING_INCREASE
const NODE_INTERNAL_OUTPUT_SPACING_INCREASE
Definition: eztemplate.php:237
eZTemplate\TYPE_OPTIMIZED_ATTRIBUTE_LOOKUP
const TYPE_OPTIMIZED_ATTRIBUTE_LOOKUP
Definition: eztemplate.php:264
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.