TODO: This is not efficient. The extensions should be indexed by structureType.

{@inheritdoc}
778636
public function hasExtension($structureType, $name)
    {
        $extensions = $this->getExtensions($structureType);

        return isset($extensions[$name]);
    }
1011657
protected static function buildStructures()
    {
		$perspectives = array();
		$toAdd = array();
		$sorted = \helpers_ExtensionHelper::sortByDependencies(\common_ext_ExtensionsManager::singleton()->getEnabledExtensions());
		foreach(array_keys($sorted) as $extId){
			$file = self::getStructuresFilePath($extId);
			if(!is_null($file)){
			    $xmlStructures = new \SimpleXMLElement($file, null, true);
				$extStructures = $xmlStructures->xpath("/structures/structure");
				foreach($extStructures as $xmlStructure){
				    $perspective = Perspective::fromSimpleXMLElement($xmlStructure, $extId);
				    if (!isset($perspectives[$perspective->getId()])) {
				        $perspectives[$perspective->getId()] = $perspective;
				    } else {
				        foreach ($perspective->getChildren() as $section) {
				            $perspectives[$perspective->getId()]->addSection($section);
				        }
				    }
				}
				foreach($xmlStructures->xpath("/structures/toolbar/toolbaraction") as $xmlStructure){
				    $perspective = Perspective::fromLegacyToolbarAction($xmlStructure, $extId);
			        $perspectives[$perspective->getId()] = $perspective;
			        if (isset($xmlStructure['structure'])) {
			            $toAdd[$perspective->getId()] = (string)$xmlStructure['structure'];  
			        }
				}
			}
		}
		
		foreach ($toAdd as $to => $from) {
		    if (isset($perspectives[$from]) && isset($perspectives[$to])) {
		        foreach($perspectives[$from]->getChildren() as $section) {
		            $perspectives[$to]->addSection($section);
		        }
		    } 
		}

        usort($perspectives, function ($a, $b) {
            return $a->getLevel() - $b->getLevel();
        });

		return array(
			'perspectives' => $perspectives
		);
    }
1298747
public function withAdditionalExtensions(Extension ...$exts): self
    {
        $obj = clone $this;
        $obj->_extensions = $obj->_extensions->withExtensions(...$exts);
        return $obj;
    }
1234716
protected function lexInterfaceTypeExtension(): InterfaceTypeExtensionNode
    {
        $start = $this->lexer->getToken();

        $this->expectKeyword(KeywordEnum::EXTEND);
        $this->expectKeyword(KeywordEnum::INTERFACE);

        $name       = $this->lexName();
        $directives = $this->lexDirectives();
        $fields     = $this->lexFieldsDefinition();

        if (empty($directives) && empty($fields)) {
            throw $this->unexpected();
        }

        return new InterfaceTypeExtensionNode($name, $directives, $fields, $this->createLocation($start));
    }
159378
private function initTypeExtensions()
    {
        $this->typeExtensions = [];

        foreach ($this->loadTypeExtensions() as $extension) {
            if (!$extension instanceof BlockTypeExtensionInterface) {
                throw new Exception\UnexpectedTypeException(
                    $extension,
                    'Oro\Component\Layout\BlockTypeExtensionInterface'
                );
            }

            $type = $extension->getExtendedType();

            $this->typeExtensions[$type][] = $extension;
        }
    }
3019
private function resolveObjectExtensions(HasExtensionsInterface $objectDefinition): array
    {
        $extensions = [];

        //get all extensions registered as services
        $registeredExtensions = $this->container->get(ExtensionManager::class)->getExtensions();
        foreach ($registeredExtensions as $registeredExtension) {
            foreach ($objectDefinition->getExtensions() as $extensionDefinition) {
                $extensionClass = $extensionDefinition->getClass();
                if (\get_class($registeredExtension) === $extensionClass) {
                    $extensions[$extensionClass] = $registeredExtension;
                }
            }
        }

        //get all extensions not registered as services
        foreach ($objectDefinition->getExtensions() as $extensionDefinition) {
            $class = $extensionDefinition->getClass();
            if (!isset($extensions[$class])) {
                $instance = new $class();
                if ($instance instanceof ContainerAwareInterface) {
                    $instance->setContainer($this->container);
                }

                $extensions[$class] = $instance;
            }
        }

        return array_values($extensions);
    }
444071
public function getExtensions()
    {
        if (null == $this->extensions_unserialized && null !== $this->extensions) {
            $this->extensions_unserialized = unserialize($this->extensions);
        }

        return $this->extensions_unserialized;
    }
679295
public function addExtension(ExtensionInterface $extension)
    {
        if (!in_array($extension, $this->extensions)) {
            $this->extensions[] = $extension;
            $options = Phug::getExtensionsOptions([$extension]);
            foreach ([$this, $this->getCompiler()] as $instance) {
                $instance->setOptionsRecursive($options);
            }

            $this->initCompiler();
        }
    }
476745
private function addStructureProperties(
        StructureMetadata $structureMetadata,
        StructureBehavior $document,
        VisitorInterface $visitor
    ) {
        /** @var ManagedStructure $structure */
        $structure = $document->getStructure();
        $data = $structure->toArray();
        foreach ($structureMetadata->getProperties() as $name => $property) {
            if ('title' === $name || !array_key_exists($name, $data) || $property->hasTag('sulu.rlp')) {
                continue;
            }

            $visitor->addData($name, $data[$name]);
        }
    }
94341
private function iterateStructure(ClassMap $classMap, ElementtypeStructure $structure, ElementtypeStructureNode $node)
    {
        $fieldRegistry = $this->getContainer()->get('phlexible_elementtype.field.registry');
        $data = [];

        foreach ($structure->getChildNodes($node->getDsId()) as $childNode) {
            $field = $fieldRegistry->getField($childNode->getType());
            if ($field->isField()) {
                $data[$childNode->getName()] = $childNode->getType();
            } else {
                if ($childNode->isOptional() || $childNode->isRepeatable()) {
                    $data[$childNode->getName()] = $this->toCamelCase($childNode->getName()).'[]';
                    $map = $this->iterateStructure($classMap, $structure, $childNode);
                    $classMap->add($this->toCamelCase($childNode->getName()), $map);
                } else {
                    $data = array_merge($data, $this->iterateStructure($classMap, $structure, $childNode));
                }
            }
        }

        return $data;
    }
337560
public function getExtendedType()
    {
        if (!method_exists($this, 'getExtendedTypes')) {
            throw new LogicException(sprintf('You need to implement the static getExtendedTypes() method when implementing the %s in %s.', FormTypeExtensionInterface::class, static::class));
        }

        @trigger_error(sprintf('The %s::getExtendedType() method is deprecated since Symfony 4.2 and will be removed in 5.0. Use getExtendedTypes() instead.', \get_class($this)), E_USER_DEPRECATED);

        foreach (static::getExtendedTypes() as $extendedType) {
            return $extendedType;
        }
    }
717839
public function findExtensions(): Extensions
    {
        $extensions = new Extensions();


        foreach ($this->configRepository->getPaths() as $path) {
            $composerPattern = $this->configRepository->getRootPath() . '/' . $path . '/composer.json';

            $composerFiles = $this->filesystem->glob($composerPattern);



            if ($composerFiles === false) {
                throw new ExtensionException('Error occurs when looking for extensions in the [' . $composerPattern . '] path.');
            }

            foreach ($composerFiles as $composerFile) {
                $package = $this->extensionFactory->getComposerPackage($composerFile);

                if (!in_array($package->getType(), self::$validTypes, true)) {
                    continue;
                }

                $extension = $this->extensionFactory->create($composerFile);

                if (!$this->extensionValidator->isValid($extension)) {
                    throw new ExtensionException('The extension [' . $extension->getPackage()->getName() . '] is not valid.');
                }

                $extensions->push($extension);
            }
        }

        return $extensions;
    }
750698
@Override
    public Map<String, String> getExtensionProperties() {
        List<Node> props = extension.get("property");
        Map<String, String> properties = new HashMap<String, String>();

        for (Node prop : props) {
            properties.put(prop.getAttribute("name"), prop.getText());
        }
        return properties;
    }
231112
private function initFieldType($type)
    {
        if (isset($this->fieldTypes[$type])) {
            return;
        }

        $typeInstance = false;
        foreach ($this->extensions as $extension) {
            if ($extension->hasFieldType($type)) {
                $typeInstance = $extension->getFieldType($type);
                break;
            }
        }

        if (!$typeInstance) {
            return;
        }

        $this->fieldTypes[$type] = $typeInstance;

        $ext = [];
        foreach ($this->extensions as $extension) {
            if ($extension->hasFieldTypeExtensions($type)) {
                $fieldExtensions = $extension->getFieldTypeExtensions($type);
                foreach ($fieldExtensions as $fieldExtension) {
                    $ext[] = $fieldExtension;
                }
            }
        }

        $this->fieldExtensions[$type] = $ext;
    }
512457
public function getStructureMetadata(StructureBehavior $document)
    {
        try {
            return $this->structureFactory->getStructureMetadata(
                $this->getMetadata($document)->getAlias(),
                $document->getStructureType()
            );
        } catch (StructureTypeNotFoundException $exception) {
            return;
        }
    }
733948
private function initTypeExtensions()
    {
        $this->typeExtensions = [];

        foreach ($this->loadTypeExtensions() as $extension) {
            if (!$extension instanceof BlockTypeExtensionInterface) {
                throw new UnexpectedTypeException($extension, 'Fxp\Component\Block\BlockTypeExtensionInterface');
            }

            foreach ($extension::getExtendedTypes() as $extendedType) {
                $this->typeExtensions[$extendedType][] = $extension;
            }
        }
    }
747344
protected void addCachedExtension(E extension)
    {
        if (!this.extensions.containsKey(extension.getId())) {
            // extensions
            this.extensions.put(extension.getId(), extension);

            // versions
            addCachedExtensionVersion(extension.getId().getId(), extension);
            if (!this.strictId) {
                for (String feature : extension.getFeatures()) {
                    addCachedExtensionVersion(feature, extension);
                }
            }
        }
    }