You are here

public function ServerRequest::getAttribute in Zircon Profile 8

Same name in this branch
  1. 8 vendor/zendframework/zend-diactoros/src/ServerRequest.php \Zend\Diactoros\ServerRequest::getAttribute()
  2. 8 vendor/symfony/psr-http-message-bridge/Tests/Fixtures/ServerRequest.php \Symfony\Bridge\PsrHttpMessage\Tests\Fixtures\ServerRequest::getAttribute()
Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-diactoros/src/ServerRequest.php \Zend\Diactoros\ServerRequest::getAttribute()

Retrieve a single derived request attribute.

Retrieves a single derived request attribute as described in getAttributes(). If the attribute has not been previously set, returns the default value as provided.

This method obviates the need for a hasAttribute() method, as it allows specifying a default value to return if the attribute is not found.

Parameters

string $name The attribute name.:

mixed $default Default value to return if the attribute does not exist.:

Return value

mixed

Overrides ServerRequestInterface::getAttribute

See also

getAttributes()

File

vendor/zendframework/zend-diactoros/src/ServerRequest.php, line 182

Class

ServerRequest
Server-side HTTP request

Namespace

Zend\Diactoros

Code

public function getAttribute($attribute, $default = null) {
  if (!array_key_exists($attribute, $this->attributes)) {
    return $default;
  }
  return $this->attributes[$attribute];
}