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

Question only: $messages attribute as an array? #15

Open
cxj opened this issue Mar 30, 2018 · 0 comments
Open

Question only: $messages attribute as an array? #15

cxj opened this issue Mar 30, 2018 · 0 comments

Comments

@cxj
Copy link
Contributor

cxj commented Mar 30, 2018

Did you envision the $messages attribute to be an array of messages, similar to the $output attribute, which is often treated as shown in the example below. I realize how $messages and $output are treated by user-derived classes is really up to us the users. I would however like to try to stay true to your vision to ensure that my code always plays well with the Aura and related-projects ecosystem. Thanks.

class Payload extends AuraPayload
{
    /**
     *
     * Output values carried in the payload.
     *
     * @var array
     *
     */
    protected $output = [];

    /**
     *
     * Converts the Payload to an array.
     *
     * @return array
     *
     */
    public function asArray()
    {
        $arr = [];
        foreach (get_object_vars($this) as $key => $val) {
            $arr[$key] = $val;
        }
        return $arr;
    }

    /**
     *
     * Merges added output values with the existing ones.
     *
     * @param array $output Merge these values with the existing ones.
     **
     * @return $this
     */
    public function addOutput(array $output)
    {
        $this->output = array_merge($this->output, $output);
        return $this;
    }
}
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