Neos\Flow\Http\Request::getAttribute PHP Method

getAttribute() public method

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.
See also: getAttributes()
public getAttribute ( string $name, mixed $default = null ) : mixed
$name string The attribute name.
$default mixed Default value to return if the attribute does not exist.
return mixed
    public function getAttribute($name, $default = null)
    {
        if (isset($this->attributes[$name])) {
            return $this->attributes[$name];
        }
        return $default;
    }

Usage Example

コード例 #1
0
 /**
  * Get the values of trusted proxy header.
  *
  * @param string $type One of the HEADER_* constants
  * @param Request $request The request to get the trusted proxy header from
  * @return \Iterator An array of the values for this header type or NULL if this header type should not be trusted
  */
 protected function getTrustedProxyHeaderValues($type, Request $request)
 {
     $trustedHeaders = isset($this->settings['headers'][$type]) ? $this->settings['headers'][$type] : '';
     if ($trustedHeaders === '' || !$request->getAttribute(Request::ATTRIBUTE_TRUSTED_PROXY)) {
         (yield null);
         return;
     }
     $trustedHeaders = array_map('trim', explode(',', $trustedHeaders));
     foreach ($trustedHeaders as $trustedHeader) {
         if ($request->hasHeader($trustedHeader)) {
             (yield array_map('trim', explode(',', $request->getHeader($trustedHeader))));
         }
     }
     (yield null);
 }