Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
PrintNode example
while
(
!
$this
->stream->
isEOF
(
)
)
{
switch
(
$this
->
getCurrentToken
(
)
->
getType
(
)
)
{
case
/* Token::TEXT_TYPE */ 0:
$token
=
$this
->stream->
next
(
)
;
$rv
[
]
=
new
TextNode
(
$token
->
getValue
(
)
,
$token
->
getLine
(
)
)
;
break
;
case
/* Token::VAR_START_TYPE */ 2:
$token
=
$this
->stream->
next
(
)
;
$expr
=
$this
->expressionParser->
parseExpression
(
)
;
$this
->stream->
expect
(
/* Token::VAR_END_TYPE */ 4
)
;
$rv
[
]
=
new
PrintNode
(
$expr
,
$token
->
getLine
(
)
)
;
break
;
case
/* Token::BLOCK_START_TYPE */ 1:
$this
->stream->
next
(
)
;
$token
=
$this
->
getCurrentToken
(
)
;
if
(
/* Token::NAME_TYPE */ 5 !==
$token
->
getType
(
)
)
{
throw
new
SyntaxError
(
'A block must start with a tag name.',
$token
->
getLine
(
)
,
$this
->stream->
getSourceContext
(
)
)
;
}
if
(
null !==
$test
&&
$test
(
$token
)
)
{
$ref
=
new
TempNameExpression
(
$name
,
$lineno
)
;
$ref
->
setAttribute
(
'always_defined', true
)
;
$filter
=
$this
->parser->
getExpressionParser
(
)
->
parseFilterExpressionRaw
(
$ref
,
$this
->
getTag
(
)
)
;
$this
->parser->
getStream
(
)
->
expect
(
Token::BLOCK_END_TYPE
)
;
$body
=
$this
->parser->
subparse
(
[
$this
, 'decideApplyEnd'
]
, true
)
;
$this
->parser->
getStream
(
)
->
expect
(
Token::BLOCK_END_TYPE
)
;
return
new
Node
(
[
new
SetNode
(
true,
$ref
,
$body
,
$lineno
,
$this
->
getTag
(
)
)
,
new
PrintNode
(
$filter
,
$lineno
,
$this
->
getTag
(
)
)
,
]
)
;
}
public
function
decideApplyEnd
(
Token
$token
)
: bool
{
return
$token
->
test
(
'endapply'
)
;
}
public
function
getTag
(
)
: string
{
return
'apply';
}
if
(
$stream
->
nextIf
(
/* Token::BLOCK_END_TYPE */ 3
)
)
{
$body
=
$this
->parser->
subparse
(
[
$this
, 'decideBlockEnd'
]
, true
)
;
if
(
$token
=
$stream
->
nextIf
(
/* Token::NAME_TYPE */ 5
)
)
{
$value
=
$token
->
getValue
(
)
;
if
(
$value
!=
$name
)
{
throw
new
SyntaxError
(
sprintf
(
'Expected endblock for block "%s" (but "%s" given).',
$name
,
$value
)
,
$stream
->
getCurrent
(
)
->
getLine
(
)
,
$stream
->
getSourceContext
(
)
)
;
}
}
}
else
{
$body
=
new
Node
(
[
new
PrintNode
(
$this
->parser->
getExpressionParser
(
)
->
parseExpression
(
)
,
$lineno
)
,
]
)
;
}
$stream
->
expect
(
/* Token::BLOCK_END_TYPE */ 3
)
;
$block
->
setNode
(
'body',
$body
)
;
$this
->parser->
popBlockStack
(
)
;
$this
->parser->
popLocalScope
(
)
;
return
new
BlockReferenceNode
(
$name
,
$lineno
,
$this
->
getTag
(
)
)
;
}
return
$node
;
}
$component
=
$this
->
getComponent
(
$node
)
;
if
(
!
$component
)
{
return
$node
;
}
$line
=
$node
->
getTemplateLine
(
)
;
$print_nodes
=
[
]
;
$component_id
=
$component
->
getPluginId
(
)
;
$emoji
=
static
::
emojiForString
(
$component_id
)
;
if
(
$env
->
isDebug
(
)
)
{
$print_nodes
[
]
=
new
PrintNode
(
new
ConstantExpression
(
sprintf
(
'<!-- %s Component start: %s -->',
$emoji
,
$component_id
)
,
$line
)
,
$line
)
;
}
$print_nodes
[
]
=
new
PrintNode
(
new
FunctionExpression
(
'attach_library',
new
Node
(
[
new
ConstantExpression
(
$component
->
getLibraryName
(
)
,
$line
)
]
)
,
$line
)
,
$line
)
;
$print_nodes
[
]
=
new
PrintNode
(
new
FunctionExpression
(
'sdc_additional_context',
new
Node
(
[
new
ConstantExpression
(
$component_id
,
$line
)
]
)
,
$line
)
,
$line
)
;