From 6df293c4824dad7457526292c486d5f93ead14ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Fri, 29 May 2015 12:31:48 +0200 Subject: [PATCH 1/6] [PSR-7] Bridge documentation --- cookbook/index.rst | 1 + cookbook/map.rst.inc | 4 ++ cookbook/psr7.rst | 88 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 cookbook/psr7.rst diff --git a/cookbook/index.rst b/cookbook/index.rst index 98828a56287..5d5a2797c3f 100644 --- a/cookbook/index.rst +++ b/cookbook/index.rst @@ -27,6 +27,7 @@ The Cookbook serializer service_container/index session/index + psr7 symfony1 templating/index testing/index diff --git a/cookbook/map.rst.inc b/cookbook/map.rst.inc index 74eb60224c4..243d8e9daed 100644 --- a/cookbook/map.rst.inc +++ b/cookbook/map.rst.inc @@ -192,6 +192,10 @@ * (configuration) :doc:`/cookbook/configuration/pdo_session_storage` * :doc:`/cookbook/session/avoid_session_start` +* **PSR-7** + + * :doc:`/cookbook/psr7` + * **symfony1** * :doc:`/cookbook/symfony1` diff --git a/cookbook/psr7.rst b/cookbook/psr7.rst new file mode 100644 index 00000000000..ece2040850b --- /dev/null +++ b/cookbook/psr7.rst @@ -0,0 +1,88 @@ +.. index:: + single: PSR-7 + +The PSR-7 Bridge +================ + + The PSR-7 bridge converts :doc:`HttpFoundation ` + objects from and to objects implementing HTTP message interfaces defined + by the `PSR-7`_. + +Installation +------------ + +You can install the component in 2 different ways: + +* :doc:`Install it via Composer ` (``symfony/psr-http-message-bridge`` on `Packagist`_); +* Use the official Git repository (https://github.com/symfony/psr-http-message-bridge). + +The bridge also needs a PSR-7 implementation to allow converting HttpFoundation +objects to PSR-7 objects. It provides native support for _`Zend Diactoros`_. +Use Composer (``zendframework/zend-diactoros`` on `Packagist`_) or refers to +the project documentation to install it. + +Usage +----- + +Converting from HttpFoundation Objects to PSR-7 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The bridge provides an interface of a factory called +:class:`Symfony\\Bridge\\PsrHttpMessage\\HttpMessageFactoryInterface` +that builds objects implementing PSR-7 interfaces from HttpFoundation objects. +It also provide a default implementation using Zend Diactoros internally. + +The following code snippet explain how to convert a :class:`Symfony\\Component\\HttpFoundation\\Request` +to a Zend Diactoros :class:`Zend\\Diactoros\\ServerRequest` implementing the +:class:`Psr\\Http\\Message\\ServerRequestInterface` interface:: + + use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory; + use Symfony\Component\HttpFoundation\Request; + + $symfonyRequest = new Request(array(), array(), array(), array(), array(), array('HTTP_HOST' => 'dunglas.fr'), 'Content'); + // The HTTP_HOST server key must be set to avoid an unexpected error + + $psr7Factory = new DiactorosFactory(); + $psrRequest = $psr7Factory->createRequest($symfonyRequest); + +And now from a :class:`Symfony\\Component\\HttpFoundation\\Response` to a Zend +Diactoros :class:`Zend\\Diactoros\\Response` implementing the :class:`Psr\\Http\\Message\\ResponseInterface` +interface:: + + use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory; + use Symfony\Component\HttpFoundation\Response; + + $symfonyResponse = new Response('Content'); + + $psr7Factory = new DiactorosFactory(); + $psrResponse = $psr7Factory->createResponse($symfonyResponse); + +Converting Objects implementing PSR-7 Interfaces to HttpFoundation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +On the other hand, the bridge provide a factory interface called +:class:`Symfony\\Bridge\\PsrHttpMessage\\HttpFoundationFactoryInterface` +that builds HttpFoundation objects from objects implementing PSR-7 interfaces. + +The next snippet explain how to convert an object implementing the :class:`Psr\\Http\\Message\\ServerRequestInterface` +interface to a :class:`Symfony\\Component\\HttpFoundation\\Request` instance:: + + use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory; + + // $psrRequest is an instance of Psr\Http\Message\ServerRequestInterface + + $httpFoundationFactory = new HttpFoundationFactory(); + $symfonyRequest = $httpFoundationFactory->createRequest($psrRequest); + +From an object implementing the :class:`Psr\\Http\\Message\\ResponseInterface` +to a :class:`Symfony\\Component\\HttpFoundation\\Response` instance:: + + use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory; + + // $psrResponse is an instance of Psr\Http\Message\ResponseInterface + + $httpFoundationFactory = new HttpFoundationFactory(); + $symfonyResponse = $httpFoundationFactory->createResponse($psrResponse); + +.. _`PSR-7`: http://www.php-fig.org/psr/psr-7/ +.. _Packagist: https://packagist.org/packages/symfony/psr-http-message-bridge From c6f10c99a277a25f7af669c701f452fe96382acd Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 19 Jun 2015 12:24:17 -0400 Subject: [PATCH 2/6] [#5331] Tiny typo --- cookbook/psr7.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookbook/psr7.rst b/cookbook/psr7.rst index ece2040850b..2d0316d1824 100644 --- a/cookbook/psr7.rst +++ b/cookbook/psr7.rst @@ -18,7 +18,7 @@ You can install the component in 2 different ways: The bridge also needs a PSR-7 implementation to allow converting HttpFoundation objects to PSR-7 objects. It provides native support for _`Zend Diactoros`_. -Use Composer (``zendframework/zend-diactoros`` on `Packagist`_) or refers to +Use Composer (``zendframework/zend-diactoros`` on `Packagist`_) or refer to the project documentation to install it. Usage From fe9759aa83db094b1fe42524ccdfe8fe06c86336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Fri, 10 Jul 2015 08:12:58 +0200 Subject: [PATCH 3/6] [PSR-7] Fix Diactoros link --- cookbook/psr7.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cookbook/psr7.rst b/cookbook/psr7.rst index 2d0316d1824..79cab6caa09 100644 --- a/cookbook/psr7.rst +++ b/cookbook/psr7.rst @@ -17,7 +17,7 @@ You can install the component in 2 different ways: * Use the official Git repository (https://github.com/symfony/psr-http-message-bridge). The bridge also needs a PSR-7 implementation to allow converting HttpFoundation -objects to PSR-7 objects. It provides native support for _`Zend Diactoros`_. +objects to PSR-7 objects. It provides native support for `Zend Diactoros`_. Use Composer (``zendframework/zend-diactoros`` on `Packagist`_) or refer to the project documentation to install it. @@ -86,3 +86,4 @@ to a :class:`Symfony\\Component\\HttpFoundation\\Response` instance:: .. _`PSR-7`: http://www.php-fig.org/psr/psr-7/ .. _Packagist: https://packagist.org/packages/symfony/psr-http-message-bridge +.. _`Zend Diactoros`: https://github.com/zendframework/zend-diactoros From 3878e1426533d4b479bf02a37e2e43c3cbf09dad Mon Sep 17 00:00:00 2001 From: Willem-Jan Date: Thu, 16 Jul 2015 20:40:13 +0200 Subject: [PATCH 4/6] Removed reference to remove HTTPS off from nginx configuration --- cookbook/configuration/web_server_configuration.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/cookbook/configuration/web_server_configuration.rst b/cookbook/configuration/web_server_configuration.rst index 0be18f40d31..2720e8a4f80 100644 --- a/cookbook/configuration/web_server_configuration.rst +++ b/cookbook/configuration/web_server_configuration.rst @@ -269,7 +269,6 @@ The **minimum configuration** to get your application running under Nginx is: fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param HTTPS off; } # PROD location ~ ^/app\.php(/|$) { @@ -277,7 +276,6 @@ The **minimum configuration** to get your application running under Nginx is: fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param HTTPS off; # Prevents URIs that include the front controller. This will 404: # http://domain.tld/app.php/some-path # Remove the internal directive to allow URIs like this From 40eb0bd77d541df88cd2e98a90212316407022e6 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 21 Jul 2015 13:18:00 +0200 Subject: [PATCH 5/6] Misc. improvements in the Console component introduction --- components/console/introduction.rst | 47 +++++++++++++++++------------ 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/components/console/introduction.rst b/components/console/introduction.rst index 81229476e8f..ad772247b62 100644 --- a/components/console/introduction.rst +++ b/components/console/introduction.rst @@ -140,6 +140,9 @@ output. For example:: // white text on a red background $output->writeln('foo'); +The closing tag can be replaced by ````, which revokes all formatting options +established by the last opened tag. + It is possible to define your own styles using the class :class:`Symfony\\Component\\Console\\Formatter\\OutputFormatterStyle`:: @@ -148,23 +151,27 @@ It is possible to define your own styles using the class // ... $style = new OutputFormatterStyle('red', 'yellow', array('bold', 'blink')); $output->getFormatter()->setStyle('fire', $style); - $output->writeln('foo'); + $output->writeln('foo'); Available foreground and background colors are: ``black``, ``red``, ``green``, ``yellow``, ``blue``, ``magenta``, ``cyan`` and ``white``. -And available options are: ``bold``, ``underscore``, ``blink``, ``reverse`` and ``conceal``. +And available options are: ``bold``, ``underscore``, ``blink``, ``reverse`` +(enables the "reverse video" mode where the background and foreground colors +are swapped) and ``conceal`` (sets the foreground color to transparent, making +the typed text invisible - although it can be selected and copied; this option is +commonly used when asking the user to type sensitive information). You can also set these colors and options inside the tagname:: // green text - $output->writeln('foo'); + $output->writeln('foo'); // black text on a cyan background - $output->writeln('foo'); + $output->writeln('foo'); // bold text on a yellow background - $output->writeln('foo'); + $output->writeln('foo'); Verbosity Levels ~~~~~~~~~~~~~~~~ @@ -261,15 +268,15 @@ You can access the ``names`` argument as an array:: $text .= ' '.implode(', ', $names); } -There are 3 argument variants you can use: +There are three argument variants you can use: -=========================== =============================================================================================================== +=========================== =========================================================================================================== Mode Value -=========================== =============================================================================================================== -InputArgument::REQUIRED The argument is required -InputArgument::OPTIONAL The argument is optional and therefore can be omitted -InputArgument::IS_ARRAY The argument can contain an indefinite number of arguments and must be used at the end of the argument list -=========================== =============================================================================================================== +=========================== =========================================================================================================== +``InputArgument::REQUIRED`` The argument is required +``InputArgument::OPTIONAL`` The argument is optional and therefore can be omitted +``InputArgument::IS_ARRAY`` The argument can contain an indefinite number of arguments and must be used at the end of the argument list +=========================== =========================================================================================================== You can combine ``IS_ARRAY`` with ``REQUIRED`` and ``OPTIONAL`` like this:: @@ -342,14 +349,14 @@ will work: There are 4 option variants you can use: -=========================== ===================================================================================== -Option Value -=========================== ===================================================================================== -InputOption::VALUE_IS_ARRAY This option accepts multiple values (e.g. ``--dir=/foo --dir=/bar``) -InputOption::VALUE_NONE Do not accept input for this option (e.g. ``--yell``) -InputOption::VALUE_REQUIRED This value is required (e.g. ``--iterations=5``), the option itself is still optional -InputOption::VALUE_OPTIONAL This option may or may not have a value (e.g. ``--yell`` or ``--yell=loud``) -=========================== ===================================================================================== +=============================== ===================================================================================== +Option Value +=============================== ===================================================================================== +``InputOption::VALUE_IS_ARRAY`` This option accepts multiple values (e.g. ``--dir=/foo --dir=/bar``) +``InputOption::VALUE_NONE`` Do not accept input for this option (e.g. ``--yell``) +``InputOption::VALUE_REQUIRED`` This value is required (e.g. ``--iterations=5``), the option itself is still optional +``InputOption::VALUE_OPTIONAL`` This option may or may not have a value (e.g. ``--yell`` or ``--yell=loud``) +=============================== ===================================================================================== You can combine ``VALUE_IS_ARRAY`` with ``VALUE_REQUIRED`` or ``VALUE_OPTIONAL`` like this: From 65dca624e47bda6c4559b7d37ffe23a51dd8d6f8 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Mon, 6 Jul 2015 14:25:02 +0200 Subject: [PATCH 6/6] updated tree for front controller --- create_framework/front-controller.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/create_framework/front-controller.rst b/create_framework/front-controller.rst index 90e7e69dbb0..c132580f9c4 100644 --- a/create_framework/front-controller.rst +++ b/create_framework/front-controller.rst @@ -146,11 +146,13 @@ web root directory: example.com ├── composer.json - │ src + ├── composer.lock + ├── src │ └── pages │ ├── hello.php │ └── bye.php ├── vendor + │ └── autoload.php └── web └── front.php