1<?php 2 3/** 4 * This file is part of the FreeDSx SASL package. 5 * 6 * (c) Chad Sikorra <Chad.Sikorra@gmail.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace FreeDSx\Sasl; 13 14use Countable, IteratorAggregate; 15use function array_key_exists, count; 16 17/** 18 * The message object encapsulates options / values for all mechanism messages. 19 * 20 * @author Chad Sikorra <Chad.Sikorra@gmail.com> 21 */ 22class Message implements Countable, IteratorAggregate 23{ 24 protected $data = []; 25 26 public function __construct(array $data = []) 27 { 28 $this->data = $data; 29 } 30 31 /** 32 * @return mixed 33 */ 34 public function get(string $name) 35 { 36 return $this->data[$name] ?? null; 37 } 38 39 public function has(string $name): bool 40 { 41 return array_key_exists($name, $this->data); 42 } 43 44 /** 45 * @param mixed $value 46 * @return Message 47 */ 48 public function set(string $name, $value): self 49 { 50 $this->data[$name] = $value; 51 52 return $this; 53 } 54 55 public function count(): int 56 { 57 return count($this->data); 58 } 59 60 public function toArray(): array 61 { 62 return $this->data; 63 } 64 65 public function getIterator() 66 { 67 return new \ArrayIterator($this->data); 68 } 69} 70