From d0ebf2f1ec717a9accd3aa824e72490c5ff095b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Tue, 30 Oct 2012 09:49:51 +0100 Subject: [PATCH 1/2] Added a note about request accept-* headers parsing. --- components/http_foundation/introduction.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/components/http_foundation/introduction.rst b/components/http_foundation/introduction.rst index 374d7ee7cea..1aaed68f0c7 100644 --- a/components/http_foundation/introduction.rst +++ b/components/http_foundation/introduction.rst @@ -215,6 +215,23 @@ the method tells you if the request contains a Session which was started in one of the previous requests. +Accessing `Accept-*` Headers Data +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If you need to access parsed data from `Accept`, `Accept-Language`, +`Accept-Charset` or `Accept-Encoding`, you can use +:class:`Symfony\\Component\\HttpFoundation\\AcceptHeader` utility class:: + + $accept = AcceptHeader::fromString($request->headers->get('Accept')); + if ($accept->has('text/html') { + $item = $accept->get('html'); + $charset = $item->getAttribute('charset', 'utf-8'); + $quality = $item->getQuality(); + } + + // accepts items are sorted by descending quality + $accepts = AcceptHeader::fromString($request->headers->get('Accept'))->all(); + Accessing other Data ~~~~~~~~~~~~~~~~~~~~ From 7c7b981b546dcb71a1662faab32308ea3c984186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Tue, 30 Oct 2012 18:00:18 +0100 Subject: [PATCH 2/2] Added information about accept-* headers request methods. --- components/http_foundation/introduction.rst | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/components/http_foundation/introduction.rst b/components/http_foundation/introduction.rst index 1aaed68f0c7..b27909a6529 100644 --- a/components/http_foundation/introduction.rst +++ b/components/http_foundation/introduction.rst @@ -218,8 +218,20 @@ the previous requests. Accessing `Accept-*` Headers Data ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -If you need to access parsed data from `Accept`, `Accept-Language`, -`Accept-Charset` or `Accept-Encoding`, you can use +You can easily access basic data extracted from ``Accept-*`` headers +by using following methods: + +* :method:`Symfony\\Component\\HttpFoundation\\Request::getAcceptableContentTypes`: + Returns the list of accepted content types ordered by descending quality; + +* :method:`Symfony\\Component\\HttpFoundation\\Request::getLanguages`: + Returns the list of accepted languages ordered by descending quality; + +* :method:`Symfony\\Component\\HttpFoundation\\Request::getCharsets`: + Returns the list of accepted languages ordered by descending quality; + +If you need to egt full access to parsed data from ``Accept``, ``Accept-Language``, +``Accept-Charset`` or ``Accept-Encoding``, you can use :class:`Symfony\\Component\\HttpFoundation\\AcceptHeader` utility class:: $accept = AcceptHeader::fromString($request->headers->get('Accept'));