Aura.Payload icon indicating copy to clipboard operation
Aura.Payload copied to clipboard

Question only: $messages attribute as an array?

Open cxj opened this issue 6 years ago • 0 comments

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;
    }
}

cxj avatar Mar 30 '18 00:03 cxj