CAS_Client::getAttributes PHP Method

getAttributes() public method

Get an key values arry of attributes
public getAttributes ( ) : arry
return arry of attributes
    public function getAttributes()
    {
        // Sequence validation
        $this->ensureAuthenticationCallSuccessful();
        // This is likely a duplicate check that could be removed....
        if (empty($this->_user)) {
            // if no user is set, there shouldn't be any attributes also...
            phpCAS::error('this method should be used only after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
        }
        return $this->_attributes;
    }

Usage Example

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']));
 }
All Usage Examples Of CAS_Client::getAttributes
CAS_Client