Helper function to build the content array.

@param array $sender
The sender array.
@param array $destination
The destination array.
@param array $parcel
The parcel array.
@param array $options
The options array.

@return array
The content array.
349080
protected function buildShipmentArray(
        array $sender,
        array $destination,
        array $parcel,
        array $options = []
    ) {
        $this->formatPostalCode($sender['address-details']['postal-zip-code']);
        $this->formatPostalCode($destination['address-details']['postal-zip-code']);
        $shipment_info = [
            'requested-shipping-point' => $destination['address-details']['postal-zip-code'],
            'cpc-pickup-indicator' => true,
            'delivery-spec' => [
                'service-code' => $parcel['service_code'],
                'sender' => $sender,
                'destination' => $destination,
                'parcel-characteristics' => $parcel,
                'preferences' => [
                    'show-packing-instructions' => $options['packing_instructions'] ?? true,
                ],
                'notification' => [],
                'settlement-info' => [
                    'contract-id' => '',
                    'intended-method-of-payment' => 'Account',
                ],
            ],
        ];

        if (!empty($options['option_codes'])) {
            $shipment_info['options']['option'] = $this->parseOptionCodes($options);
        }

        return $shipment_info;
    }
85781
function generatePackage( $package, $options )
    {
        $this->Package = $package;
        $remoteIDArray = array();
        $this->NodeIDArray = array_unique( $this->NodeIDArray );
        foreach( $this->NodeIDArray as $nodeID )
        {
            $this->NodeObjectArray[(string)$nodeID] = eZContentObjectTreeNode::fetch( $nodeID );
        }

        foreach( $this->RootNodeIDArray as $nodeID )
        {
            $this->RootNodeObjectArray[(string)$nodeID] = eZContentObjectTreeNode::fetch( $nodeID );
        }

        $this->generateObjectArray( $options['node_assignment'] );

        $classIDArray = false;
        if ( $options['include_classes'] )
        {
            $remoteIDArray['class'] = array();
            $classIDArray = $this->generateClassIDArray();

            foreach ( $classIDArray as $classID )
            {
                eZContentClassPackageHandler::addClass( $package, $classID );
            }
        }

        $dom = new DOMDocument( '1.0', 'utf-8' );
        $packageRoot = $dom->createElement( 'content-object' );
        $dom->appendChild( $packageRoot );

        $objectListDOMNode = $this->createObjectListNode( $options );
        $importedObjectListDOMNode = $dom->importNode( $objectListDOMNode, true );
        $packageRoot->appendChild( $importedObjectListDOMNode );

        $overrideSettingsArray = false;
        $templateFilenameArray = false;
        if ( $options['include_templates'] )
        {
            $overrideSettingsListNode = $this->generateOverrideSettingsArray( $options['site_access_array'], $options['minimal_template_set'] );
            $importedOverrideSettingsListNode = $dom->importNode( $overrideSettingsListNode, true );
            $packageRoot->appendChild( $importedOverrideSettingsListNode );

            $designTemplateListNode = $this->generateTemplateFilenameArray();
            $importedDesignTemplateListNode = $dom->importNode( $designTemplateListNode, true );
            $packageRoot->appendChild( $importedDesignTemplateListNode );

            $fetchAliasListNode = $this->generateFetchAliasArray();
            $importedFetchAliasListNode = $dom->importNode( $fetchAliasListNode, true );
            $packageRoot->appendChild( $importedFetchAliasListNode );
        }

        $siteAccessListDOMNode = $this->createSiteAccessListNode( $options );
        $importedSiteAccessListDOMNode = $dom->importNode( $siteAccessListDOMNode, true );
        $packageRoot->appendChild( $importedSiteAccessListDOMNode );

        $topNodeListDOMNode = $this->createTopNodeListDOMNode( $options );
        $importedTopNodeListDOMNode = $dom->importNode( $topNodeListDOMNode, true );
        $packageRoot->appendChild( $importedTopNodeListDOMNode );

        //$filename = substr( md5( mt_rand() ), 0, 8 );
        $filename = 'contentobjects';
        $this->Package->appendInstall( 'ezcontentobject', false, false, true,
                                       $filename, $this->contentObjectDirectory(),
                                       array( 'content' => $packageRoot ) );
        $this->Package->appendInstall( 'ezcontentobject', false, false, false,
                                       $filename, $this->contentObjectDirectory(),
                                       array( 'content' => false ) );
    }
981301
private void createAckMailboxesIfNeeded(final Set<Integer> localPartitions) {
        m_mailboxesZKPath = VoltZK.exportGenerations + "/" + "mailboxes";
        if (m_mbox == null) {
            m_mbox = new LocalMailbox(m_messenger) {
                @Override
                public void deliver(VoltMessage message) {
                    if (message instanceof BinaryPayloadMessage) {
                        BinaryPayloadMessage bpm = (BinaryPayloadMessage)message;
                        ByteBuffer buf = ByteBuffer.wrap(bpm.m_payload);
                        final byte msgType = buf.get();
                        final int partition = buf.getInt();
                        final Map<String, ExportDataSource> partitionSources = m_dataSourcesByPartition.get(partition);

                        final int length = buf.getInt();
                        byte stringBytes[] = new byte[length];
                        buf.get(stringBytes);
                        String tableName = new String(stringBytes, Constants.UTF8ENCODING);
                        if (partitionSources == null) {
                            if (!m_removingPartitions.contains(partition)) {
                                exportLog.error("Received an export message " + msgType + " for partition " + partition +
                                        " which does not exist on this node");
                            }
                            return;
                        }
                        final ExportDataSource eds = partitionSources.get(tableName);
                        if (eds == null) {
                            // For dangling buffers
                            if (msgType == ExportManager.TAKE_MASTERSHIP) {
                                final long requestId = buf.getLong();
                                if (exportLog.isDebugEnabled()) {
                                    exportLog.debug("Received TAKE_MASTERSHIP message(" + requestId +
                                            ") for a stream that no longer exists from " +
                                            CoreUtils.hsIdToString(message.m_sourceHSId) +
                                            " to " + CoreUtils.hsIdToString(m_mbox.getHSId()));
                                }
                                sendDummyTakeMastershipResponse(message.m_sourceHSId, requestId, partition, stringBytes);
                            } else {
                                exportLog.warn("Received export message " + msgType + " for partition " +
                                        partition + " source " + tableName +
                                        " which does not exist on this node, sources = " + partitionSources);
                            }
                            return;
                        }

                        if (msgType == ExportManager.RELEASE_BUFFER) {
                            final long seqNo = buf.getLong();
                            final long catalogVersion = buf.getInt();
                            try {
                                if (exportLog.isDebugEnabled()) {
                                    exportLog.debug("Received RELEASE_BUFFER message for " + eds.toString() +
                                            " , sequence number: " + seqNo + ", catalogVersion: " + catalogVersion +
                                            " from " + CoreUtils.hsIdToString(message.m_sourceHSId) +
                                            " to " + CoreUtils.hsIdToString(m_mbox.getHSId()));
                                }
                                eds.remoteAck(seqNo);
                            } catch (RejectedExecutionException ignoreIt) {
                                // ignore it: as it is already shutdown
                            }
                        } else if (msgType == ExportManager.GIVE_MASTERSHIP) {
                            final long ackSeqNo = buf.getLong();
                            try {
                                if (exportLog.isDebugEnabled()) {
                                    exportLog.debug("Received GIVE_MASTERSHIP message for " + eds.toString() +
                                            " with sequence number:" + ackSeqNo +
                                            " from " + CoreUtils.hsIdToString(message.m_sourceHSId) +
                                            " to " + CoreUtils.hsIdToString(m_mbox.getHSId()));
                                }
                                eds.remoteAck(ackSeqNo);
                            } catch (RejectedExecutionException ignoreIt) {
                                // ignore it: as it is already shutdown
                            }
                            eds.acceptMastership();
                        } else if (msgType == ExportManager.GAP_QUERY) {
                            final long requestId = buf.getLong();
                            long gapStart = buf.getLong();
                            if (exportLog.isDebugEnabled()) {
                                exportLog.debug("Received GAP_QUERY message(" + requestId +
                                        ") for " + eds.toString() +
                                        " from " + CoreUtils.hsIdToString(message.m_sourceHSId) +
                                        " to " + CoreUtils.hsIdToString(m_mbox.getHSId()));
                            }
                            eds.handleQueryMessage(message.m_sourceHSId, requestId, gapStart);
                        } else if (msgType == ExportManager.QUERY_RESPONSE) {
                            final long requestId = buf.getLong();
                            final long lastSeq = buf.getLong();
                            if (exportLog.isDebugEnabled()) {
                                exportLog.debug("Received QUERY_RESPONSE message(" + requestId +
                                        "," + lastSeq + ") for " + eds.toString() +
                                        " from " + CoreUtils.hsIdToString(message.m_sourceHSId) +
                                        " to " + CoreUtils.hsIdToString(m_mbox.getHSId()));
                            }
                            eds.handleQueryResponse(message.m_sourceHSId, requestId, lastSeq);
                        } else if (msgType == ExportManager.TAKE_MASTERSHIP) {
                            final long requestId = buf.getLong();
                            if (exportLog.isDebugEnabled()) {
                                exportLog.debug("Received TAKE_MASTERSHIP message(" + requestId +
                                        ") for " + eds.toString() +
                                        " from " + CoreUtils.hsIdToString(message.m_sourceHSId) +
                                        " to " + CoreUtils.hsIdToString(m_mbox.getHSId()));
                            }
                            eds.handleTakeMastershipMessage(message.m_sourceHSId, requestId);
                        } else if (msgType == ExportManager.TAKE_MASTERSHIP_RESPONSE) {
                            final long requestId = buf.getLong();
                            if (exportLog.isDebugEnabled()) {
                                exportLog.debug("Received TAKE_MASTERSHIP_RESPONSE message(" + requestId +
                                        ") for " + eds.toString() +
                                        " from " + CoreUtils.hsIdToString(message.m_sourceHSId) +
                                        " to " + CoreUtils.hsIdToString(m_mbox.getHSId()));
                            }
                            eds.handleTakeMastershipResponse(message.m_sourceHSId, requestId);
                        } else {
                            exportLog.error("Receive unsupported message type " + message + " in export subsystem");
                        }
                    } else {
                        exportLog.error("Receive unexpected message " + message + " in export subsystem");
                    }
                }
            };
            m_messenger.createMailbox(null, m_mbox);
        }

        // Rejoining node may receives gap query message before childUpdating thread gets back result,
        // in case it couldn't find local mailbox to send back response, add local mailbox to the list first.
        for (Integer partition : localPartitions) {
            updateAckMailboxes(partition, null);
        }
        // Update latest replica list to each data source.
        updateReplicaList(localPartitions);
    }
747963
private function mergeArray($destinationArray, $sourceArray)
    {
        $result = array();
        foreach ($destinationArray as $key => $destinationArrayItem) {
            if (is_int($key)) {
                $result[] = $destinationArrayItem;
            } else {
                $result[$key] = $destinationArrayItem;
            }
        }

        foreach ($sourceArray as $key => $sourceArrayItem) {
            if (is_int($key)) {
                $result[] = $sourceArrayItem;
            } else {
                $result[$key] = $this->run($result[$key], $sourceArrayItem);
            }
        }

        return $result;
    }
488715
public function ModerationController_MergeDiscussions_Create($Sender) {
      $Session = Gdn::Session();
      $Sender->Form = new Gdn_Form();
      $Sender->Title(T('Merge Discussions'));

      $DiscussionModel = new DiscussionModel();
      $CheckedDiscussions = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedDiscussions', array());
      if (!is_array($CheckedDiscussions))
         $CheckedDiscussions = array();
       
      $DiscussionIDs = $CheckedDiscussions;
      $Sender->SetData('DiscussionIDs', $DiscussionIDs);
      $CountCheckedDiscussions = count($DiscussionIDs);
      $Sender->SetData('CountCheckedDiscussions', $CountCheckedDiscussions);
      $Discussions = $DiscussionModel->SQL->WhereIn('DiscussionID', $DiscussionIDs)->Get('Discussion')->ResultArray();
      $Sender->SetData('Discussions', $Discussions);
      
      // Perform the merge
      if ($Sender->Form->AuthenticatedPostBack()) {
         // Create a new discussion record
         $MergeDiscussion = FALSE;
         $MergeDiscussionID = $Sender->Form->GetFormValue('MergeDiscussionID');
         foreach ($Discussions as $Discussion) {
            if ($Discussion['DiscussionID'] == $MergeDiscussionID) {
               $MergeDiscussion = $Discussion;
               break;
            }
         }
         if ($MergeDiscussion) {
            $ErrorCount = 0;
            
            // Verify that the user has permission to perform the merge.
            $Category = CategoryModel::Categories($MergeDiscussion['CategoryID']);
            if ($Category && !$Category['PermsDiscussionsEdit'])
               throw PermissionException('Vanilla.Discussions.Edit');
            
            // Assign the comments to the new discussion record
            $DiscussionModel->SQL
               ->Update('Comment')
               ->Set('DiscussionID', $MergeDiscussionID)
               ->WhereIn('DiscussionID', $DiscussionIDs)
               ->Put();
               
            $CommentModel = new CommentModel();
            foreach ($Discussions as $Discussion) {
               if ($Discussion['DiscussionID'] == $MergeDiscussionID)
                  continue;
               
               // Create a comment out of the discussion.
               $Comment = ArrayTranslate($Discussion, array('Body', 'Format', 'DateInserted', 'InsertUserID', 'InsertIPAddress', 'DateUpdated', 'UpdateUserID', 'UpdateIPAddress', 'Attributes', 'Spam', 'Likes', 'Abuse'));
               $Comment['DiscussionID'] = $MergeDiscussionID;
               
               $CommentModel->Validation->Results(TRUE);
               $CommentID = $CommentModel->Save($Comment);
               if ($CommentID) {
                  // Move any attachments (FileUpload plugin awareness)
                  if (class_exists('MediaModel')) {
                     $MediaModel = new MediaModel();
                     $MediaModel->Reassign($Discussion['DiscussionID'], 'discussion', $CommentID, 'comment');
                  }
                  
                  // Delete discussion that was merged
                  $DiscussionModel->Delete($Discussion['DiscussionID']);                  
               } else {
                  $Sender->InformMessage($CommentModel->Validation->ResultsText());
                  $ErrorCount++;
               }
            }
            // Update counts on all affected discussions.
            $CommentModel->UpdateCommentCount($MergeDiscussionID);
            $CommentModel->RemovePageCache($MergeDiscussionID);
   
            // Clear selections
            Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedDiscussions', FALSE);
            ModerationController::InformCheckedDiscussions($Sender);
            if ($ErrorCount == 0)
               $Sender->RedirectUrl = Url("/discussion/$MergeDiscussionID/".Gdn_Format::Url($MergeDiscussion['Name']));
         }
      }
      
      $Sender->Render('MergeDiscussions', '', 'plugins/SplitMerge');
   }
199254
public function serialize(Subject $subject, array $options = [])
    {
        $first = $this->messageRepo->findOneBy([
          'subject' => $subject,
          'first' => true,
        ]);

        return [
          'id' => $subject->getUuid(),
          'forum' => [
            'id' => $subject->getForum()->getUuid(),
          ],
          'tags' => $this->serializeTags($subject),
          'content' => $first ? $first->getContent() : null,
          'title' => $subject->getTitle(),
          'meta' => $this->serializeMeta($subject, $options),
          'restrictions' => $this->serializeRestrictions($subject, $options),
          'poster' => $subject->getPoster() ? $this->fileSerializer->serialize($subject->getPoster()) : null,
        ];
    }
191564
public function createAlternativeContentPart(Message $message, MessagePart $contentPart)
    {
        $altPart = $this->partBuilderFactory->newPartBuilder($this->mimePartFactory)->createMessagePart();
        $this->setMimeHeaderBoundaryOnPart($altPart, 'multipart/alternative');
        $message->removePart($contentPart);
        $message->addChild($altPart, 0);
        $altPart->addChild($contentPart, 0);
        return $altPart;
    }
797604
public function cost($origin, $destination, $shipment, $courier = null)
    {
        $courier = mb_strtolower($courier);

        $parameter = $this->shipment($shipment);
        $parameter['origin'] = $origin;
        $parameter['destination'] = $destination;
        $parameter['courier'] = $courier ?: implode(':', array_keys($this->courier));

        return $this->request($this->api_version . '/internationalCost', $parameter, 'POST');
    }
1260938
public function createSms($body, $recipients, $sender)
    {
        if (is_array($recipients)) {
            $sms = $this->factory->createSms($body, $recipients, $sender);
        } else {
            $sms = $this->factory->createSms($body, array($recipients), $sender);
        }

        return $sms;
    }
895977
public function getRecipientSpecificNotificationsSubject($contentItems, RecipientInterface $recipient)
    {
        $count = sizeof($contentItems);

        if (1 == $count) {
            // get the content-item out of the boxed associative array => array(array('templateId' => contentItem))
            $onlyItem = current(current($contentItems));
            // get the title out of the notification in the contentItem
            return $onlyItem['notification']->getTitle();
        }

        return $this->translatorService->transChoice('_az.email.notifications.subject.%count%', $count, array('%count%' => $count));
    }
525297
public final <T> void parseArray(
      Collection<? super T> destinationCollection, Class<T> destinationItemClass)
      throws IOException {
    parseArray(destinationCollection, destinationItemClass, null);
  }
1014574
public function buildMarshalMap($marshaller, $map, $options)
    {
        if (isset($options['translations']) && !$options['translations']) {
            return [];
        }

        return [
            '_translations' => function ($value, $entity) use ($marshaller, $options) {
                /* @var \Cake\Datasource\EntityInterface $entity */
                $translations = $entity->get('_translations');
                foreach ($this->_config['fields'] as $field) {
                    $options['validate'] = $this->_config['validator'];
                    $errors = [];
                    if (!is_array($value)) {
                        return null;
                    }
                    foreach ($value as $language => $fields) {
                        if (!isset($translations[$language])) {
                            $translations[$language] = $this->_table->newEntity();
                        }
                        $marshaller->merge($translations[$language], $fields, $options);
                        if ((bool)$translations[$language]->getErrors()) {
                            $errors[$language] = $translations[$language]->getErrors();
                        }
                    }
                    // Set errors into the root entity, so validation errors
                    // match the original form data position.
                    $entity->setErrors($errors);
                }

                return $translations;
            }
        ];
    }
952323
public function send($destination, Message $message)
    {
        return $this->getClient()->send($destination, $message, ['transaction' => $this->transactionId], false);
    }
386843
protected function buildStringResponse($content, $headers = [], $options = 0)
    {
        $headers = array_merge($headers, $this->headers);

        $data = [
            'data' => $content,
        ];

        $response = new JsonResponse($data, $this->getStatusCode(), $headers, $options);

        return $response;
    }
374203
public function send($subject, array $options = array()) {
        $to = $this->to;
        $from = $this->from;
        $cc = $this->cc;
        $bcc = $this->bcc;
        $replyTo = $this->replyTo;

        foreach ($options as $key => $value) {
            $$key = $value;
        }

        $this->createHeaders($from, $cc, $bcc, $replyTo);

        if (!empty($this->html)) {
            $message = $this->html;

            $endWithSeparator = false;
            if ($this->text || $this->attachments) {
                $this->headers("Content-type: multipart/" . (($this->attachments) ? 'mixed' : 'alternative') . "; charset=" . $this->htmlCharset);
                $endWithSeparator = true;
            }
            else {
                $this->headers("Content-type: text/html; charset=" . $this->htmlCharset);
                $this->headers('Content-Transfer-Encoding:8bit');
            }
            $this->headers("MIME-Version: 1.0");

            if (!empty($this->text)) {
                $this->separateHeaders();
                $this->headers("Content-type: text/plain; charset=" . $this->htmlCharset);
                $this->headers('Content-Transfer-Encoding:8bit');
                $this->headers($this->text);

                $this->separateHeaders();
                $this->headers("Content-type: text/html; charset=" . $this->htmlCharset);
                $this->headers('Content-Transfer-Encoding:8bit');
                $this->headers($message);
            }
        }
        elseif (!empty($this->text)) {
            $message = $this->text;
        }
        else {
            throw new Exception('Email content not set! Use either/both of setText() and setHTML()');
        }

        if (!empty($this->attachments)) {
            $this->setAttachmentHeader();
        }

        if ($endWithSeparator)
            $this->separateHeaders();

        return mail($to, $subject, $message, $this->headers);
    }
1268853
public function createFromArrayWithContext($data, $options)
    {
        $_edgeClass = $this->_edgeClass;

        return $_edgeClass::createFromArray($data, $options);
    }
869079
public function contentLayout($type, $father = null, $region = null, $admin = null)
    {
        $type = $this->getType($type);
        $content = $this->getContentByType($type->getName(), $father, $region);
        $array = null;

        if ($content && ($type->isPublish() || $admin)) {
            $array = [];
            $array['content'] = $content;
            $array['type'] = $type->getName();
            $array['publish'] = $type->isPublish();
            $array = $this->homeService->isDefinedPush($array, 'father', $father);
            $array = $this->homeService->isDefinedPush($array, 'region', $region);
        }

        return $array;
    }