Recreates the envelope from a json string.

@param string $envelope

@return self
3060
public static function fromString(string $envelope): self
    {
        $envelope = json_decode($envelope, true);
        if (!is_array($envelope)) {
            throw new \InvalidArgumentException('Envelope is invalid. ' . json_last_error_msg());
        }

        $serializer = isset($envelope['serializer']) ? $envelope['serializer'] : 'php';
        $isReplay = isset($envelope['is_replay']) ? filter_var($envelope['is_replay'], FILTER_VALIDATE_BOOLEAN) : false;
        $message = self::getSerializer($serializer)->deserialize(isset($envelope['message']) ? $envelope['message'] : '');

        /*
         * don't attempt to set replay if it's the php serializer because it already knows
         * if it's a replay as the entire object is serialized with its internal state.
         *
         * this is a PHP feature only, all other serializers have no notion of the
         * language specific in memory object.  we use php serializer because it's
         * very fast to un/de-serialize the objects.
         */
        if ($isReplay && 'php' !== $serializer) {
            $message->isReplay(true);
        }

        return new self($message, $serializer);
    }
287934
public static function create(array $payload): self
    {
        $senderId = $payload['sender']['id'];
        $recipientId = $payload['recipient']['id'];
        $timestamp = $payload['timestamp'];
        $checkoutUpdate = CheckoutUpdate::create($payload['checkout_update']);

        return new static($senderId, $recipientId, $timestamp, $checkoutUpdate);
    }
542120
public function replace($old, $new): self
    {
        Assert::typeOf(['string', __CLASS__], $old, $new);

        return new static(str_replace((string) $old, (string) $new, $this->data), $this->encoding);
    }
311266
static function fromJson(object $map): self {
    return (new static(isset($map->source_files) && is_array($map->source_files) ? array_map([SourceFile::class, 'fromJson'], $map->source_files) : []))
      ->setCommitSha(isset($map->commit_sha) && is_string($map->commit_sha) ? $map->commit_sha : '')
      ->setGit(isset($map->git) && is_object($map->git) ? GitData::fromJson($map->git) : null)
      ->setParallel(isset($map->parallel) && is_bool($map->parallel) ? $map->parallel : false)
      ->setRepoToken(isset($map->repo_token) && is_string($map->repo_token) ? $map->repo_token : '')
      ->setRunAt(isset($map->run_at) && is_string($map->run_at) ? new \DateTime($map->run_at) : null)
      ->setServiceJobId(isset($map->service_job_id) && is_string($map->service_job_id) ? $map->service_job_id : '')
      ->setServiceName(isset($map->service_name) && is_string($map->service_name) ? $map->service_name : '')
      ->setServiceNumber(isset($map->service_number) && is_string($map->service_number) ? $map->service_number : '')
      ->setServicePullRequest(isset($map->service_pull_request) && is_string($map->service_pull_request) ? $map->service_pull_request : '');
  }
462422
public static function create(array $payload): self
    {
        $senderId = $payload['sender']['id'];
        $recipientId = $payload['recipient']['id'];
        $timestamp = $payload['timestamp'];
        $passThreadControl = PassThreadControl::create($payload['pass_thread_control']);

        return new static($senderId, $recipientId, $timestamp, $passThreadControl);
    }
832569
public static function create(string $environment): self
    {
        $environment = \strtolower($environment);

        self::validateEnvironment($environment);

        return new self($environment);
    }
1010684
public function setStatus($status, $envelope = null)
	{
		// Check if we're not in a final state yet
		if ($this->status > 0) {
			throw new \RuntimeException('Cannot change status from final state ' . $this->status . ' to state ' . $status . '.');
		}

		// Check if this is a valid state
		if ( !in_array($status, array_keys(self::$statusDescriptionMapping)) ) {
			throw new \InvalidArgumentException('Status ' . $status . ' is not a valid status.');
		}

		// Check if the retry envelope is not this envelope
		if ($this === $envelope) {
			throw new \InvalidArgumentException('Retry envelope cannot be set to this envelope.');
		}

		// Save it!
		$this->status = $status;
		$this->retryEnvelope = $envelope;
	}
438009
public static function create(array $payload): self
    {
        $senderId = $payload['sender']['id'];
        $recipientId = $payload['recipient']['id'];
        $delivery = Delivery::create($payload['delivery']);

        return new static($senderId, $recipientId, $delivery);
    }
475368
public static function create(array $payload): self
    {
        $senderId = $payload['sender']['id'];
        $recipientId = $payload['recipient']['id'];
        $timestamp = $payload['timestamp'];
        $read = Read::create($payload['read']);

        return new static($senderId, $recipientId, $timestamp, $read);
    }
160252
static function fromJson(object $map): self {
    return new static(
      isset($map->head) && is_object($map->head) ? GitCommit::fromJson($map->head) : null,
      isset($map->branch) && is_string($map->branch) ? $map->branch : '',
      isset($map->remotes) && is_array($map->remotes) ? array_map([GitRemote::class, 'fromJson'], $map->remotes) : []
    );
  }
930077
static function fromJson(object $map): self {
    return new static(
      isset($map->sourceFile) && is_string($map->sourceFile) ? $map->sourceFile : '',
      isset($map->functions) && is_object($map->functions) ? FunctionCoverage::fromJson($map->functions) : null,
      isset($map->branches) && is_object($map->branches) ? BranchCoverage::fromJson($map->branches) : null,
      isset($map->lines) && is_object($map->lines) ? LineCoverage::fromJson($map->lines) : null
    );
  }
1254185
public static function load($json)
    {
        $j = new Json();

        return self::create($j->decode($json), $j);
    }
332958
public function removeRecipient(string $recipient): self
    {
        $itemPosition = array_search($recipient, $this->recipients);

        if (false !== $itemPosition) {
            unset($this->recipients[$itemPosition]);
        }

        unset($this->recipientVariables[$recipient]);

        return $this;
    }
780683
public static function wrap($message, array $stamps = []): self
    {
        $envelope = $message instanceof self ? $message : new self($message);

        return $envelope->with(...$stamps);
    }
889460
public static function create(array $payload): self
    {
        $senderId = $payload['sender']['id'];
        $recipientId = $payload['recipient']['id'];
        unset($payload['sender'], $payload['recipient']);

        return new static($senderId, $recipientId, $payload);
    }
1111714
public function build(AMQPEnvelope $envelope)
    {
        $wrapper = $this->wrap($envelope);

        return new $this->delivery_skeleton($wrapper->getBody(), $wrapper->getEnvelope(), $wrapper->getProperties());
    }
1091956
public function invoke(Envelope $envelope, Queue $queue)
    {
        try {
            $this->dispatcher->dispatch(BernardEvents::INVOKE, new EnvelopeEvent($envelope, $queue));

            $receiver = $this->router->route($envelope);
            $receiver->receive($envelope->getMessage());

            // We successfully processed the message.
            $queue->acknowledge($envelope);

            $this->dispatcher->dispatch(BernardEvents::ACKNOWLEDGE, new EnvelopeEvent($envelope, $queue));
        } catch (\Throwable $error) {
            $this->rejectDispatch($error, $envelope, $queue);
        } catch (\Exception $exception) {
            $this->rejectDispatch($exception, $envelope, $queue);
        }
    }