1<?php
2/**
3 * This file is part of the FreeDSx LDAP package.
4 *
5 * (c) Chad Sikorra <Chad.Sikorra@gmail.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11namespace FreeDSx\Ldap\Operation\Request;
12
13use FreeDSx\Asn1\Asn1;
14use FreeDSx\Asn1\Type\AbstractType;
15use FreeDSx\Asn1\Type\NullType;
16use FreeDSx\Ldap\Exception\ProtocolException;
17
18/**
19 * A request to unbind. RFC 4511, 4.3
20 *
21 * UnbindRequest ::= [APPLICATION 2] NULL
22 *
23 * @author Chad Sikorra <Chad.Sikorra@gmail.com>
24 */
25class UnbindRequest implements RequestInterface
26{
27    protected const APP_TAG = 2;
28
29    /**
30     * {@inheritdoc}
31     */
32    public static function fromAsn1(AbstractType $type)
33    {
34        if (!$type instanceof NullType) {
35            throw new ProtocolException('The unbind request is invalid');
36        }
37
38        return new self();
39    }
40
41    /**
42     * {@inheritdoc}
43     */
44    public function toAsn1(): AbstractType
45    {
46        return Asn1::application(self::APP_TAG, Asn1::null());
47    }
48}
49