Skip to content

Commit

Permalink
Merge branch '2.7' into 2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Sep 5, 2015
2 parents f96eecf + 9eb4b11 commit de141d5
Show file tree
Hide file tree
Showing 25 changed files with 383 additions and 400 deletions.
2 changes: 2 additions & 0 deletions book/http_cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ header value::
namespace AppBundle\Controller;

// ...
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Entity\Article;

Expand All @@ -665,6 +666,7 @@ header value::

$date = $authorDate > $articleDate ? $authorDate : $articleDate;

$response = new Response();
$response->setLastModified($date);
// Set response as public. Otherwise it will be private by default.
$response->setPublic();
Expand Down
41 changes: 41 additions & 0 deletions components/config/definition.rst
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,47 @@ tree with ``append()``::
This is also useful to help you avoid repeating yourself if you have sections
of the config that are repeated in different places.

The example results in the following:

.. configuration-block::

.. code-block:: yaml
database:
connection:
driver: ~ # Required
host: localhost
username: ~
password: ~
memory: false
parameters: # Required
# Prototype
name:
value: ~ # Required
.. code-block:: xml
<database>
<!-- driver: Required -->
<connection
driver=""
host="localhost"
username=""
password=""
memory="false"
>
<!-- prototype -->
<!-- value: Required -->
<parameters
name="parameters name"
value=""
/>
</connection>
</database>
.. _component-config-normalization:

Normalization
Expand Down
6 changes: 5 additions & 1 deletion components/console/helpers/progressbar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,18 @@ you can also set the current progress by calling the
Prior to version 2.6, the progress bar only works if your platform
supports ANSI codes; on other platforms, no output is generated.

.. versionadded:: 2.6
.. tip::

If your platform doesn't support ANSI codes, updates to the progress
bar are added as new lines. To prevent the output from being flooded,
adjust the
:method:`Symfony\\Component\\Console\\Helper\\ProgressBar::setRedrawFrequency`
accordingly. By default, when using a ``max``, the redraw frequency
is set to *10%* of your ``max``.

.. versionadded:: 2.6
The ``setRedrawFrequency()`` method was introduced in Symfony 2.6.

If you don't know the number of steps in advance, just omit the steps argument
when creating the :class:`Symfony\\Component\\Console\\Helper\\ProgressBar`
instance::
Expand Down
171 changes: 104 additions & 67 deletions components/console/helpers/questionhelper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ helper set, which you can get by calling

The Question Helper has a single method
:method:`Symfony\\Component\\Console\\Command\\Command::ask` that needs an
:class:`Symfony\\Component\\Console\\Output\\InputInterface` instance as the
:class:`Symfony\\Component\\Console\\Input\\InputInterface` instance as the
first argument, an :class:`Symfony\\Component\\Console\\Output\\OutputInterface`
instance as the second argument and a
:class:`Symfony\\Component\\Console\\Question\\Question` as last argument.
Expand All @@ -24,14 +24,24 @@ Asking the User for Confirmation
Suppose you want to confirm an action before actually executing it. Add
the following to your command::

use Symfony\Component\Console\Question\ConfirmationQuestion;
// ...
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;

$helper = $this->getHelper('question');
$question = new ConfirmationQuestion('Continue with this action?', false);
class YourCommand extends Command
{
// ...

public function execute(InputInterface $input, OutputInterface $output)
{
$helper = $this->getHelper('question');
$question = new ConfirmationQuestion('Continue with this action?', false);

if (!$helper->ask($input, $output, $question)) {
return;
if (!$helper->ask($input, $output, $question)) {
return;
}
}
}

In this case, the user will be asked "Continue with this action?". If the user
Expand Down Expand Up @@ -66,11 +76,15 @@ You can also ask a question with more than a simple yes/no answer. For instance,
if you want to know a bundle name, you can add this to your command::

use Symfony\Component\Console\Question\Question;
// ...

$question = new Question('Please enter the name of the bundle', 'AcmeDemoBundle');
// ...
public function execute(InputInterface $input, OutputInterface $output)
{
// ...
$question = new Question('Please enter the name of the bundle', 'AcmeDemoBundle');

$bundle = $helper->ask($input, $output, $question);
$bundle = $helper->ask($input, $output, $question);
}

The user will be asked "Please enter the name of the bundle". They can type
some name which will be returned by the
Expand All @@ -86,20 +100,24 @@ which makes sure that the user can only enter a valid string
from a predefined list::

use Symfony\Component\Console\Question\ChoiceQuestion;
// ...

$helper = $this->getHelper('question');
$question = new ChoiceQuestion(
'Please select your favorite color (defaults to red)',
array('red', 'blue', 'yellow'),
0
);
$question->setErrorMessage('Color %s is invalid.');
// ...
public function execute(InputInterface $input, OutputInterface $output)
{
// ...
$helper = $this->getHelper('question');
$question = new ChoiceQuestion(
'Please select your favorite color (defaults to red)',
array('red', 'blue', 'yellow'),
0
);
$question->setErrorMessage('Color %s is invalid.');

$color = $helper->ask($input, $output, $question);
$output->writeln('You have just selected: '.$color);
$color = $helper->ask($input, $output, $question);
$output->writeln('You have just selected: '.$color);

// ... do something with the color
// ... do something with the color
}

The option which should be selected by default is provided with the third
argument of the constructor. The default is ``null``, which means that no
Expand All @@ -120,18 +138,22 @@ feature using comma separated values. This is disabled by default, to enable
this use :method:`Symfony\\Component\\Console\\Question\\ChoiceQuestion::setMultiselect`::

use Symfony\Component\Console\Question\ChoiceQuestion;
// ...

$helper = $this->getHelper('question');
$question = new ChoiceQuestion(
'Please select your favorite colors (defaults to red and blue)',
array('red', 'blue', 'yellow'),
'0,1'
);
$question->setMultiselect(true);
// ...
public function execute(InputInterface $input, OutputInterface $output)
{
// ...
$helper = $this->getHelper('question');
$question = new ChoiceQuestion(
'Please select your favorite colors (defaults to red and blue)',
array('red', 'blue', 'yellow'),
'0,1'
);
$question->setMultiselect(true);

$colors = $helper->ask($input, $output, $question);
$output->writeln('You have just selected: ' . implode(', ', $colors));
$colors = $helper->ask($input, $output, $question);
$output->writeln('You have just selected: ' . implode(', ', $colors));
}

Now, when the user enters ``1,2``, the result will be:
``You have just selected: blue, yellow``.
Expand All @@ -146,13 +168,17 @@ You can also specify an array of potential answers for a given question. These
will be autocompleted as the user types::

use Symfony\Component\Console\Question\Question;
// ...

$bundles = array('AcmeDemoBundle', 'AcmeBlogBundle', 'AcmeStoreBundle');
$question = new Question('Please enter the name of a bundle', 'FooBundle');
$question->setAutocompleterValues($bundles);
// ...
public function execute(InputInterface $input, OutputInterface $output)
{
// ...
$bundles = array('AcmeDemoBundle', 'AcmeBlogBundle', 'AcmeStoreBundle');
$question = new Question('Please enter the name of a bundle', 'FooBundle');
$question->setAutocompleterValues($bundles);

$name = $helper->ask($input, $output, $question);
$name = $helper->ask($input, $output, $question);
}

Hiding the User's Response
~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -161,13 +187,17 @@ You can also ask a question and hide the response. This is particularly
convenient for passwords::

use Symfony\Component\Console\Question\Question;
// ...

$question = new Question('What is the database password?');
$question->setHidden(true);
$question->setHiddenFallback(false);
// ...
public function execute(InputInterface $input, OutputInterface $output)
{
// ...
$question = new Question('What is the database password?');
$question->setHidden(true);
$question->setHiddenFallback(false);

$password = $helper->ask($input, $output, $question);
$password = $helper->ask($input, $output, $question);
}

.. caution::

Expand All @@ -189,20 +219,24 @@ be suffixed with ``Bundle``. You can validate that by using the
method::

use Symfony\Component\Console\Question\Question;
// ...

$question = new Question('Please enter the name of the bundle', 'AcmeDemoBundle');
$question->setValidator(function ($answer) {
if ('Bundle' !== substr($answer, -6)) {
throw new \RuntimeException(
'The name of the bundle should be suffixed with \'Bundle\''
);
}
return $answer;
});
$question->setMaxAttempts(2);

$name = $helper->ask($input, $output, $question);
// ...
public function execute(InputInterface $input, OutputInterface $output)
{
// ...
$question = new Question('Please enter the name of the bundle', 'AcmeDemoBundle');
$question->setValidator(function ($answer) {
if ('Bundle' !== substr($answer, -6)) {
throw new \RuntimeException(
'The name of the bundle should be suffixed with \'Bundle\''
);
}
return $answer;
});
$question->setMaxAttempts(2);

$name = $helper->ask($input, $output, $question);
}

The ``$validator`` is a callback which handles the validation. It should
throw an exception if there is something wrong. The exception message is displayed
Expand All @@ -222,23 +256,26 @@ Validating a Hidden Response
You can also use a validator with a hidden question::

use Symfony\Component\Console\Question\Question;
// ...

$helper = $this->getHelper('question');

$question = new Question('Please enter your password');
$question->setValidator(function ($value) {
if (trim($value) == '') {
throw new \Exception('The password can not be empty');
}
// ...
public function execute(InputInterface $input, OutputInterface $output)
{
// ...
$helper = $this->getHelper('question');

return $value;
});
$question->setHidden(true);
$question->setMaxAttempts(20);
$question = new Question('Please enter your password');
$question->setValidator(function ($value) {
if (trim($value) == '') {
throw new \Exception('The password can not be empty');
}

$password = $helper->ask($input, $output, $question);
return $value;
});
$question->setHidden(true);
$question->setMaxAttempts(20);

$password = $helper->ask($input, $output, $question);
}

Testing a Command that Expects Input
------------------------------------
Expand Down Expand Up @@ -276,6 +313,6 @@ from the command line, you need to set the helper input stream::
}

By setting the input stream of the ``QuestionHelper``, you imitate what the
console would do internally with all user input through the cli. This way
console would do internally with all user input through the CLI. This way
you can test any user interaction (even complex ones) by passing an appropriate
input stream.
6 changes: 3 additions & 3 deletions components/form/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ to bootstrap or access Twig and add the :class:`Symfony\\Bridge\\Twig\\Extension
$defaultFormTheme = 'form_div_layout.html.twig';

$vendorDir = realpath(__DIR__.'/../vendor');
// the path to TwigBridge so Twig can locate the
// the path to TwigBridge library so Twig can locate the
// form_div_layout.html.twig file
$vendorTwigBridgeDir =
$vendorDir.'/symfony/twig-bridge/Symfony/Bridge/Twig';
$appVariableReflection = new \ReflectionClass('\Symfony\Bridge\Twig\AppVariable');
$vendorTwigBridgeDir = dirname($appVariableReflection->getFileName());
// the path to your other templates
$viewsDir = realpath(__DIR__.'/../views');

Expand Down
5 changes: 0 additions & 5 deletions components/security/secure_tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ algorithm; you can use the same strategy in your own code thanks to the
// is some known string (e.g. password) equal to some user input?
$bool = StringUtils::equals($knownString, $userInput);

.. caution::

To avoid timing attacks, the known string must be the first argument
and the user-entered string the second.

Generating a Secure random Number
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
3 changes: 2 additions & 1 deletion contributing/community/reviews.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ Pick a pull request from the `PRs in need of review`_ and follow these steps:
$ git fetch origin pull/15723/head:pr15723
$ git checkout pr15723
Now you can test the project against the code in the PR.
Now you can :doc:`test the project </contributing/code/tests>` against
the code in the PR.

#. **Update the PR Status**

Expand Down
10 changes: 7 additions & 3 deletions cookbook/controller/service.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,13 @@ the route ``_controller`` value:
defined as a service. See the `FrameworkExtraBundle documentation`_ for
details.

.. versionadded:: 2.6
If your controller service implements the ``__invoke`` method, you can simply refer to the service id
(``app.hello_controller``).
.. tip::

If your controller implements the ``__invoke()`` method, you can simply
refer to the service id (``app.hello_controller``).

.. versionadded:: 2.6
Support for ``__invoke()`` was introduced in Symfony 2.6.

Alternatives to base Controller Methods
---------------------------------------
Expand Down
Loading

0 comments on commit de141d5

Please sign in to comment.