@param \ArrayAccess $flaggedObject
@param array        $layout

@return array
487633
protected function getLayoutOptions(\ArrayAccess $flaggedObject, array $layout)
    {
        $result = array();
        foreach ($layout as $flag => $options) {
            if ($flaggedObject->offsetExists($flag)) {
                $value = $flaggedObject->offsetGet($flag);
                $value = (string) $value;
                if (isset($options[$value])) {
                    $result += $options[$value];
                }
            }
        }

        /* @var $callback callable */
        foreach ($this->layoutCallback as $callback) {
            $result = $callback($flaggedObject, $result);
        }

        return $result;
    }
1145707
protected function renderSubCommandArguments(BlockLayout $layout, array $arguments)
    {
        foreach ($arguments as $argument) {
            $this->renderArgument($layout, $argument);
        }

        $layout->add(new EmptyLine());
    }
1364400
private static function getFlagsSelect($statement, $flags)
    {
        $flags['querytype'] = 'SELECT';
        $flags['is_select'] = true;

        if (! empty($statement->from)) {
            $flags['select_from'] = true;
        }

        if ($statement->options->has('DISTINCT')) {
            $flags['distinct'] = true;
        }

        if (! empty($statement->group) || ! empty($statement->having)) {
            $flags['is_group'] = true;
        }

        if (! empty($statement->into)
            && ($statement->into->type === 'OUTFILE')
        ) {
            $flags['is_export'] = true;
        }

        $expressions = $statement->expr;
        if (! empty($statement->join)) {
            foreach ($statement->join as $join) {
                $expressions[] = $join->expr;
            }
        }

        foreach ($expressions as $expr) {
            if (! empty($expr->function)) {
                if ($expr->function === 'COUNT') {
                    $flags['is_count'] = true;
                } elseif (in_array($expr->function, static::$FUNCTIONS)) {
                    $flags['is_func'] = true;
                }
            }
            if (! empty($expr->subquery)) {
                $flags['is_subquery'] = true;
            }
        }

        if (! empty($statement->procedure)
            && ($statement->procedure->name === 'ANALYSE')
        ) {
            $flags['is_analyse'] = true;
        }

        if (! empty($statement->group)) {
            $flags['group'] = true;
        }

        if (! empty($statement->having)) {
            $flags['having'] = true;
        }

        if (! empty($statement->union)) {
            $flags['union'] = true;
        }

        if (! empty($statement->join)) {
            $flags['join'] = true;
        }

        return $flags;
    }
475908
protected function parseListing(ContainerInterface $container, Contao2BackendViewDefinitionInterface $view)
    {
        $listing = $view->getListingConfig();
        $listDca = $this->getFromDca('list');

        if ((null === $listing->getRootLabel()) && (null !== ($label = $this->getFromDca('config/label')))) {
            $listing->setRootLabel($label);
        }

        if ((null === $listing->getRootIcon()) && (null !== ($icon = $this->getFromDca('config/icon')))) {
            $listing->setRootIcon($icon);
        }

        // Cancel if no list configuration found.
        if (!$listDca) {
            return [];
        }

        $parsedProperties = $this->parseListSorting($listing, $listDca);
        $this->parseListLabel($container, $listing, $listDca);

        return $parsedProperties;
    }
845975
public function loadRulesData(int $status, ?Layout $layout = null, int $offset = 0, ?int $limit = null): array
    {
        $query = $this->getRuleSelectQuery();

        if ($layout instanceof Layout) {
            $query->andWhere(
                $query->expr()->eq('layout_id', ':layout_id')
            )
            ->setParameter('layout_id', $layout->id, Type::INTEGER);
        }

        $query->addOrderBy('rd.priority', 'DESC');

        $this->applyStatusCondition($query, $status, 'r.status');
        $this->applyOffsetAndLimit($query, $offset, $limit);

        return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
    }
965056
public function checkCacheFlag($eventObject) {
        if (Mage::helper('turpentine/varnish')->shouldResponseUseVarnish()) {
            $layoutXml = $eventObject->getLayout()->getUpdate()->asSimplexml();
            foreach ($layoutXml->xpath('//turpentine_cache_flag') as $node) {
                foreach ($node->attributes() as $attr => $value) {
                    if ($attr == 'value') {
                        if ( ! (string) $value) {
                            Mage::register('turpentine_nocache_flag', true, true);
                            return; //only need to set the flag once
                        }
                    }
                }
            }
        }
    }
752247
public function findAndValidateJsonRpcMethodDefinition(ContainerBuilder $container) : array
    {
        $definitionList = [];

        $taggedServiceList = $container->findTaggedServiceIds(JsonRpcHttpServerExtension::JSONRPC_METHOD_TAG);

        foreach ($taggedServiceList as $serviceId => $tagAttributeList) {
            $this->validateJsonRpcMethodDefinition($serviceId, $container->getDefinition($serviceId));

            foreach ($tagAttributeList as $tagAttributeKey => $tagAttributeData) {
                $this->validateJsonRpcMethodTagAttributes($serviceId, $tagAttributeData);
                $methodName = $tagAttributeData[JsonRpcHttpServerExtension::JSONRPC_METHOD_TAG_METHOD_NAME_KEY];
                $definitionList[$serviceId][] = $methodName;
            }
        }

        return $definitionList;
    }
1267968
protected function getDecorator($layout)
    {
        $key = '{{ CONTENT }}';
        if (false === strpos($layout, $key)) {
            return [];
        }

        $segments = explode($key, $layout);
        $decorator = [
            'pre' => $segments[0] ?? '',
            'post' => $segments[1] ?? '',
        ];

        return $decorator;
    }
51152
public function render(string $layout = null, array $context = [])
    {
        if (null === $layout) {
            $layout = 'default';
        }
        $type = $this->getFlexType();

        $grav = Grav::instance();

        /** @var Debugger $debugger */
        $debugger = $grav['debugger'];
        $debugger->startTimer('flex-collection-' . ($debugKey =  uniqid($type, false)), 'Render Collection ' . $type . ' (' . $layout . ')');

        $cache = $key = null;
        foreach ($context as $value) {
            if (!\is_scalar($value)) {
                $key = false;
            }
        }

        if ($key !== false) {
            $key = md5($this->getCacheKey() . '.' . $layout . json_encode($context));
            $cache = $this->getCache('render');
        }

        try {
            $data = $cache ? $cache->get($key) : null;

            $block = $data ? HtmlBlock::fromArray($data) : null;
        } catch (InvalidArgumentException $e) {
            $debugger->addException($e);
            $block = null;
        } catch (\InvalidArgumentException $e) {
            $debugger->addException($e);
            $block = null;
        }

        $checksum = $this->getCacheChecksum();
        if ($block && $checksum !== $block->getChecksum()) {
            $block = null;
        }

        if (!$block) {
            $block = HtmlBlock::create($key);
            $block->setChecksum($checksum);
            if ($key === false) {
                $block->disableCache();
            }

            $grav->fireEvent('onFlexCollectionRender', new Event([
                'collection' => $this,
                'layout' => &$layout,
                'context' => &$context
            ]));

            $output = $this->getTemplate($layout)->render(
                ['grav' => $grav, 'config' => $grav['config'], 'block' => $block, 'collection' => $this, 'layout' => $layout] + $context
            );

            if ($debugger->enabled()) {
                $output = "\n<!–– START {$type} collection ––>\n{$output}\n<!–– END {$type} collection ––>\n";
            }

            $block->setContent($output);

            try {
                $cache && $block->isCached() && $cache->set($key, $block->toArray());
            } catch (InvalidArgumentException $e) {
                $debugger->addException($e);
            }
        }

        $debugger->stopTimer('flex-collection-' . $debugKey);

        return $block;
    }
1089983
private function processZones(Layout $layout, array $layoutData): void
    {
        foreach ($layout->getZones() as $zone) {
            if (!array_key_exists($zone->getIdentifier(), $layoutData['zones'])) {
                throw new RuntimeException(
                    sprintf('Missing data for zone "%s"', $zone->getIdentifier())
                );
            }

            $this->processZone($zone, $layoutData['zones'][$zone->getIdentifier()]);
        }
    }
139610
public function getRuleCount(int $ruleStatus, ?Layout $layout = null): int
    {
        $query = $this->connection->createQueryBuilder();
        $query->select('count(*) AS count')
            ->from('ngbm_rule');

        if ($layout instanceof Layout) {
            $query->andWhere(
                $query->expr()->eq('layout_id', ':layout_id')
            )
            ->setParameter('layout_id', $layout->id, Type::INTEGER);
        }

        $this->applyStatusCondition($query, $ruleStatus);

        $data = $query->execute()->fetchAll(PDO::FETCH_ASSOC);

        return (int) ($data[0]['count'] ?? 0);
    }
987991
protected function renderSubCommandOptions(BlockLayout $layout, array $options)
    {
        foreach ($options as $option) {
            $this->renderOption($layout, $option);
        }

        $layout->add(new EmptyLine());
    }
193511
protected function getLayoutFile(Layout $layout)
    {
        $layoutfile = $layout->getPath();
        if (null === $layoutfile && 0 < $this->manageableExt->count()) {
            $adapter = null;
            if (null !== $this->defaultAdapter && null !== $adapter = $this->rendererAdapters->get($this->defaultAdapter)) {
                $extensions = $adapter->getManagedFileExtensions();
            } else {
                $extensions = $this->manageableExt->keys();
            }

            if (0 === count($extensions)) {
                throw new RendererException(
                        'Declared adapter(s) (count:'.$this->rendererAdapters->count().') is/are not able to manage '.
                        'any file extensions at moment.'
                );
            }

            $layoutfile = StringUtils::toPath($layout->getLabel(), array('extension' => reset($extensions)));
            $layout->setPath($layoutfile);
        }

        return $layoutfile;
    }
1347424
protected function getFlags($flagOptions)
    {
        $flags = [];

        foreach ($flagOptions as $key => $value) {
            $prefix = strlen($key) === 1 ? '-' : '--';
            if (is_bool($value)) {
                if ($value) {
                    // of example "--quiet"
                    $flags[] = $prefix.$key;
                }
            } elseif (is_array($value)) {
                foreach ($value as $subKey => $subValue) {
                    if (is_int($subKey)) {
                        // of example "--exclude 'dir'"
                        $flags[] = $prefix.$key.' '.escapeshellarg($subValue);
                    } else {
                        // of example "-o BatchMode='yes'"
                        $flags[] = $prefix.$key.' '.$subKey.'='.$subValue;
                    }
                }
            } elseif (is_string($value)) {
                // of example "--rsh 'ssh -p 22'"
                $flags[] = $prefix.$key.' '.escapeshellarg($value);
            }
        }

        return $flags;
    }
1368679
protected function processBlockViewData(
        BlockView $blockView,
        ContextInterface $context,
        DataAccessor $data,
        $deferred,
        $encoding
    ) {
        if ($deferred) {
            $this->expressionProcessor->processExpressions($blockView->vars, $context, $data, true, $encoding);
        }

        $this->buildValueBags($blockView);

        foreach ($blockView->children as $key => $childView) {
            $this->processBlockViewData($childView, $context, $data, $deferred, $encoding);

            if (!$childView->isVisible()) {
                unset($blockView->children[$key]);
            }
        }
    }
1096903
public function collectBlockView(BlockViewInterface $blockView): void
    {
        $block = $blockView->getBlock();
        $blockDefinition = $block->getDefinition();

        $blockData = [
            'id' => $block->getId(),
            'layout_id' => $block->getLayoutId(),
            'definition' => $blockDefinition->getName(),
            'view_type' => $blockDefinition->hasViewType($block->getViewType()) ?
                $blockDefinition->getViewType($block->getViewType())->getName() :
                'Invalid view type',
            'locale' => $block->getLocale(),
            'template' => null,
            'template_path' => null,
        ];

        if ($blockView->getTemplate() !== null) {
            $templateSource = $this->getTemplateSource($blockView->getTemplate());

            $blockData['template'] = $templateSource->getName();
            $blockData['template_path'] = $templateSource->getPath();
        }

        $this->data['blocks'][] = $blockData;
    }
1100387
private function addTranslations(Layout $layout, array $layoutData): void
    {
        $translationLocales = $this->extractTranslationLocales($layoutData);

        foreach ($translationLocales as $locale) {
            $this->layoutService->addTranslation($layout, $locale, $layoutData['main_locale']);
        }
    }