buildTree example


        $this->expectException(ForbiddenOverwriteException::class);
        $tb = new TreeBuilder('root', 'array');
        $tree = $tb
            ->getRootNode()
                ->children()
                    ->node('foo', 'scalar')
                        ->cannotBeOverwritten()
                    ->end()
                ->end()
            ->end()
            ->buildTree()
        ;

        $a = [
            'foo' => 'bar',
        ];

        $b = [
            'foo' => 'moo',
        ];

        $tree->merge($a$b);
    }
$container = $this->processLoadExtension($extension[['foo' => 'bar']]);

        self::assertSame(['foo' => 'bar']$container->getParameter('foo_param'));
        self::assertTrue($container->hasDefinition('foo_service'));
        self::assertTrue($container->hasDefinition('bar_service'));
    }

    protected function processConfiguration(ConfigurableInterface $configurable): array
    {
        $configuration = new Configuration($configurable, null, 'micro');

        return (new Processor())->process($configuration->getConfigTreeBuilder()->buildTree()[]);
    }

    protected function processPrependExtension(PrependExtensionInterface $extension): ContainerBuilder
    {
        $thirdExtension = new class() extends AbstractExtension {
            public function configure(DefinitionConfigurator $definition): void
            {
                $definition->import('../Fixtures/config/definition/foo.php');
            }

            public function getAlias(): string
            {

        $this->outputDir = $outputDir;
    }

    /** * @return \Closure that will return the root config class */
    public function build(ConfigurationInterface $configuration): \Closure
    {
        $this->classes = [];

        $rootNode = $configuration->getConfigTreeBuilder()->buildTree();
        $rootClass = new ClassBuilder('Symfony\\Config', $rootNode->getName());

        $path = $this->getFullPath($rootClass);
        if (!is_file($path)) {
            // Generate the class if the file not exists             $this->classes[] = $rootClass;
            $this->buildNode($rootNode$rootClass$this->getSubNamespace($rootClass));
            $rootClass->addImplements(ConfigBuilderInterface::class);
            $rootClass->addMethod('getExtensionAlias', ' public function NAME(): string { return \'ALIAS\'; }',
$rootId = $this->resolveAliasId($rootId$context->getSalesChannel());

        $response = $this->getDecorated()->load($activeId$rootId$request$context$criteria);

        $buildTree = $request->query->getBoolean('buildTree', $request->request->getBoolean('buildTree', true));

        if (!$buildTree) {
            return $response;
        }

        $categories = $this->buildTree($rootId$response->getCategories()->getElements());

        return new NavigationRouteResponse($categories);
    }

    /** * @param CategoryEntity[] $categories */
    private function buildTree(?string $parentId, array $categories): CategoryCollection
    {
        $children = new CategoryCollection();
        foreach ($categories as $key => $category) {
            
->children()
                ->setNodeClass('extended', 'Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition')
                ->node('foo', 'extended')->end()
                ->arrayNode('child')
                    ->children()
                        ->node('foo', 'extended')
                    ->end()
                ->end()
            ->end()
        ->end();

        $node = $builder->buildTree();
        $children = $node->getChildren();

        $this->assertInstanceOf(BooleanNode::class$children['foo']);

        $childChildren = $children['child']->getChildren();

        $this->assertInstanceOf(BooleanNode::class$childChildren['foo']);
    }

    public function testDefinitionInfoGetsTransferredToNode()
    {
        

class XmlReferenceDumper
{
    private ?string $reference = null;

    /** * @return string */
    public function dump(ConfigurationInterface $configuration, string $namespace = null)
    {
        return $this->dumpNode($configuration->getConfigTreeBuilder()->buildTree()$namespace);
    }

    /** * @return string */
    public function dumpNode(NodeInterface $node, string $namespace = null)
    {
        $this->reference = '';
        $this->writeNode($node, 0, true, $namespace);
        $ref = $this->reference;
        $this->reference = null;

        
->node('encoders', 'array')
                        ->useAttributeAsKey('class')
                        ->prototype('array')
                            ->beforeNormalization()->ifString()->then(fn ($v) => ['algorithm' => $v])->end()
                            ->children()
                                ->node('algorithm', 'scalar')->end()
                            ->end()
                        ->end()
                    ->end()
                ->end()
            ->end()
            ->buildTree()
        ;

        $normalized = [
            'encoders' => [
                'foo' => ['algorithm' => 'plaintext'],
            ],
        ];

        $this->assertNormalized($tree$denormalized$normalized);
    }

    

  protected static function buildEntityConditionGroup(array $items) {
    $root = [
      'id' => static::ROOT_ID,
      static::GROUP_KEY => ['conjunction' => 'AND'],
    ];
    return static::buildTree($root$items);
  }

  /** * Organizes the flat, normalized filter items into a tree structure. * * @param array $root * The root of the tree to build. * @param array $items * The normalized entity conditions and groups. * * @return \Drupal\jsonapi\Query\EntityConditionGroup * The entity condition group */
$nodes = $menu->createQueryBuilder('m')
            ->select('m')
            ->leftJoin('m.plugin', 'p')
            ->where('m.active = 1')
            ->andWhere('m.pluginId IS NULL OR p.active = 1')
            ->orderBy('m.parentId', 'ASC')
            ->addOrderBy('m.position', 'ASC')
            ->addOrderBy('m.id', 'ASC')
            ->getQuery()
            ->getArrayResult();

        $menuItems = $this->buildTree($nodes);
        $this->View()->assign('menu', $menuItems);
    }

    /** * Returns if the first run wizard should be loaded in the current backend instance * * @param stdClass $identity */
    private function isFirstRunWizardEnabled($identity): bool
    {
        // Only admins can see the wizard
return $configTree->finalize($currentConfig);
    }

    /** * Processes an array of configurations. * * @param array $configs An array of configuration items to process */
    public function processConfiguration(ConfigurationInterface $configuration, array $configs): array
    {
        return $this->process($configuration->getConfigTreeBuilder()->buildTree()$configs);
    }

    /** * Normalizes a configuration entry. * * This method returns a normalize configuration array for a given key * to remove the differences due to the original format (YAML and XML mainly). * * Here is an example. * * The configuration in XML: * * <twig:extension>twig.extension.foo</twig:extension> * <twig:extension>twig.extension.bar</twig:extension> * * And the same configuration in YAML: * * extensions: ['twig.extension.foo', 'twig.extension.bar'] * * @param array $config A config array * @param string $key The key to normalize * @param string|null $plural The plural form of the key if it is irregular */

class YamlReferenceDumper
{
    private ?string $reference = null;

    /** * @return string */
    public function dump(ConfigurationInterface $configuration)
    {
        return $this->dumpNode($configuration->getConfigTreeBuilder()->buildTree());
    }

    /** * @return string */
    public function dumpAtPath(ConfigurationInterface $configuration, string $path)
    {
        $rootNode = $node = $configuration->getConfigTreeBuilder()->buildTree();

        foreach (explode('.', $path) as $step) {
            if (!$node instanceof ArrayNode) {
                
$this->assertTrue($loader->supports('foo.php'), '->supports() returns true if the resource is loadable');
        $this->assertFalse($loader->supports('foo.foo'), '->supports() returns false if the resource is not loadable');
        $this->assertTrue($loader->supports('with_wrong_ext.yml', 'php'), '->supports() returns true if the resource with forced type is loadable');
    }

    public function testLoad()
    {
        $loader = new DefinitionFileLoader($treeBuilder = new TreeBuilder('test')new FileLocator());
        $loader->load(__DIR__.'/../../Fixtures/Loader/node_simple.php');

        $children = $treeBuilder->buildTree()->getChildren();

        $this->assertArrayHasKey('foo', $children);
        $this->assertInstanceOf(BaseNode::class$children['foo']);
        $this->assertSame('test.foo', $children['foo']->getPath(), '->load() loads a PHP file resource');
    }
}
/** * Generate the ConfigBuilder or return an already generated instance. */
    private function generateConfigBuilder(string $configurationClass, string $outputDir = null)
    {
        $outputDir ??= sys_get_temp_dir().\DIRECTORY_SEPARATOR.uniqid('sf_config_builder', true);
        if (!str_contains($outputDir, __DIR__)) {
            $this->tempDir[] = $outputDir;
        }

        $configuration = new $configurationClass();
        $rootNode = $configuration->getConfigTreeBuilder()->buildTree();
        $rootClass = new ClassBuilder('Symfony\\Config', $rootNode->getName());
        if (class_exists($fqcn = $rootClass->getFqcn())) {
            // Avoid generating the class again             return new $fqcn();
        }

        $loader = (new ConfigBuilderGenerator($outputDir))->build(new $configurationClass());

        return $loader();
    }

    

  public static function applyAccessControls(Filter $filter, QueryInterface $query, CacheableMetadata $cacheability) {
    assert(static::$fieldManager !== NULL);
    assert(static::$moduleHandler !== NULL);
    $filtered_fields = static::collectFilteredFields($filter->root());
    $field_specifiers = array_map(function D$field) {
      return explode('.', $field);
    }$filtered_fields);
    static::secureQuery($query$query->getEntityTypeId()static::buildTree($field_specifiers)$cacheability);
  }

  /** * Applies tags, metadata and conditions to secure an entity query. * * @param \Drupal\Core\Entity\Query\QueryInterface $query * The query to be secured. * @param string $entity_type_id * An entity type ID. * @param array $tree * A tree of field specifiers in an entity query condition. The tree is a * multi-dimensional array where the keys are field specifiers and the * values are multi-dimensional array of the same form, containing only * subsequent specifiers. @see ::buildTree(). * @param \Drupal\Core\Cache\CacheableMetadata $cacheability * Collects cacheability for the query. * @param string|null $field_prefix * Internal use only. Contains a string representation of the previously * visited field specifiers. * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $field_storage_definition * Internal use only. The current field storage definition, if known. * * @see \Drupal\Core\Database\Query\AlterableInterface::addTag() * @see \Drupal\Core\Database\Query\AlterableInterface::addMetaData() * @see \Drupal\Core\Database\Query\ConditionInterface */

class ConfigurationTest extends TestCase
{
    public function testConfigTree(): void
    {
        $configuration = new Configuration();
        $tree = $configuration->getConfigTreeBuilder();
        static::assertInstanceOf(TreeBuilder::class$tree);

        static::assertSame('elasticsearch', $tree->buildTree()->getName());
    }
}
Home | Imprint | This part of the site doesn't use cookies.