Loads from Extensions

@param array $content
495101
private function loadFromExtensions($content)
    {
        foreach ($content as $namespace => $values) {
            if (in_array($namespace, ['imports', 'parameters'])) {
                continue;
            }

            if (!is_array($values)) {
                $values = [];
            }

            $this->configCollection->add($namespace, $values);
        }
    }
1066021
protected function processVars(string &$content): void
    {
        $pattern = $this->getTagPattern('(\$.+?)');
        $content = preg_replace_callback($pattern, function ($match) {
            return '<?php echo ' . $match[1] . '; ?>';
        }, $content);
    }
1091668
public static function getArrayKeys($content)
    {
        preg_match_all(self::ARRAY_KEYS_REGEX, trim($content), $matches);

        return !empty($matches) ? $matches[1] : array();
    }
788313
public function loadContent(string $content, $encoding='UTF-8')
    {
        $this->preserve_no_newlines = (strpos($content, '<') !== false && strpos($content, "\n") === false);

        if (!\is_bool($this->xml_mode)) {
            $this->xml_mode = (stripos($content, '<?xml') === 0);
        }

        $this->xml_print_pi = (stripos($content, '<?xml') === 0);

        $xml_pi_node_added = false;
        if (!$this->xml_mode && $encoding && stripos($content, '<?xml') === false) {
            $content = '<?xml encoding="'.$encoding.'">'.$content; // add pi node to make libxml use the correct encoding
            $xml_pi_node_added = true;
        }

        libxml_disable_entity_loader(true);
        libxml_use_internal_errors(true);

        $dom_document = new \DOMDocument('1.0', $encoding);
        $dom_document->strictErrorChecking = false;
        $dom_document->validateOnParse = false;
        $dom_document->recover = true;

        if ($this->xml_mode) {
            $dom_document->loadXML($content, $this->libxml_options);
        } else {
            $dom_document->loadHTML($content, $this->libxml_options);
        }

        $this->setDomDocument($dom_document);

        if ($xml_pi_node_added) { // pi node added, now remove it
            foreach ($dom_document->childNodes as $node) {
                if ($node->nodeType === XML_PI_NODE) {
                    $dom_document->removeChild($node);
                    break;
                }
            }
        }

        foreach ($dom_document->childNodes as $node) {
            $this->nodes[] = $node;
        }

        $this->length = \count($this->nodes);
    }
1018690
public static function create(array $content)
    {
        $access = static::arrayGet($content, 'access');
        $token = static::arrayGet($access, 'token');
        $tokenid = static::arrayGet($token, 'id');
        $expires = static::arrayGet($token, 'expires');

        try {
            $expireDate = new \DateTime($expires);
        } catch (\Exception $e) {
            throw new TokenException(sprintf('Invalid expiration date: %s', $e->getMessage()), null, $e);
        }

        $token = new static($tokenid, $expireDate);

        $catalogs = static::arrayGet($access, 'serviceCatalog');
        if (is_array($catalogs)) {
            foreach ($catalogs as $catalog) {
                $type = static::arrayGet($catalog, 'type');
                $name = static::arrayGet($catalog, 'name');
                $endpoints = static::arrayGet($catalog, 'endpoints');

                if (!is_array($endpoints)) {
                    throw new TokenException(sprintf('Invalid endpoints: %s', json_encode($endpoints)));
                }

                $token->addServiceCatalog($type, $name, $endpoints);
            }
        }

        return $token;
    }
1116810
private function processContent($content)
    {
        $this->mimetype = null;
        foreach ($content as $asset) {
            if (null === $this->mimetype) {
                $this->mimetype = $asset->mimetype;
            }

            if ($asset->mimetype !== $this->mimetype) {
                throw new Exception\RuntimeException(
                    sprintf(
                        'Asset "%s" doesn\'t have the expected mime-type "%s".',
                        $asset->getTargetPath(),
                        $this->mimetype
                    )
                );
            }

            $this->setLastModified(
                max(
                    $asset->getLastModified(),
                    $this->getLastModified()
                )
            );
            $this->setContent(
                $this->getContent() . $asset->dump()
            );
        }
    }
568757
public function setContent($content)
    {
        if (is_array($content)) {
            $this->setContentType('json');
            $this->_content = json_encode($content, JSON_PRETTY_PRINT);
        } else {
            $this->_content = (string) $content;
        }
    }
1136321
public static function toArray($content)
	{
		$doc = new DomDocument('1.0', 'UTF-8');
		$doc->loadXML($content,LIBXML_COMPACT | LIBXML_NOBLANKS | LIBXML_NOCDATA);
		$result = array();
		self::parseToArray($doc->documentElement,$result);
		return $result;
	}
852504
public function add($content)
    {
        if (is_array($content)) $paths_list = $content;
        else $paths_list = array_map(explode(',', $content));
        $report = array();

        $options = func_get_args();
        array_shift($options);

        // parse options
        if (isset($options[0]) && is_string($options[0])) {
            $options[PCLZIP_OPT_ADD_PATH] = $options[0];
            if (isset($options[1]) && is_string($options[1])) {
                $options[PCLZIP_OPT_REMOVE_PATH] = $options[1];
            }
        } else {
            $options = array_combine(
                array_filter($options, function ($v) {return (bool) $v&2;}),
                array_filter($options, function ($v) {return (bool) ($v-1)&2;})
            );
        }

        // filters initiation
        $filters = array();
        if (isset($options[PCLZIP_OPT_REMOVE_PATH])
            && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH]))
            $filters[] = function (&$key, &$value) use ($options) {
                $key = str_replace($key, null, $key);
            };
        if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH]))
            $filters[] = function (&$key, &$value) { $key = basename($key); };
        if (isset($options[PCLZIP_OPT_ADD_PATH]))
            $filters[] = function (&$key, &$value) use ($options) {
                $key = rtrim($options[PCLZIP_OPT_ADD_PATH], '/').'/'.
                    ltrim($key, '/');
            };

        if (isset($options[PCLZIP_CB_PRE_ADD])
            && is_callable($options[PCLZIP_CB_PRE_ADD]))
            $preAddCallback = $options[PCLZIP_CB_PRE_ADD];
        else $preAddCallback = function () { return 1; };

        if (isset($options[PCLZIP_CB_POST_ADD])
            && is_callable($options[PCLZIP_CB_POST_ADD]))
            $postAddCallback = $options[PCLZIP_CB_POST_ADD];
        else $postAddCallback = function () { return 1; };

        if (isset($options[PCLZIP_OPT_COMMENT]))
            $this->archive->setArchiveComment($options[PCLZIP_OPT_COMMENT]);
        if (isset($options[PCLZIP_OPT_ADD_COMMENT])) {
            $comment =
                ($comment = $this->archive->getArchiveComment() !== false)
                    ? $comment : null;
            $this->archive->setArchiveComment(
                $comment . $options[PCLZIP_OPT_ADD_COMMENT]);
        }
        if (isset($options[PCLZIP_OPT_PREPEND_COMMENT])) {
            $comment =
                ($comment = $this->archive->getArchiveComment() !== false)
                    ? $comment : null;
            $this->archive->setArchiveComment(
                $options[PCLZIP_OPT_PREPEND_COMMENT] . $comment);
        }


        // scan filesystem for files list
        $files_list = array();
        foreach ($content as $file_to_add) {
            $report[] = $this->addSnippet($file_to_add, $filters,
                $preAddCallback, $postAddCallback);

            // additional dir contents
            if (is_dir($file_to_add)) {
                $directory_contents = new \RecursiveIteratorIterator(
                    new \RecursiveDirectoryIterator(
                        $file_to_add, \RecursiveDirectoryIterator::SKIP_DOTS),
                    RecursiveIteratorIterator::SELF_FIRST);
                foreach ($directory_contents as $file_to_add) {
                    $report[] = $this->addSnippet($file_to_add, $filters,
                        $preAddCallback, $postAddCallback);
                }
            }
        }
        // ...
        return $report;
    }
42727
public function setContent($content)
    {
        $this->content = null;
        if ($content === null) {
            return;
        }

        if (TypeHandling::isSimpleType(gettype($content)) && !is_array($content)) {
            $this->content = (string)$content;
        }

        if (is_resource($content)) {
            $this->content = $content;
        }

        return $this;
    }
643409
public function load($files)
    {
        if (!is_array($files)) {
            $files = [$files];
        }
        foreach ($files as $file) {
            $file = new File($file);
            $extName = $file->extName();
            if ($extName == 'json') {
                $data = json_decode($file->readAll(), true);
                if (!$data) {
                    throw new \Exception("File '{$file}' is not valid JSON");
                }
            } else {
                $data = require (string) $file;
            }
            $this->fromArray($data);
        }
    }
1261695
public function setContent( Content $content )
    {
        foreach ( $this->handlers as $handler )
        {
            if ( $handler instanceof ContentAwareHandlerInterface )
            {
                $handler->setContent( $content );
            }
        }
    }
426437
public function load(array $data)
    {
        foreach ($data as $index => $value) {
            $this->set($index, $value);
        }
    }
1211548
private function mountContent($content)
    {
        if ($this->extended || empty($content)) {
            //No blocks or text can exists outside parent template blocks
            return;
        }

        if (is_array($content)) {
            $plainContent = '';
            foreach ($content as $token) {
                $plainContent .= $token[HtmlTokenizer::TOKEN_CONTENT];
            }

            $content = $plainContent;
        }

        $matches = $this->compiler->getSyntax()->parseBlock($content);
        if (!empty($matches)) {
            $chunks = explode($matches[0], $content);

            //We expecting first chunk to be string (before block)
            $this->mountContent(array_shift($chunks));

            $this->mountBlock(
                $matches['name'],
                isset($matches['default']) ? $matches['default'] : ''
            );

            //Rest of content (after block)
            $this->mountContent(join($matches[0], $chunks));

            return;
        }

        if (is_string(end($this->nodes))) {
            $this->nodes[key($this->nodes)] .= $content;

            return;
        }

        $this->nodes[] = $content;
    }
626054
private function checkContent($content)
    {
        if (! is_array($content) and ! is_string($content)) {
            throw new InvalidTypeException(
                'The content must be an array or string value, ' . gettype($content) . ' is given.'
            );
        }

        $this->checkSingleValuedContent($content);

        return is_array($content) ? $content : [$content];
    }
771471
protected function loadExtension($extension)
	{
		if (isset($this->classMap[$extension]))
		{
			return;
		}
		foreach ($this->supportedTypes as $imageType => $extensions)
		{
			if (in_array($extension, $extensions, true))
			{
				$this->loadType($imageType);
			}
		}
	}
519785
protected function processUrlTag(string &$content): void
    {
        $pattern = $this->getTagPattern('url(\s+(.+?))?' . preg_quote($this->endTag, '/') . '(.+?)' . preg_quote($this->startTag . '/url', '/'));
        $content = preg_replace_callback($pattern, function ($match) {
            $matchName = $match[2];
            $matchPath = $match[3];
            $urlAsset = Application::$app->getService('urlAsset');
            if ($matchName == '') {
                return $urlAsset->getUrl($matchPath);
            } else {
                return $urlAsset->getUrl($matchPath, $matchName);
            }
        }, $content);
    }