Binding::getBinding()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace OpenConext\Value\Saml\Metadata\Common;
4
5
use OpenConext\Value\Assert\Assertion;
6
use OpenConext\Value\Serializable;
7
8
final class Binding implements Serializable
9
{
10
    /**
11
     * URNs for the various bindings
12
     */
13
    const HTTP_POST     = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST';
14
    const HTTP_REDIRECT = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect';
15
    const HTTP_ARTIFACT = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact';
16
    const SOAP          = 'urn:oasis:names:tc:SAML:2.0:bindings:SOAP';
17
    const HOK_SSO       = 'urn:oasis:names:tc:SAML:2.0:profiles:holder-of-key:SSO:browser';
18
19
    private static $validBindings = array(
20
        self::HTTP_POST,
21
        self::HTTP_REDIRECT,
22
        self::HTTP_ARTIFACT,
23
        self::SOAP,
24
        self::HOK_SSO
25
    );
26
27
    /**
28
     * @var string
29
     */
30
    private $binding;
31
32
    public function __construct($binding)
33
    {
34
        $message = 'Binding must be one of Binding::HTTP_POST, Binding::HTTP_REDIRECT, Binding::HTTP_ARTIFACT '
35
                    . 'Binding::SOAP or Binding::HOK_SSO';
36
37
        Assertion::inArray($binding, self::$validBindings, $message);
38
39
        $this->binding = $binding;
40
    }
41
42
    /**
43
     * @return Binding
44
     */
45
    public static function httpPost()
46
    {
47
        return new self(self::HTTP_POST);
48
    }
49
50
    /**
51
     * @return Binding
52
     */
53
    public static function httpRedirect()
54
    {
55
        return new self(self::HTTP_REDIRECT);
56
    }
57
58
    /**
59
     * @return Binding
60
     */
61
    public static function httpArtifact()
62
    {
63
        return new self(self::HTTP_ARTIFACT);
64
    }
65
66
    /**
67
     * @return Binding
68
     */
69
    public static function soap()
70
    {
71
        return new self(self::SOAP);
72
    }
73
74
    /**
75
     * @return Binding
76
     */
77
    public static function holderOfKey()
78
    {
79
        return new self(self::HOK_SSO);
80
    }
81
82
    /**
83
     * @param $binding
84
     * @return bool
85
     */
86
    public static function isValidBinding($binding)
87
    {
88
        return in_array($binding, self::$validBindings);
89
    }
90
91
    /**
92
     * @param string $binding
93
     * @return bool
94
     */
95
    public function isOfType($binding)
96
    {
97
        $message = 'BindingType must be one of Binding::HTTP_POST, Binding::HTTP_REDIRECT, Binding::HTTP_ARTIFACT '
98
            . 'Binding::SOAP or Binding::HOK_SSO';
99
100
        Assertion::inArray($binding, self::$validBindings, $message);
101
102
        return $this->binding === $binding;
103
    }
104
105
    /**
106
     * @return string
107
     */
108
    public function getBinding()
109
    {
110
        return $this->binding;
111
    }
112
113
    /**
114
     * @param Binding $other
115
     * @return bool
116
     */
117
    public function equals(Binding $other)
118
    {
119
        return $this->binding === $other->binding;
120
    }
121
122
    public static function deserialize($data)
123
    {
124
        Assertion::nonEmptyString($data, 'data');
125
126
        return new self($data);
127
    }
128
129
    public function serialize()
130
    {
131
        return $this->binding;
132
    }
133
134
    public function __toString()
135
    {
136
        return $this->binding;
137
    }
138
}
139