Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

class Payload cannot handle mixed types in publish despite publish function accepting mixed payload #81

Open
IvanWillsBI opened this issue May 8, 2024 · 2 comments

Comments

@IvanWillsBI
Copy link

IvanWillsBI commented May 8, 2024

public function publish(string $name, mixed $payload, ?string $replyTo = null): self
{
        return $this->send(new Publish([
            'payload' => Payload::parse($payload),
            'replyTo' => $replyTo,
            'subject' => $name,
        ]));
}

public static function parse(mixed $data): self
{
        if ($data instanceof self) {
            return $data;
        }
        if (is_string($data)) {
            return new self($data);
        }
        if (is_array($data)) {
            return new self(json_encode($data));
        }

        return new self("");
}```

Causes nil bodies to be published to NATS if data type is not string or array
@IvanWillsBI IvanWillsBI changed the title class Payload cannot handle mixed types in publish despute publish function accepting mixed payload class Payload cannot handle mixed types in publish despite publish function accepting mixed payload May 8, 2024
@IvanWillsBI
Copy link
Author

IvanWillsBI commented May 8, 2024

public static function parse(mixed $data): self
    {
        if ($data instanceof self) {
            return $data;
        }
        if (is_string($data)) {
            return new self($data);
        }
        if (is_array($data)) {
            return new self(json_encode($data));
        }
        if (is_resource($data)) {
            return new self('');
        }

        return new self(json_encode($data));
    }

@IvanWillsBI
Copy link
Author

public static function parse(mixed $data): self
    {
        if ($data instanceof self) {
            return $data;
        }
        if (is_string($data)) {
            return new self($data);
        }
        if (is_array($data)) {
            return new self(json_encode($data));
        }
        if (is_resource($data)) {
            return new self('');
        }

        return new self(json_encode($data));
    }

Is this a viable fix, I would raise a PR but encountering a permissions issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant