CAS_Client::getAttribute PHP Method

getAttribute() public method

Get a specific attribute by name
public getAttribute ( string $key ) : string
$key string name of attribute
return string attribute values
    public function getAttribute($key)
    {
        // Sequence validation
        $this->ensureAuthenticationCallSuccessful();
        if ($this->_hasAttribute($key)) {
            return $this->_attributes[$key];
        }
    }

Usage Example

示例#1
0
 /**
  * Validate user attributes.
  *
  * @return void
  */
 public function validateUserAttributes()
 {
     $attras = $this->object->getAttributes();
     $this->assertInternalType('array', $attras);
     if (count($attras) != 4 || !is_array($attras['memberOf'])) {
         print "\n";
         print_r($attras);
     }
     $this->assertEquals(4, count($attras));
     $this->assertTrue($this->object->hasAttribute('givenName'));
     // direct access
     $this->assertEquals('John', $this->object->getAttribute('givenName'));
     // array access
     $this->assertArrayHasKey('givenName', $attras);
     $this->assertEquals('John', $attras['givenName']);
     $this->assertTrue($this->object->hasAttribute('surname'));
     // direct access
     $this->assertEquals('Smith', $this->object->getAttribute('surname'));
     // array access
     $this->assertArrayHasKey('surname', $attras);
     $this->assertEquals('Smith', $attras['surname']);
     $this->assertTrue($this->object->hasAttribute('memberOf'));
     // direct access
     $memberOf = $this->object->getAttribute('memberOf');
     $this->assertInternalType('array', $memberOf);
     $this->assertEquals(2, count($memberOf));
     $this->assertTrue(in_array('CN=Staff,OU=Groups,DC=example,DC=edu', $memberOf));
     $this->assertTrue(in_array('CN=Spanish Department,OU=Departments,OU=Groups,DC=example,DC=edu', $memberOf));
     // array access
     $this->assertArrayHasKey('memberOf', $attras);
     $this->assertInternalType('array', $attras['memberOf']);
     $this->assertEquals(2, count($attras['memberOf']));
     $this->assertTrue(in_array('CN=Staff,OU=Groups,DC=example,DC=edu', $attras['memberOf']));
     $this->assertTrue(in_array('CN=Spanish Department,OU=Departments,OU=Groups,DC=example,DC=edu', $attras['memberOf']));
 }
All Usage Examples Of CAS_Client::getAttribute
CAS_Client