summaryrefslogtreecommitdiff
path: root/app/Core/Ldap/Entry.php
blob: e67dd625642da79b2e5e8904cb9eff8e386ce1e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php

namespace Kanboard\Core\Ldap;

/**
 * LDAP Entry
 *
 * @package ldap
 * @author  Frederic Guillot
 */
class Entry
{
    /**
     * LDAP entry
     *
     * @access private
     * @var array
     */
    private $entry = array();

    /**
     * Constructor
     *
     * @access public
     * @param  array $entry
     */
    public function __construct(array $entry)
    {
        $this->entry = $entry;
    }

    /**
     * Get all attribute values
     *
     * @access public
     * @param  string  $attribute
     * @return string[]
     */
    public function getAll($attribute)
    {
        $attributes = array();

        if (! isset($this->entry[$attribute]['count'])) {
            return $attributes;
        }

        for ($i = 0; $i < $this->entry[$attribute]['count']; $i++) {
            $attributes[] = $this->entry[$attribute][$i];
        }

        return $attributes;
    }

    /**
     * Get first attribute value
     *
     * @access public
     * @param  string  $attribute
     * @param  string  $default
     * @return string
     */
    public function getFirstValue($attribute, $default = '')
    {
        return isset($this->entry[$attribute][0]) ? $this->entry[$attribute][0] : $default;
    }

    /**
     * Get entry distinguished name
     *
     * @access public
     * @return string
     */
    public function getDn()
    {
        return isset($this->entry['dn']) ? $this->entry['dn'] : '';
    }

    /**
     * Return true if the given value exists in attribute list
     *
     * @access public
     * @param  string  $attribute
     * @param  string  $value
     * @return boolean
     */
    public function hasValue($attribute, $value)
    {
        $attributes = $this->getAll($attribute);
        return in_array($value, $attributes);
    }
}