Optimizes print nodes.

It replaces:

* "echo $this->render(Parent)Block()" with "$this->display(Parent)Block()"

@param Twig_NodeInterface $node A Node
@param Twig_Environment   $env  The current Twig environment
513482
protected function optimizePrintNode(Twig_NodeInterface $node, Twig_Environment $env)
    {
        if (!$node instanceof Twig_Node_Print) {
            return $node;
        }

        if (
            $node->getNode('expr') instanceof Twig_Node_Expression_BlockReference ||
            $node->getNode('expr') instanceof Twig_Node_Expression_Parent
        ) {
            $node->getNode('expr')->setAttribute('output', true);

            return $node->getNode('expr');
        }

        return $node;
    }
1089137
public function renderTableJs(\Twig_Environment $env, $args = array()) {
        $array = array();
        $config = $this->fillModel($array);
        $array['updateUrl'] =  $this->fetchUrl($args, 'update', $config->getUpdateRoute());
        $array['deleteUrl'] = $this->fetchUrl($args, 'delete', $config->getDeleteRoute());
        $array['addUrl'] = $this->fetchUrl($args, 'add', $config->getAddRoute());
        $array['dtDefaultOpts'] = $this->container->getParameter('twentysteps_auto_tables.default_datatables_options');
        $array['dtOpts'] = $config->getDataTablesOptions();
        $array['dtTagOpts'] = $this->getParameter($args, 'dtOptions', array());
        $array['tableId'] = $config->getId();
        $array['transScope'] = $config->getTransScope();
        $array['reloadAfterAdd'] = $this->getParameter($args, 'reloadAfterAdd', true);
        $array['reloadAfterUpdate'] = $this->getParameter($args, 'reloadAfterUpdate', false);
        $array['includeJavascript'] = $this->checkIncludeJavascript();
        $array['includeBootstrap3'] = $this->getParameter($args, 'includeBootstrap3', false);
        $array['includeJquery'] = $this->getParameter($args, 'includeJquery', FALSE);
        $array['includeJqueryUi'] = $this->getParameter($args, 'includeJqueryUi', $config->getFrontendFramework() == FrontendFramework::JQUERY_UI);
        $array['includeJqueryEditable'] = $this->getParameter($args, 'includeJqueryEditable', TRUE);
        $array['includeJqueryEditableDatePicker'] = $this->getParameter($args, 'includeJqueryEditableDatePicker', $config->getFrontendFramework() == FrontendFramework::JQUERY_UI);
        $array['includeJqueryEditableBootstrapDatePicker'] = $this->getParameter($args, 'includeJqueryEditableBootstrapDatePicker', $config->getFrontendFramework() == FrontendFramework::BOOTSTRAP3);
        $array['includeJqueryDataTables'] = $this->getParameter($args, 'includeJqueryDataTables', TRUE);
        $array['includeJqueryValidate'] = $this->getParameter($args, 'includeJqueryValidate', TRUE);
        $array['useJqueryUi'] = $config->getFrontendFramework() == FrontendFramework::JQUERY_UI;
        $array['useBootstrap'] = $config->getFrontendFramework() == FrontendFramework::BOOTSTRAP3;
        return $this->render($env, 'twentystepsAutoTablesBundle:AutoTablesExtension:autoTableJs.html.twig', $array);
    }
1122776
public function renderWidget(Twig_Environment $env, $route, array $parameters = [])
    {
        $template = $env->loadTemplate(
            '@KunstmaanAdmin/MultiDomainAdminTwigExtension/widget.html.twig'
        );

        return $template->render(
            \array_merge(
                $parameters, [
                    'hosts' => $this->getAdminDomainHosts(),
                    'route' => $route,
                ]
            )
        );
    }
736587
private function renderNode(NodeInterface $node, int $node_id): string
    {
        if ($node instanceof LeafNode) {
            return $this->renderLeafNode($node, $node_id);
        } elseif ($node instanceof RootNode) {
            return $this->renderRootNode($node_id);
        }
        return $this->renderInternalNode($node, $node_id);
    }
63579
public function renderPageAction(NodeInterface $node, $type, $sub_area = null, $locality = null)
    {
        /** @var SiteManager $siteManager */
        $siteManager = $this->get('ucms_site.manager');
        if ($siteManager->hasContext()) {
            /** @var ContextManager $layoutContext */
            $layoutContext = $this->get('ucms_layout.context_manager');
            $layoutContext->getPageContext()
                          ->setCurrentLayoutNodeId($node->id(), $siteManager->getContext()->getId())
            ;
        }

        return node_view($node);
    }
719794
private function upgradeNode(NodeInterface $node)
    {
        foreach ($node->getProperties('i18n:-*') as $property) {
            $property->remove();
        }

        foreach ($node->getNodes() as $childNode) {
            $this->upgradeNode($childNode);
        }
    }
900536
public function enterNode(NodeInterface $node): VisitorResult
    {
        $schema = $this->typeInfo->getSchema();

        if ($node instanceof SelectionSetNode) {
            $namedType = getNamedType($this->typeInfo->getType());
            $this->typeInfo->pushParentType($namedType instanceof CompositeTypeInterface ? $namedType : null);
        } elseif ($node instanceof FieldNode) {
            $parentType      = $this->typeInfo->getParentType();
            $fieldDefinition = null;
            $fieldType       = null;
            if (null !== $parentType) {
                $fieldDefinition = $this->typeInfo->resolveFieldDefinition($schema, $parentType, $node);
                if (null !== $fieldDefinition) {
                    $fieldType = $fieldDefinition->getType();
                }
            }
            $this->typeInfo->pushFieldDefinition($fieldDefinition);
            $this->typeInfo->pushType(isOutputType($fieldType) ? $fieldType : null);
        } elseif ($node instanceof DirectiveNode) {
            $this->typeInfo->setDirective($schema->getDirective($node->getNameValue()));
        } elseif ($node instanceof OperationDefinitionNode) {
            $type      = null;
            $operation = $node->getOperation();
            if ($operation === 'query') {
                $type = $schema->getQueryType();
            } elseif ($operation === 'mutation') {
                $type = $schema->getMutationType();
            } elseif ($operation === 'subscription') {
                $type = $schema->getSubscriptionType();
            }
            $this->typeInfo->pushType($type instanceof ObjectType ? $type : null);
        } elseif ($node instanceof InlineFragmentNode || $node instanceof FragmentDefinitionNode) {
            $typeCondition = $node->getTypeCondition();
            $outputType    = null !== $typeCondition
                ? TypeASTConverter::convert($schema, $typeCondition)
                : getNamedType($this->typeInfo->getType());
            $this->typeInfo->pushType(isOutputType($outputType) ? $outputType : null);
        } elseif ($node instanceof VariableDefinitionNode) {
            $inputType = TypeASTConverter::convert($schema, $node->getType());
            /** @noinspection PhpParamsInspection */
            $this->typeInfo->pushInputType(isInputType($inputType) ? $inputType : null);
        } elseif ($node instanceof ArgumentNode) {
            $argumentType       = null;
            $argumentDefinition = null;
            $fieldOrDirective   = $this->typeInfo->getDirective() ?: $this->typeInfo->getFieldDefinition();
            if (null !== $fieldOrDirective) {
                $argumentDefinition = find(
                    $fieldOrDirective->getArguments(),
                    function (Argument $argument) use ($node) {
                        return $argument->getName() === $node->getNameValue();
                    }
                );
                if (null !== $argumentDefinition) {
                    $argumentType = $argumentDefinition->getType();
                }
            }
            $this->typeInfo->setArgument($argumentDefinition);
            $this->typeInfo->pushInputType(isInputType($argumentType) ? $argumentType : null);
        } elseif ($node instanceof ListValueNode) {
            $listType = getNullableType($this->typeInfo->getInputType());
            $itemType = $listType instanceof ListType ? $listType->getOfType() : $listType;
            $this->typeInfo->pushInputType(isInputType($itemType) ? $itemType : null);
        } elseif ($node instanceof ObjectFieldNode) {
            $objectType     = getNamedType($this->typeInfo->getInputType());
            $inputFieldType = null;
            if ($objectType instanceof InputObjectType) {
                $fields     = $objectType->getFields();
                $inputField = $fields[$node->getNameValue()] ?? null;
                if (null !== $inputField) {
                    $inputFieldType = $inputField->getType();
                }
            }
            /** @noinspection PhpParamsInspection */
            $this->typeInfo->pushInputType(isInputType($inputFieldType) ? $inputFieldType : null);
        } elseif ($node instanceof EnumValueNode) {
            $enumType  = getNamedType($this->typeInfo->getInputType());
            $enumValue = null;
            if ($enumType instanceof EnumType) {
                $enumValue = $enumType->getValue($node->getValue());
            }
            $this->typeInfo->setEnumValue($enumValue);
        }

        return $this->visitor->enterNode($node);
    }
47794
public function addNode(NodeInterface $node): NodeInterface
    {
        $this->_nodes[$node->getId()] = $node;

        if ($this->getParent()) {
            $this->getParent()->addNode($node);
        }

        return $this;
    }
460986
public function copyNode(NodeInterface $node)
    {
        $this->nodeContextPath = $node->getContextPath();
        $this->mode = self::MODE_COPY;
    }
233005
protected function filterNodeByContext(NodeInterface $node, Context $context)
    {
        $this->securityContext->withoutAuthorizationChecks(function () use (&$node, $context) {
            if (!$context->isRemovedContentShown() && $node->isRemoved()) {
                $node = null;
                return;
            }
            if (!$context->isInvisibleContentShown() && !$node->isVisible()) {
                $node = null;
                return;
            }
            if (!$context->isInaccessibleContentShown() && !$node->isAccessible()) {
                $node = null;
            }
        });
        return $node;
    }
170298
public function afterNodeCreate(NodeInterface $node)
    {
        if (!$this->eventEmittingService->isEnabled()) {
            return;
        }

        /* @var $nodeEvent NodeEvent */
        $nodeEvent = array_pop($this->currentNodeAddEvents);
        $nodeEvent->setNode($node);
        $this->eventEmittingService->popContext();
        $this->eventEmittingService->add($nodeEvent);
    }
1300135
private function spliceTree($envs, Block $block, $without)
    {
        $newBlock = null;

        foreach ($envs as $e) {
            if (! isset($e->block)) {
                continue;
            }

            if ($e->block === $block) {
                continue;
            }

            if (isset($e->block->type) && $e->block->type === Type::T_AT_ROOT) {
                continue;
            }

            if ($e->block && $this->isWithout($without, $e->block)) {
                continue;
            }

            $b = new Block;
            $b->sourceName   = $e->block->sourceName;
            $b->sourceIndex  = $e->block->sourceIndex;
            $b->sourceLine   = $e->block->sourceLine;
            $b->sourceColumn = $e->block->sourceColumn;
            $b->selectors    = [];
            $b->comments     = $e->block->comments;
            $b->parent       = null;

            if ($newBlock) {
                $type = isset($newBlock->type) ? $newBlock->type : Type::T_BLOCK;

                $b->children = [[$type, $newBlock]];

                $newBlock->parent = $b;
            } elseif (count($block->children)) {
                foreach ($block->children as $child) {
                    if ($child[0] === Type::T_BLOCK) {
                        $child[1]->parent = $b;
                    }
                }

                $b->children = $block->children;
            }

            if (isset($e->block->type)) {
                $b->type = $e->block->type;
            }

            if (isset($e->block->name)) {
                $b->name = $e->block->name;
            }

            if (isset($e->block->queryList)) {
                $b->queryList = $e->block->queryList;
            }

            if (isset($e->block->value)) {
                $b->value = $e->block->value;
            }

            $newBlock = $b;
        }

        $type = isset($newBlock->type) ? $newBlock->type : Type::T_BLOCK;

        return [$type, $newBlock];
    }
460355
public function parse(\Twig_NodeInterface $node)
    {
        foreach ($node as $subNode) {

            if (! $subNode instanceof \Twig_NodeInterface) {
                continue;
            }

            $nodeClass = get_class($subNode);

            switch ($nodeClass) {
                case 'Twig_Node_Set':
                    $this->context[] = $this->env->getCompiler()->compile($subNode)->getSource();
                    break;
                
                default:
                    $this->parse($subNode);
                    break;
            }
        }

        return $this;
    }
1019952
protected function finish(NodeInterface $node)
    {
        $this->persistenceManager->persistAll();

        $updateNodeInfo = new UpdateNodeInfo();
        $updateNodeInfo->setNode($node);
        $updateNodeInfo->recursive();

        $updateParentNodeInfo = new UpdateNodeInfo();
        $updateParentNodeInfo->setNode($node->getParent());

        $this->feedbackCollection->add($updateNodeInfo);
        $this->feedbackCollection->add($updateParentNodeInfo);

        $this->updateWorkspaceInfo();

        if ($node->getNodeType()->isOfType('Neos.Neos:Content') && ($this->getParentDomAddress() || $this->getSiblingDomAddress())) {

            // we can ONLY render out of band if:
            // 1) the parent of our new (or copied or moved) node is a ContentCollection; so we can directly update an element of this content collection
            if ($node->getParent()->getNodeType()->isOfType('Neos.Neos:ContentCollection') &&

                // 2) the parent DOM address (i.e. the closest RENDERED node in DOM is actually the ContentCollection; and
                //    no other node in between
                $this->getParentDomAddress() &&
                $this->getParentDomAddress()->getFusionPath() &&
                $this->getParentDomAddress()->getContextPath() === $node->getParent()->getContextPath()
            ) {
                $renderContentOutOfBand = new RenderContentOutOfBand();
                $renderContentOutOfBand->setNode($node);
                $renderContentOutOfBand->setParentDomAddress($this->getParentDomAddress());
                $renderContentOutOfBand->setSiblingDomAddress($this->getSiblingDomAddress());
                $renderContentOutOfBand->setMode($this->getMode());

                $this->feedbackCollection->add($renderContentOutOfBand);
            } else {
                $reloadDocument = new ReloadDocument();
                $reloadDocument->setNode($node);

                $this->feedbackCollection->add($reloadDocument);
            }
        }
    }
1044015
public function nodeRemoved(NodeInterface $node)
    {
        if (!$this->eventEmittingService->isEnabled()) {
            return;
        }

        /* @var $nodeEvent NodeEvent */
        $nodeEvent = $this->eventEmittingService->emit(self::NODE_REMOVED, [], NodeEvent::class);
        $nodeEvent->setNode($node);
    }
522314
protected function processConfigurationNode(NodeInterface $node)
    {

        // load the object manager instance
        /** @var \AppserverIo\Psr\Di\ObjectManagerInterface $objectManager */
        $objectManager = $this->getApplication()->search(ObjectManagerInterface::IDENTIFIER);

        // iterate over all configured descriptors and try to load object description
        /** \AppserverIo\Appserver\Core\Api\Node\DescriptorNode $descriptor */
        foreach ($this->getDescriptors() as $descriptor) {
            try {
                // load the descriptor class
                $descriptorClass = $descriptor->getNodeValue()->getValue();

                // load the object descriptor, initialize the servlet mappings and add it to the object manager
                /** \AppserverIo\Psr\Deployment\DescriptorInterface $objectDescriptor */
                if ($objectDescriptor = $descriptorClass::newDescriptorInstance()->fromConfiguration($node)) {
                    $objectManager->addObjectDescriptor($objectDescriptor, true);
                }

                // proceed with the next descriptor
                continue;

                // if class can not be reflected continue with next class
            } catch (\Exception $e) {
                // log an error message
                $this->getApplication()->getInitialContext()->getSystemLogger()->error($e->__toString());

                // proceed with the next descriptor
                continue;
            }
        }
    }
780279
private function renderEdge(NodeInterface $node, NodeInterface $child, array $node_map, string $S): string
    {
        return sprintf(
            '%s -> %s [ '.self::BASE_EDGE_PROPS.' '.self::EDGE_PROPS.' ];',
            array_search($node, $node_map, true),
            array_search($child, $node_map, true),
            substr($S, $child->getStart(), $child->getEnd() - $child->getStart() + 1)
        );
    }