Send the list of all block values to Livedocx service to prepare the merging

@param array $blocks

@return Livedocx

@throws DeclarationException
438757
protected function declareListOfBlocks($blocks)
    {
        foreach ( $blocks as $block ) {
            try {
                $this->getSoapClient()->SetBlockFieldValues(array(
                    'blockName'        => $block->getName() ,
                    'blockFieldValues' => $this->getSoapClient()->convertArray($block->retrieveValues())
                ));
            } catch ( SoapException $ex ) {
                $s = '';
                if ( ! is_null($block->getName()) ) {
                    $s.= " (block: {$block->getName()})";
                }
                throw new DeclarationException("Error while sending blocks informations to Livedocx service" . $s , $ex);
            }
        }
        return $this;
    }
1305444
public function writeBlocks( $blocks )
	{
		foreach( $blocks as $name => $content )
		{
			$list[]	= str_replace( "{#name#}", $name, $this->patternSection );
			$list[]	= $content;
			$list[]	= "";
		}
		$file	= new FS_File_Writer( $this->fileName );
		return $file->writeArray( $list );
	}
814956
protected function _setBlock($block)
    {
        if ($block !== null && !($block instanceof BlockInterface)) {
            throw $this->_createInvalidArgumentException(
                $this->__('Invalid block'),
                null,
                null,
                $block
            );
        }

        $this->block = $block;
    }
360808
private static void mergeBlocks(List< Block > blocks) {
        for (int i = 1; i < blocks.size(); i++) {
            Block b1 = blocks.get(i - 1);
            Block b2 = blocks.get(i);
            if ((b1.mode == b2.mode) &&
                (b1.mode != EncodingMode.NUM || b1.length + b2.length <= MAX_NUMERIC_COMPACTION_BLOCK_SIZE)) {
                b1.length += b2.length;
                blocks.remove(i);
                i--;
            }
        }
    }
1278376
public static function executeStarts(
        iterable $indexes,
        array $blocks,
        ContextStorageInterface $context,
        ErrorAggregatorInterface $errors
    ): bool {
        $allOk = true;

        foreach ($indexes as $index) {
            $context->setCurrentBlockId($index);
            $block      = $blocks[$index];
            $errorsInfo = static::executeProcedureStart($block, $context);
            if (empty($errorsInfo) === false) {
                static::addBlockErrors($errorsInfo, $context, $errors);
                $allOk = false;
            }
        }

        return $allOk;
    }
629736
private function internalDisableTranslations(PersistenceBlock $block): PersistenceBlock
    {
        $block = $this->blockHandler->updateBlock(
            $block,
            BlockUpdateStruct::fromArray(
                [
                    'isTranslatable' => false,
                ]
            )
        );

        foreach ($block->availableLocales as $locale) {
            if ($locale !== $block->mainLocale) {
                $block = $this->blockHandler->deleteBlockTranslation(
                    $block,
                    $locale
                );
            }
        }

        foreach ($this->blockHandler->loadChildBlocks($block) as $childBlock) {
            $this->internalDisableTranslations($childBlock);
        }

        return $block;
    }
1261421
private static function getBlocksWithEnd(array $serializedBlocks): array
    {
        $blocksWithEnd = BlockSerializer::unserializeBlocksWithEnd($serializedBlocks);

        // check result contain only block indexes and the blocks are procedures
        assert(
            is_array($blocks = static::getBlocks($serializedBlocks)) &&
            static::debugCheckBlocksExist($blocksWithEnd, $blocks, BlockSerializer::TYPE__PROCEDURE)
        );

        return $blocksWithEnd;
    }
1326085
public function setBlock($block)
    {
        $block = strtolower($block);
        if (!in_array($block, array('yes', 'no'))) {
            /**
             * @see Zend_Feed_Builder_Exception
             */
            require_once 'Zend/Feed/Builder/Exception.php';
            throw new Zend_Feed_Builder_Exception("you have to set yes or no to the itunes block property");
        }
        $this->offsetSet('block', $block);
        return $this;
    }
213731
public function sortBlocksByDirective($blocks, $sort)
    {
        array_walk($blocks, function ($block) use ($sort) {
            $block->setSort(array_search($block->getId(), $sort));
        });

        return $blocks;
    }
223479
public function transform($block)
    {
        $block = $this->entityToArray(Block::class, $block);
        return [
            'id'          => $this->setNullableValue($block['id']),
            'type'        => $block['type'],
            'region'      => $block['region'],
            'filter'      => $block['filter'],
            'options'     => $block['options'],
            'theme'       => $block['theme'],
            'weight'      => (int) $block['weight'],
            'isActive'    => (bool) $block['is_active'],
            'isCacheable' => (bool) $block['is_cacheable'],
            'createdAt'   => $block['created_at'],
            'updatedAt'   => $block['updated_at']
        ];
    }
547262
private function useBlock() {
    $node = new UseDeclarationBlockNode();
    $node->addChild($this->_use());
    while ($this->currentType === T_USE) {
      $this->matchHidden($node);
      $node->addChild($this->_use());
    }
    return $node;
  }
1309320
protected function _registerBlock(&$block, array $breakpoints = null)
    {
        $this->_blocks[] = array($breakpoints, $this->_minify($block));
        $block = '';
    }
316674
protected function add(array $values)
    {
        $values =
            $this->dispatchBeforeOperationEvent(
                '\RedKiteLabs\RedKiteCms\RedKiteCmsBundle\Core\Event\Content\Block\BeforeBlockAddingEvent',
                BlockEvents::BEFORE_ADD_BLOCK,
                $values,
                'exception_block_adding_aborted'
            );

        $this->validator->checkEmptyParams($values);
        $requiredParameters = array("PageId" => "", "LanguageId" => "", "SlotName" => "");
        $this->validator->checkRequiredParamsExists($requiredParameters, $values);

        // When the Content is null the dafault text is inserted
        if (!array_key_exists('Content', $values)) {
            $defaults = $this->getDefaultValue();
            if (!is_array($defaults)) {
                $exception = array(
                    'message' => 'exception_method_returns_invalid_value',
                    'parameters' => array(
                        '%className%' => get_class($this),
                    ),
                );
                throw new General\InvalidArgumentTypeException(json_encode($exception));
            }

            $mergedValues = array_merge($values, $defaults);
            $availableOptions = array(
                'Content' => '',
                'InternalJavascript' => '',
                'ExternalJavascript' => '',
                'InternalStylesheet' => '',
                'ExternalStylesheet' => '',
            );
            $this->validator->checkOnceValidParamExists($availableOptions, $mergedValues);
            $values = $mergedValues;
        }

        try {
            $this->blockRepository->startTransaction();

            // Saves the content
            if (null === $this->alBlock) {
                $className = $this->blockRepository->getRepositoryObjectClassName();
                $this->alBlock = new $className();
            }

            $values = $this->checkCreatedAt($values);
            $result = $this->blockRepository
                    ->setRepositoryObject($this->alBlock)
                    ->save($values);
            if (false !== $result) {
                $this->blockRepository->commit();
                $this->eventsHandler
                     ->createEvent(BlockEvents::AFTER_ADD_BLOCK, '\RedKiteLabs\RedKiteCms\RedKiteCmsBundle\Core\Event\Content\Block\AfterBlockAddedEvent', array($this))
                     ->dispatch();

                return $result;
            }

            $this->blockRepository->rollBack();

            return $result;
        } catch (\Exception $e) {
            if (isset($this->blockRepository) && $this->blockRepository !== null) {
                $this->blockRepository->rollBack();
            }

            throw $e;
        }
    }
50548
public function publish($blocks)
    {
        if ($blocks instanceof PersistentCollection) {
            $blocks = $blocks->getValues();
        }

        if (!$blocks ||
            (is_array($blocks) && !count($blocks))) {
            return;
        }

        if (! is_array($blocks)) {
            $blocks = [$blocks];
        }

        $this->disableRevisionListener();

        $deletes = [];

        foreach ($blocks as $block) {
            if (null !== $revision = $this->revisionManager->getDraftRevision($block)) {
                try {
                    $this->revisionManager->revert($block, $revision);
                } catch (DeletedException $e) {
                    // $this->em->remove($block);
                    $deletes[] = $block;
                }
            }
        }

        $this->em->flush();

        // Cycle through all deleted blocks to perform cascades manually 
        foreach ($deletes as $block) {
            if ($block instanceof CompositeBlock) {
                $descendants = $this->findDescendants($block, false);
            } else {
                $descendants = [$block];
            }

            foreach ($descendants as $descendant) {
                $descendant->setDeletedAt(new \DateTime);
                $this->em->flush($descendant);
            }
        }

        $cacheDriver = $this->em->getConfiguration()->getResultCacheImpl();
        $cacheDriver->deleteAll();

        $this->enableRevisionListener();
    }
1233653
protected function generateDocBlock(array $columns): void
  {
    $this->codeStore->append('/**');
    $this->codeStore->append(' * @todo describe routine', false);
    $this->codeStore->append(' * ', false);

    $padding = $this->getMaxColumnLength($columns);
    $format  = sprintf(' * @param p_%%-%ds @todo describe parameter', $padding);
    foreach ($columns as $column)
    {
      $this->codeStore->append(sprintf($format, $column['column_name']), false);
    }

    $this->codeStore->append(' */', false);
  }
1170797
public function add(Block ...$blocks)
    {
        foreach ($blocks as $block) {
            $this->blocks[] = $block;
        }

        return $this;
    }
227912
protected function compileDirective(Block $block)
    {
        $s = '@' . $block->name;

        if (! empty($block->value)) {
            $s .= ' ' . $this->compileValue($block->value);
        }

        if ($block->name === 'keyframes' || substr($block->name, -10) === '-keyframes') {
            $this->compileKeyframeBlock($block, [$s]);
        } else {
            $this->compileNestedBlock($block, [$s]);
        }
    }