auraphp / Aura.Payload

A Domain Payload implementation.
MIT License
55 stars 18 forks source link

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

Open cxj opened 6 years ago

cxj commented 6 years ago

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