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.
/** * 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); }