getAttribute() public method

Get a specific attribute by name
public getAttribute ( string $key ) : string
$key string name of attribute
return string attribute values
Ejemplo n.º 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']));
 }
Ejemplo n.º 2
0
 /**
  * Answer an attribute for the authenticated user.
  *
  * @param string $key attribute name
  *
  * @return mixed string for a single value or an array if multiple values exist.
  * @warning should only be called after phpCAS::forceAuthentication()
  * or phpCAS::checkAuthentication().
  */
 public static function getAttribute($key)
 {
     phpCAS::_validateClientExists();
     try {
         return self::$_PHPCAS_CLIENT->getAttribute($key);
     } catch (Exception $e) {
         phpCAS::error(get_class($e) . ': ' . $e->getMessage());
     }
 }