1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
engine.php
См. документацию.
1
<?php
7
/*
8
\Bitrix\Main\Loader::includeModule('iblock');
9
10
$arFields = array(
11
"IBLOCK_ID" => 422,
12
"NAME" => "Product name",
13
"CODE" => "main code",
14
"IBLOCK_SECTION_ID" => 12744,
15
"PROPERTY_VALUES" => array(
16
"CML2_ARTICLE" => "XX-SM6-XXXXXXXXX",
17
),
18
);
19
$element = new \Bitrix\Iblock\Template\Entity\Element(0);
20
$element->setFields($arFields);
21
echo "<pre>";//print_r($element);
22
$arSkuCollection = array();
23
for ($i = 0; $i < 5; $i++)
24
{
25
$arSkuCollection[$i] = array(
26
"IBLOCK_ID" => 423,
27
"NAME" => null,
28
"CODE" => "code($i)",
29
"PROPERTY_VALUES" => array(
30
"CML2_LINK" => $element,
31
"1377" => "0x0555555".$i,
32
"1875" => 1045,
33
),
34
);
35
$sku = new \Bitrix\Iblock\Template\Entity\Element(0);
36
$sku->setFields($arSkuCollection[$i]);//print_r($sku);
37
$arSkuCollection[$i]["NAME"] = \Bitrix\Iblock\Template\Engine::process(
38
$sku
39
//,'{=this.property.cml2_link.name}: {=this.property.cml2_link.property.CML2_ARTICUL}, {=this.property.cml2_bar_code}'
40
//,'Q{=this.code}Q'
41
//,'Q{=this.property}Q'
42
,'Q{=this.property.1377}Q{=this.property.1875}Q'
43
//,'Q{=this.property.CML2_LINK}Q'
44
//,'Q{=this.property.CML2_LINK.name}Q'
45
//,'Q{=this.property.CML2_LINK.code}Q'
46
//,'Q{=this.property.CML2_LINK.property.CML2_ARTICLE}Q'
47
//,'Q{=this.property.CML2_LINK.parent.property.str}Q'
48
//,'Q{=this.catalog.price.base}Q'
49
//,'Q{=this.catalog.weight}Q'
50
//,'Q{=this.catalog.measure}Q'
51
//,'Q{=this.catalog.store.1.name}Q'
52
//,'Q{=catalog.store}Q'
53
);
54
}
55
echo "<pre>",htmlspecialcharsEx(print_r($arSkuCollection,1)),"</pre>";
56
*/
57
namespace
Bitrix\Iblock\Template
;
63
class
Engine
64
{
80
public
static
function
process
(
Entity
\Base
$entity
,
$template
)
81
{
82
$rootNode =
self::parseTemplateTree
(
$template
,
new
NodeRoot
);
83
return
$rootNode->process(
$entity
);
84
}
85
94
protected
static
function
parseTemplateTree
(
$template
,
NodeRoot
$parent)
95
{
96
list(
$template
, $modifiers) = Helper::splitTemplate(
$template
);
97
if
($modifiers !=
""
)
98
$parent->
setModifiers
($modifiers);
99
100
$parsedTemplate = preg_split(
'/({=|})/'
,
$template
, -1, PREG_SPLIT_DELIM_CAPTURE);
101
while
(($token = array_shift($parsedTemplate)) !==
null
)
102
{
103
$node =
null
;
104
105
if
($token ===
"{="
)
106
{
107
$node =
self::parseFormula
($parsedTemplate);
108
}
109
elseif
($token !==
""
)
110
{
111
$node =
new
NodeText
($token);
112
}
113
114
if
($node)
115
$parent->
addChild
($node);
116
}
117
return
$parent;
118
}
119
129
protected
static
function
parseFormula
(
array
&$parsedTemplate)
130
{
131
$node =
null
;
132
if
(($token = array_shift($parsedTemplate)) !==
null
)
133
{
134
if
(preg_match(
"/^([a-zA-Z0-9_]+\\.[a-zA-Z0-9_.]+)\\s*\$/"
, $token, $match))
135
{
136
$node =
new
NodeEntityField
($match[1]);
137
}
138
elseif
(preg_match(
"/^([a-zA-Z0-9_]+)(.*)\$/"
, $token, $match))
139
{
140
$node =
new
NodeFunction
($match[1]);
141
self::parseFunctionArguments
($match[2], $parsedTemplate, $node);
142
}
143
}
144
//Eat up to the formula end
145
while
(($token = array_shift($parsedTemplate)) !==
null
)
146
{
147
if
($token ===
"}"
)
148
break
;
149
}
150
return
$node;
151
}
152
165
protected
static
function
parseFunctionArguments
($token,
array
&$parsedTemplate,
NodeFunction
$function)
166
{
167
$token = ltrim($token,
" \t\n\r"
);
168
169
if
($token !==
""
)
170
self::explodeFunctionArgument
($token, $function);
171
172
while
(($token = array_shift($parsedTemplate)) !==
null
)
173
{
174
if
($token ===
"}"
)
175
{
176
array_unshift($parsedTemplate, $token);
177
break
;
178
}
179
elseif
($token ===
"{="
)
180
{
181
$node =
self::parseFormula
($parsedTemplate);
182
if
($node)
183
$function->
addParameter
($node);
184
}
185
elseif
($token !==
""
)
186
{
187
self::explodeFunctionArgument
($token, $function);
188
}
189
}
190
}
191
201
protected
static
function
explodeFunctionArgument
($token,
NodeFunction
$function)
202
{
203
if
(preg_match_all(
"/
204
(
205
[a-zA-Z0-9_]+\\.[a-zA-Z0-9_.]+
206
|[0-9]+
207
|\"[^\"]*\"
208
)
209
/x"
, $token, $wordList)
210
)
211
{
212
foreach
($wordList[0] as $word)
213
{
214
if
($word !==
""
)
215
{
216
if
(preg_match(
"/^([a-zA-Z0-9_]+\\.[a-zA-Z0-9_.]+)\\s*\$/"
, $word, $match))
217
{
218
$node =
new
NodeEntityField
($match[1]);
219
}
220
else
221
{
222
$node =
new
NodeText
(trim($word,
'"'
));
223
}
224
$function->
addParameter
($node);
225
}
226
}
227
}
228
}
229
}
230
236
abstract
class
NodeBase
237
{
246
abstract
public
function
process
(
Entity
\Base
$entity
);
247
}
248
255
class
NodeRoot
extends
NodeBase
256
{
258
protected
$children
=
array
();
259
protected
$modifiers
=
array
();
260
268
public
function
addChild
(
NodeBase
$child)
269
{
270
$this->children[] = $child;
271
}
272
280
public
function
setModifiers
(
$modifiers
)
281
{
282
$this->modifiers =
array
();
283
foreach
(Helper::splitModifiers(
$modifiers
) as
$mod
)
284
{
285
if
(
$mod
==
"l"
)
286
$modifierFunction = Functions\Fabric::createInstance(
"lower"
);
287
else
288
$modifierFunction = Functions\Fabric::createInstance(
"translit"
,
array
(
289
"replace_space"
=> mb_substr(
$mod
, 1),
290
));
291
$this->modifiers[] = $modifierFunction;
292
}
293
}
294
303
public
function
process
(
Entity
\Base
$entity
)
304
{
305
$content
=
""
;
307
foreach
($this->children as $child)
308
{
309
$childContent = $child->process(
$entity
);
310
if
(is_array($childContent))
311
$content
.= implode(
" "
, $childContent);
312
else
313
$content
.= $childContent;
314
}
316
foreach
($this->modifiers as $modifier)
317
{
318
$node =
new
NodeText(
$content
);
319
$arguments = $modifier->onPrepareParameters(
$entity
,
array
($node));
320
$content
= $modifier->calculate($arguments);
321
}
322
return
$content
;
323
}
324
}
325
332
class
NodeText
extends
NodeBase
333
{
334
protected
$content
=
""
;
335
341
function
__construct
(
$content
=
""
)
342
{
343
$this->content =
$content
;
344
}
345
353
public
function
process
(
Entity
\Base
$entity
)
354
{
355
return
$this->content
;
356
}
357
}
358
366
class
NodeEntityField
extends
NodeBase
367
{
368
protected
$entityField
=
""
;
369
376
function
__construct
(
$entityField
=
""
)
377
{
378
$this->entityField = mb_strtolower(
$entityField
);
379
}
380
390
public
function
process
(
Entity
\Base
$entity
)
391
{
392
$entityObject =
$entity
;
393
$pathToField = explode(
"."
, $this->entityField);
394
for
(
$i
= 0, $c =
count
($pathToField)-1;
$i
< $c;
$i
++)
395
{
396
$entityObject = $entityObject->resolve($pathToField[
$i
]);
397
}
398
if
($entityObject)
399
return
$entityObject->getField($pathToField[$c]);
400
else
401
return
""
;
402
}
403
}
404
411
class
NodeFunction
extends
NodeBase
412
{
413
protected
$functionName
=
""
;
414
protected
$parameters
=
array
();
415
421
public
function
__construct
(
$functionName
=
""
)
422
{
423
$this->functionName = mb_strtolower(
$functionName
);
424
}
425
433
public
function
addParameter
(
NodeBase
$parameter)
434
{
435
$this->parameters[] = $parameter;
436
}
437
447
public
function
process
(
Entity
\Base
$entity
)
448
{
449
$functionObject = Functions\Fabric::createInstance($this->functionName);
450
if
($functionObject instanceof
Functions
\FunctionBase)
451
{
452
$arguments = $functionObject->onPrepareParameters(
$entity
, $this->parameters);
453
return
$functionObject->calculate($arguments);
454
}
455
else
456
{
457
return
""
;
458
}
459
}
460
}
Bitrix\Iblock\Template\Engine
Определения
engine.php:64
Bitrix\Iblock\Template\Engine\explodeFunctionArgument
static explodeFunctionArgument($token, NodeFunction $function)
Определения
engine.php:201
Bitrix\Iblock\Template\Engine\parseFormula
static parseFormula(array &$parsedTemplate)
Определения
engine.php:129
Bitrix\Iblock\Template\Engine\parseFunctionArguments
static parseFunctionArguments($token, array &$parsedTemplate, NodeFunction $function)
Определения
engine.php:165
Bitrix\Iblock\Template\Engine\process
static process(Entity\Base $entity, $template)
Определения
engine.php:80
Bitrix\Iblock\Template\Engine\parseTemplateTree
static parseTemplateTree($template, NodeRoot $parent)
Определения
engine.php:94
Bitrix\Iblock\Template\NodeBase
Определения
engine.php:237
Bitrix\Iblock\Template\NodeBase\process
process(Entity\Base $entity)
Bitrix\Iblock\Template\NodeEntityField
Определения
engine.php:367
Bitrix\Iblock\Template\NodeEntityField\$entityField
$entityField
Определения
engine.php:368
Bitrix\Iblock\Template\NodeEntityField\process
process(Entity\Base $entity)
Определения
engine.php:390
Bitrix\Iblock\Template\NodeEntityField\__construct
__construct($entityField="")
Определения
engine.php:376
Bitrix\Iblock\Template\NodeFunction
Определения
engine.php:412
Bitrix\Iblock\Template\NodeFunction\addParameter
addParameter(NodeBase $parameter)
Определения
engine.php:433
Bitrix\Iblock\Template\NodeFunction\process
process(Entity\Base $entity)
Определения
engine.php:447
Bitrix\Iblock\Template\NodeFunction\__construct
__construct($functionName="")
Определения
engine.php:421
Bitrix\Iblock\Template\NodeFunction\$parameters
$parameters
Определения
engine.php:414
Bitrix\Iblock\Template\NodeFunction\$functionName
$functionName
Определения
engine.php:413
Bitrix\Iblock\Template\NodeRoot
Определения
engine.php:256
Bitrix\Iblock\Template\NodeRoot\$modifiers
$modifiers
Определения
engine.php:259
Bitrix\Iblock\Template\NodeRoot\setModifiers
setModifiers($modifiers)
Определения
engine.php:280
Bitrix\Iblock\Template\NodeRoot\addChild
addChild(NodeBase $child)
Определения
engine.php:268
Bitrix\Iblock\Template\NodeRoot\$children
$children
Определения
engine.php:258
Bitrix\Iblock\Template\NodeText
Определения
engine.php:333
Bitrix\Iblock\Template\NodeText\process
process(Entity\Base $entity)
Определения
engine.php:353
Bitrix\Iblock\Template\NodeText\$content
$content
Определения
engine.php:334
Bitrix\Iblock\Template\NodeText\__construct
__construct($content="")
Определения
engine.php:341
$mod
if($childrenCount<=0) $mod
Определения
sync.php:11
$content
$content
Определения
commerceml.php:144
$template
$template
Определения
file_edit.php:49
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$entity
$entity
Определения
group_bizproc_workflow_delete.php:17
Bitrix\Iblock\Template\Entity
Определения
base.php:7
Bitrix\Iblock\Template\Functions
Определения
fabric.php:7
Bitrix\Iblock\Template
Определения
engine.php:57
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$i
$i
Определения
factura.php:643
count
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения
waybill.php:936
bitrix
modules
iblock
lib
template
engine.php
Создано системой
1.14.0