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