@param BlockDto[] $blocks

@return $this
485090
public function setBlocks($blocks)
    {
        foreach ($blocks as $key => $dtoData) {
            $this->blocks[$key] = new BlockDto($dtoData);
        }
    
        return $this;
    }
274828
public function setBlock(string $blockID, string $source): Isolator
    {
        if (!isset($this->phpBlocks[$blockID])) {
            throw new IsolatorException("Undefined block {$blockID}");
        }

        $this->phpBlocks[$blockID] = $source;

        return $this;
    }
21465
public function setSortsByDirective($blocks, $sort)
    {
        $sort = array_values($sort); // we're using keys as positions
        $levels = array();

        // Split arrays into levels by owner (child - parent)
        foreach ($blocks as $block) {
            $pos = array_search($block->getId(), $sort, false);
            $ownerId = ($block->getOwner()) ? $block->getOwner()->getId() : 0;
            $levels[$ownerId][$pos] = $block->getId();
        }

        foreach ($levels as &$level) {
            ksort($level);
        }

        foreach ($blocks as $block) {
            $ownerId = ($block->getOwner()) ? $block->getOwner()->getId() : 0;
            $sortedIds = $levels[$ownerId];
            $pos = array_search(array_search($block->getId(), $sortedIds), array_keys($sortedIds));
            $block->setSort($pos);

            if ($block->getOwner() && $block->getOwner()->getSuper()) {
                $superId = $block->getOwner()->getSuper()->getId();
                // See if we need to position it below an inherited block
                $pos = array_search($block->getId(), $levels[$block->getOwner()->getId()], false);
                $prevBlockId = (isset($levels[$superId]) && isset($levels[$superId][$pos - 1])) ? $levels[$superId][$pos - 1] : null;
                if ($prevBlockId !== null) {
                    $prevBlockPos = array_search($prevBlockId, array_values($levels[$superId]));
                    $block->setSortParent(($prevBlockPos !== false) ? $prevBlockPos : -1);
                } else {
                    $block->setSortParent(-1);
                }
            } else {
                $block->setSortParent(-1);
            }
        }

        return $blocks;
    }
676171
private function validateBlockTypes(array $blockTypes, array $blockDefinitions): void
    {
        foreach ($blockTypes as $identifier => $blockType) {
            if (!isset($blockDefinitions[$blockType['definition_identifier']])) {
                throw new RuntimeException(
                    sprintf(
                        'Block definition "%s" used in "%s" block type does not exist.',
                        $blockType['definition_identifier'],
                        $identifier
                    )
                );
            }
        }
    }
1180359
public function addLayoutBlock(LayoutBlockInterface $layoutBlock)
    {
        $layoutBlock->setPage($this);
        $this->layoutBlock->add($layoutBlock);

        return $this;
    }
399501
public function bind($values)
    {
        if ( ! is_array($values) ) {
            throw new InvalidException('Values assigned to a block must be an array');
        }

        // only one value
        if ( ! $this->isArrayMulti($values) ) {
            $this->bindings[] = $values;
            return $this;
        }

        // multiple values
        foreach ( $values as $line ) {
            $this->bind($line);
        }

        return $this;
    }
230758
private function filterActiveBlocks(Collection $blocks, Collection $active_blocks): Collection
    {
        return $blocks->map(static function (string $block_name) use ($active_blocks): ?ModuleBlockInterface {
            return $active_blocks->filter(static function (ModuleInterface $block) use ($block_name): bool {
                return $block->name() === $block_name;
            })->first();
        })->filter();
    }
125215
public function getMissingBlocks(Array $blocks = array())
    {
        $missing = array();
        $blocks  = $blocks ? $blocks : $this->getWroteBlocks();
        $last    = array_shift($blocks);

        if ($last['offset'] !== 0) {
            $missing[] = array('offset' => 0, 'size' => $last['offset']);
        }

        foreach ($blocks as $block) {
            if ($block['offset'] !== $last['offset'] + $last['size']) {
                $offset = $last['offset'] + $last['size'];
                $missing[] = array('offset' => $offset, 'size' => $block['offset'] - $offset);
            }
            $last = $block;
        }

        return $missing;
    }
379178
private function trackBlocks(Collection $collection, array $blocks)
    {
        $version = $collection->getVersionID();
        $buffer = 0;

        foreach ($blocks as $block) {

            if ($block instanceof Controller) {
                $controller = $block;
                $block = $controller->getBlockObject();
            }

            if ($block->getBlockTypeHandle() == BLOCK_HANDLE_STACK_PROXY) {
                if (!$controller) {
                    $controller = $block->getController();
                }

                $this->persist(
                    $controller->getStackID(),
                    $collection->getCollectionID(),
                    $version,
                    $block->getBlockID());
                $buffer++;
            }

            if ($buffer > 2) {
                $this->manager->flush();
                $buffer = 0;
            }
        }

        if ($buffer) {
            // Sometimes you just need an extra flush...
            $this->manager->flush();
        }
    }
1009849
protected function block(OutputBlock $block)
    {
        if (empty($block->lines) && empty($block->children)) {
            return;
        }

        $this->currentBlock = $block;

        $pre = $this->indentStr();

        if (! empty($block->selectors)) {
            $this->blockSelectors($block);

            $this->indentLevel++;
        }

        if (! empty($block->lines)) {
            $this->blockLines($block);
        }

        if (! empty($block->children)) {
            $this->blockChildren($block);
        }

        if (! empty($block->selectors)) {
            $this->indentLevel--;

            if (empty($block->children)) {
                $this->write($this->break);
            }

            $this->write($pre . $this->close . $this->break);
        }
    }
72812
public function addBlockType($Marker, $Type)
    {
        if (!isset($this->BlockTypes[$Marker]))
        {
            $this->BlockTypes[$Marker] = [];
        }

        $BlockTypes = &$this->BlockTypes[$Marker];
        array_unshift($BlockTypes, $Type);

        return $this;
    }
310110
public function addChild(Block $block)
    {
        $type = get_class($block);
        if (!isset($this->children[$type])) {
            $this->children[$type] = array();
        }
        $this->children[$type][] = $block;
    }
184397
public function setOperators(array $operators): self
    {
        foreach ($operators as $operator) {
            $this->validateOperator($operator);
        }
        $this->operators = $operators;

        return $this;
    }
1309320
protected function _registerBlock(&$block, array $breakpoints = null)
    {
        $this->_blocks[] = array($breakpoints, $this->_minify($block));
        $block = '';
    }
1114315
public function generateDocblock() {
		$docblock = $this->getDocblock();
		$docblock->setShortDescription($this->getDescription());
		$docblock->setLongDescription($this->getLongDescription());

		foreach ($this->methods as $method) {
			$method->generateDocblock();
		}

		return $this;
	}
504171
public function replaceBlock(BlockElement $block, array $children = null)
    {
        if ($parent = $block->getParent()) {
            foreach (array_reverse($children ?: $block->getChildren()) as $child) {
                $parent->insertAfter($block, $child);
            }
            $previous = $block->getPreviousSibling();
            if ($previous instanceof TextElement) {
                $previous->setEnd(true);
            }
            $block->remove();
        }
    }
1087287
public function block($enabled = null)
    {
        if (is_null($enabled)) {
            $enabled = !$this->isBlock;
        }

        $this->isBlock = $enabled;

        return $this;
    }