1<?php
2
3/**
4 * This file is part of the FreeDSx LDAP 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\Ldap\Operation\Request;
13
14use FreeDSx\Asn1\Asn1;
15use FreeDSx\Asn1\Type\AbstractType;
16use FreeDSx\Asn1\Type\IntegerType;
17use FreeDSx\Ldap\Exception\ProtocolException;
18
19/**
20 * RFC 4511, 4.11.
21 *
22 * AbandonRequest ::= [APPLICATION 16] MessageID
23 *
24 * @author Chad Sikorra <Chad.Sikorra@gmail.com>
25 */
26class AbandonRequest implements RequestInterface
27{
28    protected const APP_TAG = 16;
29
30    /**
31     * @var int
32     */
33    protected $messageID;
34
35    /**
36     * @param int $messageID
37     */
38    public function __construct(int $messageID)
39    {
40        $this->messageID = $messageID;
41    }
42
43    /**
44     * @param int $messageID
45     * @return $this
46     */
47    public function setMessageId(int $messageID)
48    {
49        $this->messageID = $messageID;
50
51        return $this;
52    }
53
54    /**
55     * @return int
56     */
57    public function getMessageId(): int
58    {
59        return $this->messageID;
60    }
61
62    /**
63     * {@inheritDoc}
64     * @return AbandonRequest
65     */
66    public static function fromAsn1(AbstractType $type)
67    {
68        if (!$type instanceof IntegerType) {
69            throw new ProtocolException('The abandon request is malformed');
70        }
71
72        return new self($type->getValue());
73    }
74
75    /**
76     * {@inheritdoc}
77     */
78    public function toAsn1(): AbstractType
79    {
80        return Asn1::application(self::APP_TAG, Asn1::integer($this->messageID));
81    }
82}
83