@param MessageInterface[] $messages
@param string|null        $keyBy

@return array
483066
public static function buildMessages(array $messages, string $keyBy = null): array
    {
        $values = array_map(function (MessageInterface $message) {
            return $message->build();
        }, $messages);

        if (!is_null($keyBy)) {
            $accessor = PropertyAccess::createPropertyAccessor();

            $keys = array_map(function (MessageInterface $message) use ($accessor, $keyBy) {
                return $accessor->getValue($message, $keyBy);
            }, $messages);

            $values = array_combine($keys, $values);
        }

        return $values;
    }
529072
public function report(string ...$messages): ResultInterface
    {
        if (! empty($messages)) {
            return ResultFactory::makeFailure(
                $this->checker,
                array_merge([$this->failureMessage], $messages)
            );
        }

        return ResultFactory::makeSuccess($this->checker);
    }
1318351
protected function encode(array $messages)
    {
        if ($this->encode) {
            foreach ($messages as $key => $message) {
                if (($form = mb_detect_encoding($message)) != self::TARGET_ENCODING) {
                    $messages[$key] = mb_convert_encoding($message, self::TARGET_ENCODING, $form);
                }
            }
        }

        return $messages;
    }
676652
public function isEqual(array $keys, $message = null)
    {
        $existingKey = null;
        foreach ($keys as $key) {
            if (isset($this->scope[$key])) {
                $existingKey = $key;
                break;
            }
        }
        if ($existingKey === null) {
            return $this;
        }

        foreach ($keys as $key) {
            if (isset($this->scope[$key]) && $this->scope[$key] != $this->scope[$existingKey]) {
                $keysList           = implode("', '", $keys);
                $this->errors[$key] = sprintf($message !== null ? $message : self::$isEqualMessage, $keysList);
            }
        }

        return $this;
    }
129168
public function getMessages() : array
    {
        $messages = [];

        foreach ($this->getLogs() as $log) {
            foreach ($log->getMessages() as $message) {
                $messages[] = $message;
            }
        }

        return $messages;
    }
773140
public function saveMessagesToDb($messages, $db, $sourceMessageTable, $messageTable, $removeUnused, $languages)
    {
        $q = new \yii\db\Query;
        $current = [];

        foreach ($q->select(['id', 'category', 'message'])->from($sourceMessageTable)->all() as $row) {
            $current[$row['category']][$row['id']] = $row['message'];
        }

        $new = [];
        $obsolete = [];

        foreach ($messages as $category => $msgs) {
            $msgs = array_unique($msgs);

            if (isset($current[$category])) {
                $new[$category] = array_diff($msgs, $current[$category]);
                $obsolete += array_diff($current[$category], $msgs);
            } else {
                $new[$category] = $msgs;
            }
        }

        foreach (array_diff(array_keys($current), array_keys($messages)) as $category) {
            $obsolete += $current[$category];
        }

        if (!$removeUnused) {
            foreach ($obsolete as $pk => $m) {
                if (mb_substr($m, 0, 2) === '@@' && mb_substr($m, -2) === '@@') {
                    unset($obsolete[$pk]);
                }
            }
        }

        $obsolete = array_keys($obsolete);
        $this->stdout("Inserting new messages...");
        $savedFlag = false;
        $columnNames = $db->getTableSchema($sourceMessageTable)->columnNames;
        $hasLocationColumn = in_array('location', $columnNames) ?: false;

        foreach ($new as $category => $msgs) {
            foreach ($msgs as $m) {
                $savedFlag  = true;
                $msgHash    = md5($m);
                $sourceMessageData = [
                    'category'  => $category,
                    'message'   => $m,
                ];
                if ( true === $hasLocationColumn ) {
                    $sourceMessageData['location']  = $this->extractLocations($category, $m);
                    $sourceMessageData['hash']      = $msgHash;
                }
                $db->createCommand()
                    ->insert($sourceMessageTable, $sourceMessageData)
                    ->execute()
                ;
                $lastID = ($db->driverName == 'pgsql')
                        ? $db->getLastInsertID($sourceMessageTable . '_id_seq')
                        : $db->getLastInsertID();
                foreach ($languages as $language) {
                    $messageData = [
                        'id'        => $lastID,
                        'language'  => $language,
                    ];
                    if ( true === $hasLocationColumn ) {
                        $messageData['hash'] = $msgHash;
                    }
                    $db->createCommand()
                        ->insert($messageTable, $messageData)
                        ->execute()
                    ;
                }
            }
        }

        $this->stdout($savedFlag ? "saved." . PHP_EOL : "Nothing new...skipped." . PHP_EOL);
        $this->stdout($removeUnused ? "Deleting obsoleted messages..." . PHP_EOL : "Updating obsoleted messages..." . PHP_EOL);

        if (empty($obsolete)) {
            $this->stdout("Nothing obsoleted!...skipped." . PHP_EOL);
        } else {
            if ($removeUnused) {
                $db->createCommand()
                   ->delete($sourceMessageTable, ['in', 'id', $obsolete])->execute();
                $this->stdout("deleted." . PHP_EOL);
            } else {
                $db->createCommand()
                    ->update(
                        $sourceMessageTable,
                        ['message' => new \yii\db\Expression("CONCAT('@@',message,'@@')")],
                        ['in', 'id', $obsolete]
                    )
                    ->execute()
                ;
                $this->stdout("updated." . PHP_EOL);
            }
        }

        // ------------------------------ COUNTER ------------------------------
        $counter = ['new' => 0, 'obsolete' => count($obsolete)];
        foreach ( $new as $msgs ) {
            $counter['new'] += count($msgs);
        }

        return $counter;
    }
1185640
static public function extract($data, $keys=null)
    {
        if ($data) {
            if ($keys) {
                $list = [];
                $keys = static::explode('\,\|', $keys);
                foreach ($keys as $k) {
                    $list[] = isset($data[$k]) ? $data[$k] : null;
                }
                return $list;
            }
        }
        return $data;
    }
1166209
public function publishBatch($channel, array $messages)
    {
        $topic = $this->getTopicForChannel($channel);
        $messages = array_map(function ($message) {
            return ['data' => Utils::serializeMessage($message)];
        }, $messages);

        if ($this->backgroundBatching) {
            $batchPublisher = $topic->batchPublisher();
            foreach ($messages as $message) {
                $batchPublisher->publish($message);
            }
        } else {
            $topic->publishBatch($messages);
        }
    }
1148075
public static function keyExists($value, $key, $message = null)
    {
        if (!array_key_exists($key, $value)) {
            throw new InvalidArgumentException(sprintf(
                $message ?: 'Expected array key %2$s to exist',
                Helper::typeToString($value),
                Helper::valueToString($key)
            ));
        }
    }
1335297
public static function extractModelAndKeys($model, array $keys = null)
    {
        if (! is_null($keys)) {
            if (is_string($model)) {
                $model = new $model;
            }

            return [$model, $keys];
        }

        if ($model instanceof Model) {
            return [$model, [$model->getKey()]];
        }

        if ($model instanceof Collection) {
            $keys = $model->map(function ($model) {
                return $model->getKey();
            });

            return [$model->first(), $keys];
        }
    }
79974
public function getMessages()
    {
        $this->getBotId();

        $messageContent = $this->getMessageContent($this->event->get('id'));

        $message = new IncomingMessage($messageContent->text, $messageContent->roomId, $messageContent->personId, $messageContent);

        if ($this->getBotId() === $messageContent->personId) {
            $message->setIsFromBot(true);
        }

        return [$message];
    }
1015402
public function keyBy( $keyBy )
	{
		$keyBy = $this->valueRetriever( $keyBy );

		$results = [];

		foreach ( $this->items as $key => $item )
		{
			$results[$keyBy( $item, $key )] = $item;
		}

		return new static( $results );
	}
451604
protected function success($messages = null)
	{
		$data = $this->getStatusData('success', $messages);
		return $this->jsonResponse($data, 200);
	}
776165
private function messageLoggerContext(MessageInterface $message): array
    {
        return [
            'id' => $message->getId(),
            'created' => $message->getCreated(),
            'type' => $message->getType(),
            'payload' => $message->getPayload(),
        ];
    }
1346871
public function keyBy($keyBy)
    {
        $results = [];
        foreach ($this->items as $key => $item) {
            $resolvedKey = is_object($item) ? $item->{$keyBy}  : $item[$keyBy];
            $results[$resolvedKey] = $item;
        }
        return new static($results);
    }
787070
protected function transform($messages, $format, $key)
    {
        return array_map(function ($message) use ($format, $key)
        {
            return str_replace(array(':message', ':key'), array($message, $key), $format);

        }, (array) $messages);
    }
444902
private function from_notes(array $messages, $simple = true){
    if ( !empty($messages) ){
      foreach ( $messages as $idx => $mess ){
        if ( empty($mess['id_note']) ){
          unset($messages[$idx]);
          continue;
        }
        $note = $this->notes->get($mess['id_note']);
        $note = [
          'id' => $mess['id'],
          'title' => $note['title'],
          'content' => $note['content']
        ];
        if ( $simple ){
          $messages[$idx] = $note;
        }
        else {
          $messages[$idx] = \bbn\x::merge_arrays($messages[$idx], $note);
        }
      }
    }
    return $messages;
  }