src/Form/Hydrator/Strategy/TreeSelectStrategy.php
private function findLeaf(NodeInterface $leaf, $value)
    {
        $parts = is_array($value) ? $value : explode($this->shouldUseNames() ? ' | ': '-', $value);
        $value = array_shift($parts);

        /* @var NodeInterface $item */
        foreach ($leaf->getChildren() as $item) {
            $compare = $this->shouldUseNames() ? $item->getName() : $item->getValue();
            if ($compare == $value) {
                if (count($parts)) {
                    return $this->findLeaf($item, $parts);
                }

                return $item;
            }
        }

        if ($value && $this->shouldCreateLeafs()) {
            $nodeClass = get_class($leaf);
            $node = new $nodeClass($value);
            $leaf->addChild($node);
            if (count($parts)) {
                return $this->findLeaf($node, $parts);
            }

            return $node;
        }

        return null;
    }
private function findLeaf(NodeInterface $leaf, $value)
    {
        $parts = is_array($value) ? $value : explode($this->shouldUseNames() ? ' | ': '-', $value);
        $value = array_shift($parts);

        /* @var NodeInterface $item */
        foreach ($leaf->getChildren() as $item) {
            $compare = $this->shouldUseNames() ? $item->getName() : $item->getValue();
            if ($compare == $value) {
                if (count($parts)) {
                    return $this->findLeaf($item, $parts);
                }

                return $item;
            }
        }

        if ($value && $this->shouldCreateLeafs()) {
            $nodeClass = get_class($leaf);
            $node = new $nodeClass($value);
            $leaf->addChild($node);
            if (count($parts)) {
                return $this->findLeaf($node, $parts);
            }

            return $node;
        }

        return null;
    }
private function findLeaf ( NodeInterface $ leaf , $ value ) { $ parts = is_array ( $ value ) ? $ value : explode ( $ this -> shouldUseNames ( ) ? ' | ' : '-' , $ value ) ; $ value = array_shift ( $ parts ) ; /* @var NodeInterface $item */ foreach ( $ leaf -> getChildren ( ) as $ item ) { $ compare = $ this -> shouldUseNames ( ) ? $ item -> getName ( ) : $ item -> getValue ( ) ; if ( $ compare == $ value ) { if ( count ( $ parts ) ) { return $ this -> findLeaf ( $ item , $ parts ) ; } return $ item ; } } if ( $ value && $ this -> shouldCreateLeafs ( ) ) { $ nodeClass = get_class ( $ leaf ) ; $ node = new $ nodeClass ( $ value ) ; $ leaf -> addChild ( $ node ) ; if ( count ( $ parts ) ) { return $ this -> findLeaf ( $ node , $ parts ) ; } return $ node ; } return null ; }
Find a leaf with a concrete value in the tree.

@param NodeInterface $leaf
@param string        $value

@return NodeInterface|null
Find a leaf with a concrete value in the tree .