lib/classes/Swift/Mime/SimpleMimeEntity.php
public function setChildren(array $children, $compoundLevel = null)
    {
        // TODO: Try to refactor this logic
        $compoundLevel = $compoundLevel ?? $this->getCompoundLevel($children);
        $immediateChildren = [];
        $grandchildren = [];
        $newContentType = $this->userContentType;

        foreach ($children as $child) {
            $level = $this->getNeededChildLevel($child, $compoundLevel);
            if (empty($immediateChildren)) {
                //first iteration
                $immediateChildren = [$child];
            } else {
                $nextLevel = $this->getNeededChildLevel($immediateChildren[0], $compoundLevel);
                if ($nextLevel == $level) {
                    $immediateChildren[] = $child;
                } elseif ($level < $nextLevel) {
                    // Re-assign immediateChildren to grandchildren
                    $grandchildren = array_merge($grandchildren, $immediateChildren);
                    // Set new children
                    $immediateChildren = [$child];
                } else {
                    $grandchildren[] = $child;
                }
            }
        }

        if ($immediateChildren) {
            $lowestLevel = $this->getNeededChildLevel($immediateChildren[0], $compoundLevel);

            // Determine which composite media type is needed to accommodate the
            // immediate children
            foreach ($this->compositeRanges as $mediaType => $range) {
                if ($lowestLevel > $range[0] && $lowestLevel <= $range[1]) {
                    $newContentType = $mediaType;

                    break;
                }
            }

            // Put any grandchildren in a subpart
            if (!empty($grandchildren)) {
                $subentity = $this->createChild();
                $subentity->setNestingLevel($lowestLevel);
                $subentity->setChildren($grandchildren, $compoundLevel);
                array_unshift($immediateChildren, $subentity);
            }
        }

        $this->immediateChildren = $immediateChildren;
        $this->children = $children;
        $this->setContentTypeInHeaders($newContentType);
        $this->fixHeaders();
        $this->sortChildren();

        return $this;
    }
public function setChildren(array $children, $compoundLevel = null)
    {
        // TODO: Try to refactor this logic
        $compoundLevel = $compoundLevel ?? $this->getCompoundLevel($children);
        $immediateChildren = [];
        $grandchildren = [];
        $newContentType = $this->userContentType;

        foreach ($children as $child) {
            $level = $this->getNeededChildLevel($child, $compoundLevel);
            if (empty($immediateChildren)) {
                //first iteration
                $immediateChildren = [$child];
            } else {
                $nextLevel = $this->getNeededChildLevel($immediateChildren[0], $compoundLevel);
                if ($nextLevel == $level) {
                    $immediateChildren[] = $child;
                } elseif ($level < $nextLevel) {
                    // Re-assign immediateChildren to grandchildren
                    $grandchildren = array_merge($grandchildren, $immediateChildren);
                    // Set new children
                    $immediateChildren = [$child];
                } else {
                    $grandchildren[] = $child;
                }
            }
        }

        if ($immediateChildren) {
            $lowestLevel = $this->getNeededChildLevel($immediateChildren[0], $compoundLevel);

            // Determine which composite media type is needed to accommodate the
            // immediate children
            foreach ($this->compositeRanges as $mediaType => $range) {
                if ($lowestLevel > $range[0] && $lowestLevel <= $range[1]) {
                    $newContentType = $mediaType;

                    break;
                }
            }

            // Put any grandchildren in a subpart
            if (!empty($grandchildren)) {
                $subentity = $this->createChild();
                $subentity->setNestingLevel($lowestLevel);
                $subentity->setChildren($grandchildren, $compoundLevel);
                array_unshift($immediateChildren, $subentity);
            }
        }

        $this->immediateChildren = $immediateChildren;
        $this->children = $children;
        $this->setContentTypeInHeaders($newContentType);
        $this->fixHeaders();
        $this->sortChildren();

        return $this;
    }
public function setChildren ( array $ children , $ compoundLevel = null ) { // TODO: Try to refactor this logic $ compoundLevel = $ compoundLevel ?? $ this -> getCompoundLevel ( $ children ) ; $ immediateChildren = [ ] ; $ grandchildren = [ ] ; $ newContentType = $ this -> userContentType ; foreach ( $ children as $ child ) { $ level = $ this -> getNeededChildLevel ( $ child , $ compoundLevel ) ; if ( empty ( $ immediateChildren ) ) { //first iteration $ immediateChildren = [ $ child ] ; } else { $ nextLevel = $ this -> getNeededChildLevel ( $ immediateChildren [ 0 ] , $ compoundLevel ) ; if ( $ nextLevel == $ level ) { $ immediateChildren [ ] = $ child ; } elseif ( $ level < $ nextLevel ) { // Re-assign immediateChildren to grandchildren $ grandchildren = array_merge ( $ grandchildren , $ immediateChildren ) ; // Set new children $ immediateChildren = [ $ child ] ; } else { $ grandchildren [ ] = $ child ; } } } if ( $ immediateChildren ) { $ lowestLevel = $ this -> getNeededChildLevel ( $ immediateChildren [ 0 ] , $ compoundLevel ) ; // Determine which composite media type is needed to accommodate the // immediate children foreach ( $ this -> compositeRanges as $ mediaType => $ range ) { if ( $ lowestLevel > $ range [ 0 ] && $ lowestLevel <= $ range [ 1 ] ) { $ newContentType = $ mediaType ; break ; } } // Put any grandchildren in a subpart if ( ! empty ( $ grandchildren ) ) { $ subentity = $ this -> createChild ( ) ; $ subentity -> setNestingLevel ( $ lowestLevel ) ; $ subentity -> setChildren ( $ grandchildren , $ compoundLevel ) ; array_unshift ( $ immediateChildren , $ subentity ) ; } } $ this -> immediateChildren = $ immediateChildren ; $ this -> children = $ children ; $ this -> setContentTypeInHeaders ( $ newContentType ) ; $ this -> fixHeaders ( ) ; $ this -> sortChildren ( ) ; return $ this ; }
Set all children of this entity.

@param Swift_Mime_SimpleMimeEntity[] $children
@param int                           $compoundLevel For internal use only

@return $this
Set all children of this entity .