当前位置: 首页>>代码示例>>PHP>>正文


PHP eZTemplateCompiler::generateVariableDataCode方法代码示例

本文整理汇总了PHP中eZTemplateCompiler::generateVariableDataCode方法的典型用法代码示例。如果您正苦于以下问题:PHP eZTemplateCompiler::generateVariableDataCode方法的具体用法?PHP eZTemplateCompiler::generateVariableDataCode怎么用?PHP eZTemplateCompiler::generateVariableDataCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eZTemplateCompiler的用法示例。


在下文中一共展示了eZTemplateCompiler::generateVariableDataCode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generateVariableDataCode

    static function generateVariableDataCode($php, $tpl, $variableData, &$knownTypes, $dataInspection, &$persistence, $parameters, &$resourceData)
    {
        $staticTypeMap = array(eZTemplate::TYPE_STRING => 'string', eZTemplate::TYPE_NUMERIC => 'numeric', eZTemplate::TYPE_IDENTIFIER => 'string', eZTemplate::TYPE_ARRAY => 'array', eZTemplate::TYPE_BOOLEAN => 'boolean');
        $variableAssignmentName = $parameters['variable'];
        $variableAssignmentCounter = $parameters['counter'];
        $spacing = 0;
        $optimizeNode = false;
        if (isset($parameters['spacing'])) {
            $spacing = $parameters['spacing'];
        }
        if ($variableAssignmentCounter > 0) {
            $variableAssignmentName .= $variableAssignmentCounter;
        }
        // We need to unset the assignment variable before any elements are processed
        // This ensures that we don't work on existing variables
        $php->addCodePiece("unset( \${$variableAssignmentName} );\n", array('spacing' => $spacing));
        if (is_array($variableData)) {
            foreach ($variableData as $index => $variableDataItem) {
                $variableDataType = $variableDataItem[0];
                if ($variableDataType == eZTemplate::TYPE_STRING or $variableDataType == eZTemplate::TYPE_NUMERIC or $variableDataType == eZTemplate::TYPE_IDENTIFIER or $variableDataType == eZTemplate::TYPE_ARRAY or $variableDataType == eZTemplate::TYPE_BOOLEAN) {
                    $knownTypes = array_unique(array_merge($knownTypes, array($staticTypeMap[$variableDataType])));
                    $dataValue = $variableDataItem[1];
                    $dataText = $php->thisVariableText($dataValue, 0, 0, false);
                    $php->addCodePiece("\${$variableAssignmentName} = {$dataText};\n", array('spacing' => $spacing));
                } else {
                    if ($variableDataType == eZTemplate::TYPE_OPTIMIZED_NODE) {
                        $optimizeNode = true;
                        if (!isset($resourceData['node-object-cached'])) {
                            $tpl->error("eZTemplateCompiler" . ($resourceData['use-comments'] ? ":" . __LINE__ : ""), "Attribute node-object-cached of variable \$resourceData was not found but variable node eZTemplate::TYPE_OPTIMIZED_NODE is still present. This should not happen");
                        }
                        $php->addCodePiece("\${$variableAssignmentName} = \$nod_{$resourceData['uniqid']};\n");
                        // If optimized node is not set, use unoptimized code.
                        $php->addCodePiece("if ( !\${$variableAssignmentName} )\n{\n");
                    } else {
                        if ($variableDataType == eZTemplate::TYPE_OPTIMIZED_ARRAY_LOOKUP) {
                            $code = $resourceData['use-comments'] ? "/*TC:" . __LINE__ . "*/\n" : "";
                            // This code is used a lot so we create a variable for it
                            $phpVar = "\${$variableAssignmentName}";
                            $indexName = "'{$variableDataItem[1][0][1]}'";
                            // Add sanity checking
                            $code .= "if ( !isset( {$phpVar}[{$indexName}] ) )\n" . "{\n" . "    \$tpl->error( 'eZTemplateCompiler" . ($resourceData['use-comments'] ? ":" . __LINE__ : "") . "', \"PHP variable \\{$phpVar}" . "[{$indexName}] does not exist, cannot fetch the value.\" );\n" . "    {$phpVar} = null;\n" . "}\n" . "else\n    ";
                            // Add the actual code
                            $code .= "{$phpVar} = {$phpVar}[{$indexName}];\n";
                            $php->addCodePiece($code);
                        } else {
                            if ($variableDataType == eZTemplate::TYPE_OPTIMIZED_ATTRIBUTE_LOOKUP) {
                                $code = $resourceData['use-comments'] ? "/*TC:" . __LINE__ . "*/\n" : "";
                                $code .= <<<END
if ( !is_object( \${$variableAssignmentName} ) )
{
    \${$variableAssignmentName} = null;
}
else if ( \${$variableAssignmentName}->hasAttribute( "{$variableDataItem[1][0][1]}" ) )
{
    \${$variableAssignmentName} = \${$variableAssignmentName}->attribute( "{$variableDataItem[1][0][1]}" );
}

END;
                                $php->addCodePiece($code);
                            } else {
                                if ($variableDataType == eZTemplate::TYPE_OPTIMIZED_CONTENT_CALL) {
                                    // Line number comment
                                    $code = $resourceData['use-comments'] ? "/*TC:" . __LINE__ . "*/\n" : "";
                                    // This code is used a lot so we create a variable for it
                                    $phpVar = "\${$variableAssignmentName}";
                                    // Add sanity checking
                                    $code .= "if ( !is_object( {$phpVar} ) )\n" . "{\n" . "    \$tpl->error( 'eZTemplateCompiler" . ($resourceData['use-comments'] ? ":" . __LINE__ : "") . "', \"PHP variable \\{$phpVar} is not an object, cannot fetch content()\" );\n" . "    {$phpVar} = null;\n" . "}\n" . "else\n" . "{\n";
                                    // Add the actual code
                                    $code .= "     {$phpVar}Tmp = {$phpVar}->content();\n" . "     unset( {$phpVar} );\n" . "     {$phpVar} = {$phpVar}Tmp;\n" . "     unset( {$phpVar}Tmp );\n}\n";
                                    $php->addCodePiece($code);
                                } else {
                                    if ($variableDataType == eZTemplate::TYPE_PHP_VARIABLE) {
                                        $knownTypes = array();
                                        $phpVariableName = $variableDataItem[1];
                                        $php->addCodePiece("\${$variableAssignmentName} = \${$phpVariableName};\n", array('spacing' => $spacing));
                                    } else {
                                        if ($variableDataType == eZTemplate::TYPE_VARIABLE) {
                                            $knownTypes = array();
                                            $namespace = $variableDataItem[1][0];
                                            $namespaceScope = $variableDataItem[1][1];
                                            $variableName = $variableDataItem[1][2];
                                            $namespaceText = eZTemplateCompiler::generateMergeNamespaceCode($php, $tpl, $namespace, $namespaceScope, array('spacing' => $spacing), true);
                                            if (!is_string($namespaceText)) {
                                                $namespaceText = "\$namespace";
                                            }
                                            $variableNameText = $php->thisVariableText($variableName, 0, 0, false);
                                            $code = "unset( \${$variableAssignmentName} );\n";
                                            $code .= "\${$variableAssignmentName} = ( array_key_exists( {$namespaceText}, \$vars ) and array_key_exists( {$variableNameText}, \$vars[{$namespaceText}] ) ) ? \$vars[{$namespaceText}][{$variableNameText}] : null;\n";
                                            $php->addCodePiece($code, array('spacing' => $spacing));
                                        } else {
                                            if ($variableDataType == eZTemplate::TYPE_ATTRIBUTE) {
                                                $knownTypes = array();
                                                $newParameters = $parameters;
                                                $newParameters['counter'] += 1;
                                                $tmpVariableAssignmentName = $newParameters['variable'];
                                                $tmpVariableAssignmentCounter = $newParameters['counter'];
                                                if ($tmpVariableAssignmentCounter > 0) {
                                                    $tmpVariableAssignmentName .= $tmpVariableAssignmentCounter;
                                                }
                                                if (eZTemplateNodeTool::isStaticElement($variableDataItem[1])) {
//.........这里部分代码省略.........
开发者ID:runelangseid,项目名称:ezpublish,代码行数:101,代码来源:eztemplatecompiler.php


注:本文中的eZTemplateCompiler::generateVariableDataCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。