Skip to content

Commit

Permalink
Merge branch '5.3' into 5.4
Browse files Browse the repository at this point in the history
* 5.3:
  Minor tweaks
  Adds a heading for stampede prevention so I'm able to reference this section easily
  [symfony#15270] Minor fixes
  [Console] Document console cursor
  [Security] changed interface name to the correct one
  [Form] Fixed a code example related to CSRF
  Update routing.rst
  Typo
  • Loading branch information
javiereguiluz committed Jun 17, 2021
2 parents 8522d98 + 2e413af commit 30adacd
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 9 deletions.
1 change: 1 addition & 0 deletions .doctor-rst.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,4 @@ whitelist:
- '.. versionadded:: 3.6' # MonologBundle
- '// bin/console'
- 'End to End Tests (E2E)'
- '.. code-block:: php'
Binary file added _images/components/console/cursor.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion components/cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ generate and return the value::
Use cache tags to delete more than one key at the time. Read more at
:doc:`/components/cache/cache_invalidation`.

The Cache Contracts also comes with built in `Stampede prevention`_. This will
Stampede Prevention
~~~~~~~~~~~~~~~~~~~

The Cache Contracts also come with built in `Stampede prevention`_. This will
remove CPU spikes at the moments when the cache is cold. If an example application
spends 5 seconds to compute data that is cached for 1 hour and this data is accessed
10 times every second, this means that you mostly have cache hits and everything
Expand Down
104 changes: 104 additions & 0 deletions components/console/helpers/cursor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
.. index::
single: Console Helpers; Cursor Helper

Cursor Helper
=============

.. versionadded:: 5.1

The :class:`Symfony\\Component\\Console\\Cursor` class was introduced
in Symfony 5.1.

The :class:`Symfony\\Component\\Console\\Cursor` allows you to change the
cursor position in a console command. This allows you to write on any position
of the output:

.. image:: /_images/components/console/cursor.gif
:align: center

.. code-block:: php
// src/Command/MyCommand.php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Cursor;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class MyCommand extends Command
{
// ...
public function execute(InputInterface $input, OutputInterface $output): int
{
// ...
$cursor = new Cursor($output);
// moves the cursor to a specific column (1st argument) and
// row (2nd argument) position
$cursor->moveToPosition(7, 11);
// and write text on this position using the output
$output->write('My text');
// ...
}
}
Using the cursor
----------------

Moving the cursor
.................

There are fews methods to control moving the command cursor::

// moves the cursor 1 line up from its current position
$cursor->moveUp();

// moves the cursor 3 lines up from its current position
$cursor->moveUp(3);

// same for down
$cursor->moveDown();

// moves the cursor 1 column right from its current position
$cursor->moveRight();

// moves the cursor 3 columns right from its current position
$cursor->moveRight(3);

// same for left
$cursor->moveLeft();

// move the cursor to a specific (column, row) position from the
// top-left position of the terminal
$cursor->moveToPosition(7, 11);

You can get the current command's cursor position by using::

$position = $cursor->getCurrentPosition();
// $position[0] // columns (aka x coordinate)
// $position[1] // rows (aka y coordinate)

Clearing output
...............

The cursor can also clear some output on the screen::

// clears all the output from the current line
$cursor->clearLine();

// clears all the output from the current line after the current position
$cursor->clearLineAfter();

// clears all the output from the cursors' current position to the end of the screen
$cursor->clearOutput();

// clears the entire screen
$cursor->clearScreen();

You also can leverage the :method:`Symfony\\Component\\Console\\Cursor::show`
and :method:`Symfony\\Component\\Console\\Cursor::hide` methods on the cursor.
1 change: 1 addition & 0 deletions components/console/helpers/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The Console Helpers
questionhelper
table
debug_formatter
cursor

The Console component comes with some useful helpers. These helpers contain
functions to ease some common tasks.
Expand Down
1 change: 1 addition & 0 deletions components/console/helpers/map.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
* :doc:`/components/console/helpers/questionhelper`
* :doc:`/components/console/helpers/table`
* :doc:`/components/console/helpers/debug_formatter`
* :doc:`/components/console/helpers/cursor`
2 changes: 1 addition & 1 deletion components/console/helpers/progressbar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ placeholder before displaying the progress bar::
// 0/100 -- Start

$progressBar->setMessage('Task is in progress...');
$progressBar->advance();
$progressBar->advance();
// 1/100 -- Task is in progress...

Messages can be combined with custom placeholders too. In this example, the
Expand Down
9 changes: 5 additions & 4 deletions components/form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,17 @@ The following snippet adds CSRF protection to the form factory::

use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
use Symfony\Component\Form\Forms;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Csrf\CsrfTokenManager;
use Symfony\Component\Security\Csrf\TokenGenerator\UriSafeTokenGenerator;
use Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage;

// creates a Session object from the HttpFoundation component
$session = new Session();
// creates a RequestStack object using the current request
$requestStack = new RequestStack();
$requestStack->push($request);

$csrfGenerator = new UriSafeTokenGenerator();
$csrfStorage = new SessionTokenStorage($session);
$csrfStorage = new SessionTokenStorage($requestStack);
$csrfManager = new CsrfTokenManager($csrfGenerator, $csrfStorage);

$formFactory = Forms::createFormFactoryBuilder()
Expand Down
2 changes: 1 addition & 1 deletion components/ldap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ delete existing ones::
.. versionadded:: 5.3

The option to make attribute names case-insensitive in ``getAttribute()``
and ``hasAttribute()`` was introduce in Symfony 5.3.
and ``hasAttribute()`` was introduced in Symfony 5.3.

Batch Updating
______________
Expand Down
1 change: 1 addition & 0 deletions console.rst
Original file line number Diff line number Diff line change
Expand Up @@ -454,5 +454,6 @@ tools capable of helping you with different tasks:
* :doc:`/components/console/helpers/table`: displays tabular data as a table
* :doc:`/components/console/helpers/debug_formatter`: provides functions to
output debug information when running an external program
* :doc:`/components/console/helpers/cursor`: allows to manipulate the cursor in the terminal

.. _`exit status`: https://en.wikipedia.org/wiki/Exit_status
2 changes: 1 addition & 1 deletion routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2431,7 +2431,7 @@ use the ``generateUrl()`` helper::

While objects are converted to string when used as placeholders, they are not
converted when used as extra parameters. So, if you're passing an object (e.g. an Uuid)
as value of an extra parameter, you need to explictly convert it to a string::
as value of an extra parameter, you need to explicitly convert it to a string::

$this->generateUrl('blog', ['uuid' => (string) $entity->getUuid()]);

Expand Down
2 changes: 1 addition & 1 deletion security/named_hashers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ the name of the hasher to use::
}

If you created your own password hasher implementing the
:class:`Symfony\\Component\\PasswordHasher\\Hasher\\UserPasswordHasherInterface`,
:class:`Symfony\\Component\\PasswordHasher\\PasswordHasherInterface`,
you must register a service for it in order to use it as a named hasher:

.. configuration-block::
Expand Down

0 comments on commit 30adacd

Please sign in to comment.