getUsername() public method

Returns the username.
public getUsername ( ) : string | null
return string | null
Ejemplo n.º 1
0
 /**
  * Tests the setter and getter methods.
  */
 public function testSettersAndGetters()
 {
     $context = new ContaoContext('foo');
     $this->assertEquals('foo', $context->getFunc());
     $this->assertNull($context->getAction());
     $this->assertNull($context->getUsername());
     $this->assertNull($context->getIp());
     $this->assertNull($context->getBrowser());
     $this->assertNull($context->getSource());
     $context->setAction('action');
     $context->setUsername('username');
     $context->setIp('1.2.3.4');
     $context->setBrowser('Mozilla');
     $context->setSource('Foo::bar()');
     $this->assertEquals(json_encode(['func' => 'foo', 'action' => 'action', 'username' => 'username', 'ip' => '1.2.3.4', 'browser' => 'Mozilla']), (string) $context);
 }
Ejemplo n.º 2
0
 /**
  * Sets the username.
  *
  * @param ContaoContext $context
  */
 private function updateUsername(ContaoContext $context)
 {
     if (null !== $context->getUsername()) {
         return;
     }
     $token = $this->tokenStorage->getToken();
     $context->setUsername(null === $token ? 'N/A' : $token->getUsername());
 }