preapreBagsData

@param   SessionBagInterface[] $bags

@return  static

@since   2.0
556692
protected function prepareBagsData(array $bags)
    {
        foreach ($bags as $name => $bag) {
            $ns = '_' . strtolower($name);

            $session = &$this->getBridge()->getStorage();

            if (!isset($session[$ns]) || !is_array($session[$ns])) {
                $session[$ns] = [];
            }

            $bag->setData($session[$ns]);
        }

        return $this;
    }
351588
private static function prepareHeaders(HeaderBag $headerBag)
    {
        $headers = $headerBag->all();
        $result = [];

        foreach ($headers as $header => $values) {
            $result[$header] = $values[0];
        }

        return $result;
    }
197763
private function getEntityValues(Bag $field)
    {
        $baseParts = explode('/', $field->get('values'));
        if (count($baseParts) < 2) {
            throw new \InvalidArgumentException(sprintf('The "values" key for a ContentType select must be in the form of ContentType/field_name but "%s" given', $field->get('values')));
        }

        $contentType = $baseParts[0];
        $queryFields = explode(',', $baseParts[1]);
        foreach ($queryFields as $queryField) {
            if ($queryField) {
                continue;
            }
            throw new \InvalidArgumentException(sprintf('The "values" key for a ContentType select must include a single field, or comma separated fields, "%s" given', $field->get('values')));
        }

        $filter = $field->get('filter');
        $filter['order'] = $field->get('sort');
        $filter['limit'] = $field->get('limit', self::DEFAULT_LIMIT);
        /** @var QueryResultset $entities */
        $entities = $this->query->getContent($contentType, $filter);
        if (!$entities) {
            return [];
        }

        $values = [];
        $ctCount = count($entities->getOriginalQueries());
        foreach ($entities as $entity) {
            $id = $entity->get($field->get('keys', 'id'));
            if ($ctCount > 1) {
                $values[(string)$entity->getContenttype() . '/' . $id] = $entity->get($queryFields[0]);
            } else {
                $values[$id] = $entity->get($queryFields[0]);
            }
            if (isset($queryFields[1])) {
                $values[$id] .= ' / ' . $entity->get($queryFields[1]);
            }
        }

        return $values;
    }
530858
public static function buildFilterBag(array $data)
    {
        $filterGroups = [];

        foreach ($data as $filters) {
            $filterObj = [];
            foreach ($filters as $filterName => $filterConfig) {
                $filterObj[] = new Filter($filterName, $filterConfig);
            }
            $filterGroups[] = new FilterGroup($filterObj);
        }

        return new FilterBag($filterGroups);
    }
1060321
public function getLanguageList(ParameterBagInterface $bag)
    {
        $allLangs = Intl::getLanguageBundle()->getLanguageNames();

        return array_flip(array_intersect_key($allLangs, array_flip($bag->get('pd_mailer.active_language'))));
    }
1220303
public function modify(HeaderBag &$headers)
    {
        $cspHeaders = [
            'Content-Security-Policy' => 'csp',
            'Content-Security-Policy-Report-Only' => 'cspro',
        ];

        foreach ($cspHeaders as $header => $type)
        {
            if ($this->combine)
            {
                $otherPolicyHeaders = $headers->getByName($header);

                $policies = [$this->{$type.'Config'}];

                foreach ($otherPolicyHeaders as $otherPolicy)
                {
                    $policies[]
                        = self::deconstructCSP($otherPolicy->getValue());
                }

                $this->{$type.'Config'} = self::mergeCSPList($policies);
            }

            $value = $this->{'compile'.strtoupper($type)}();

            if (empty($value))
            {
                continue;
            }

            $headers->{($this->combine ? 'replace' : 'add')}($header, $value);

            if ($this->sendLegacyHeaders)
            {
                $headers->{($this->combine ? 'replace' : 'add')}("X-$header", $value);
            }
        }
    }
1083885
public function pass(DataBagInterface $dataBag): DataBagInterface
    {
        $first = $dataBag[$this->first] ?? null;
        $second = $dataBag[$this->second] ?? null;
        $dataBag[$this->first] = $second;
        $dataBag[$this->second] = $first;

        return $dataBag;
    }
1094085
public static function fromHeaderLines(array $lines)
    {
        $bag = new static;

        foreach ($lines as $line)
        {
            preg_match('/^([^:]++)(?|(?:[:][ ]?+)(.*+)|())/', $line, $matches);
            array_shift($matches);

            list($name, $value) = $matches;

            $bag->add($name, $value);
        }

        return $bag;
    }
692506
protected function normalizeBag($bag) : Collection
	{
		return Collection::make($bag)->filter(function ($item) {
			return is_string($item) ? trim($item) !== '' : $item;
		});
	}
1029264
private function _openBag()
    {
        if ($this->_isCompressed()) {
            $this->bagDirectory = BagIt_uncompressBag($this->bag);
        } else {
            $this->bagDirectory = realpath($this->bag);
        }

        $this->bagitFile = "{$this->bagDirectory}/bagit.txt";
        list($version, $fileEncoding, $errors) = BagIt_readBagItFile(
            $this->bagitFile
        );
        $this->bagVersion = $version;
        $this->tagFileEncoding = $fileEncoding;
        $this->bagErrors = array_merge($this->bagErrors, $errors);

        $files = scandir($this->bagDirectory);
        if (count($files) > 0) {
            $bagdir = $this->bagDirectory;
            $manifestFile = findFirstExisting(
                array("$bagdir/manifest-sha1.txt", "$bagdir/manifest-md5.txt"),
                "$bagdir/manifest-sha1.txt"
            );
            try {
                $this->manifest = new BagItManifest(
                    $manifestFile,
                    $this->bagDirectory . '/',
                    $this->tagFileEncoding
                );
            } catch (Exception $exc) {
                array_push(
                    $this->bagErrors,
                    array('manifest', "Error reading $manifestFile.")
                );
            }

            if ($this->isExtended()) {
                $manifestFile = findFirstExisting(
                    array("$bagdir/tagmanifest-sha1.txt",
                    "$bagdir/tagmanifest-md5.txt"),
                    "$bagdir/tagmanifest-sha1.txt"
                );
                $this->tagManifest = new BagItManifest(
                    $manifestFile,
                    $this->bagDirectory . '/',
                    $this->tagFileEncoding
                );

                try {
                    $this->fetch = new BagItFetch(
                        "{$this->bagDirectory}/fetch.txt",
                        $this->tagFileEncoding
                    );
                } catch (Exception $exc) {
                    array_push(
                        $this->bagErrors,
                        array('fetch', 'Error reading fetch file.')
                    );
                }

                $this->bagInfoFile = "{$this->bagDirectory}/bag-info.txt";
                $this->_readBagInfo();
            }
        }
    }
651815
protected static function prefetchFiles()
	{
		self::$_files = array();
		if(!isset($_FILES) || !is_array($_FILES))
			return;

		foreach($_FILES as $class=>$info)
			self::collectFilesRecursive($class, $info['name'], $info['tmp_name'], $info['type'], $info['size'], $info['error']);
	}
1104849
public function updatePaths(MutableBag $paths)
    {
        if ($paths->isEmpty()) {
            return $paths;
        }

        if ($web = $paths['web']) {
            if ($web === 'public') {
                $paths->remove('web');
            } elseif (strpos($web, '%site%') !== 0) {
                $paths['web'] = '%site%/' . $web;
            }
        }
        $webLength = strlen($web . '/');

        if ($files = $paths['files']) {
            if ($files === $web . '/files') {
                $paths->remove('files');
            } elseif (strpos($files, $web . '/') === 0) {
                $paths['files'] = '%web%/' . substr($files, $webLength);
            }
        }

        if ($paths->has('themebase')) {
            $themes = $paths->remove('themebase');
            if ($themes === $web . '/theme') {
                // nothing
            } elseif (strpos($themes, $web . '/') === 0) {
                $paths['themes'] = '%web%/' . substr($themes, $webLength);
            }
        }

        if ($paths->has('view')) {
            $boltAssets = $paths->remove('view');
            if ($boltAssets === $web . '/bolt-public/view') {
                // nothing
            } elseif (strpos($boltAssets, $web . '/') === 0) {
                $paths['bolt_assets'] = '%web%/' . substr($boltAssets, $webLength);
            }
        }

        if ($var = $paths['var']) {
            if ($var === 'var') {
                $paths->remove('var');
            } elseif (strpos($var, '%site%') !== 0) {
                $paths['var'] = '%site%/' . $var;
            }
        }
        $var = $var ?: 'var';
        $varLength = strlen($var . '/');

        if ($cache = $paths['cache']) {
            // Handle v4 style layouts
            if (strpos($cache, $var . '/') === 0) {
                $paths['cache'] = '%var%/' . substr($cache, $varLength);
            }
        }

        if ($paths->has('app')) {
            return $paths;
        }

        $appPathKeys = ['cache', 'config', 'database'];
        $appPaths = array_intersect_key($paths->toArray(), array_flip($appPathKeys));
        // Only paths without %app% alias in them.
        $appPaths = array_filter($appPaths, function ($path) {
            return strpos($path, '%app%') === false || strpos($path, 'app') === 0;
        });
        if (empty($appPaths)) {
            return $paths;
        }
        $app = $this->determineMostCommonBaseAppPath($appPaths);

        if ($app === 'app') {
            // "app/" is the default "app" path, so don't bother setting.
            $appPathToTrim = 'app/';
        } elseif ($app === '') {
            // no common base path so just ignore app path alias
            $appPathToTrim = '';
        } else {
            // custom app path, set it.
            $site = $paths->get('site', '.');
            $paths['app'] = '%site%/' . Path::makeRelative($app, $site);
            $appPathToTrim = $app . '/';
        }

        foreach ($appPathKeys as $key) {
            if (!($path = $paths[$key])) {
                continue;
            }
            if ($appPathToTrim && strpos($path, $appPathToTrim) === 0) {
                $path = Str::replaceFirst($path, $appPathToTrim, '');
                if ($path === $key) {
                    $paths->remove($key);
                } else {
                    $paths[$key] = '%app%/' . $path;
                }
            } else {
                $paths[$key] = $path;
            }
        }

        return $paths;
    }
1060354
public static function normalizePrefetchLookup($lookups, $prefix = null): array
    {
        $results = [];
        foreach ($lookups as $lookup) {
            if (!$lookup instanceof Prefetch) {
                $lookup = new Prefetch($lookup);
            }
            if ($prefix) {
                $lookup->addPrefix($prefix);
            }
            $results[] = $lookup;
        }

        return $results;
    }
986509
public function findOrCreate($criteria, $parameters = null)
    {
        if ($criteria instanceof Bag) {
            $criteria = $criteria->toArray();
        }

        if ($parameters === null) {
            $parameters = $criteria;
        }

        $parameters = $this->castParameters($parameters);
        $entity = $this->getRepository()->findOneBy($criteria);

        if ($entity == null) {
            return $this->create($parameters);
        }

        $result = new Result();
        $result->getResources()->push($entity);

        return $result;
    }
708312
public function run(Bag $importData, MutableBag $responseBag, $overwrite = false, Bag $importUsers = null)
    {
        $this->validateContentTypes($importData);
        $relationQueue = MutableBag::from([]);
        if ($importUsers) {
            $this->importUsers($importUsers, $responseBag);
        }

        foreach ($importData as $contentTypeName => $recordsData) {
            $this->importContentType($contentTypeName, $recordsData, $relationQueue, $responseBag, $overwrite);
        }
        $this->processRelationQueue($relationQueue);

        return $responseBag;
    }
1197025
protected function getSessionBag()
    {
        if ($this->scopeDeterminator->currentScopeIsBackend()) {
            return $this->session->getBag('contao_backend');
        }

        if ($this->scopeDeterminator->currentScopeIsFrontend()) {
            return $this->session->getBag('contao_frontend');
        }

        return $this->session->getBag('attributes');
    }
199167
public function preload($preload)
    {
        $validPreloadAttrs = ['auto', 'metadata', 'none'];
        
        if (\in_array($preload, $validPreloadAttrs, true)) {
            $this->attributes['preload'] = $preload;
        }

        return $this;
    }