8000 Merge branch '3.4' into 4.0 · symfony/symfony-docs@81943ab · GitHub
[go: up one dir, main page]

Skip to content

Commit 81943ab

Browse files
committed
Merge branch '3.4' into 4.0
* 3.4: Clarify unanimous access strategy description Improved variable naming
2 parents 0195c22 + 22fd27b commit 81943ab

File tree

93 files changed

+561
-565
lines changed
  • security
  • translation
  • console
  • controller
  • create_framework
  • doctrine
  • event_dispatcher
  • form
  • introduction
  • reference
  • routing
  • security
  • service_container
  • templating
  • testing
  • translation
  • validation
  • Some content is hidden

    Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

    93 files changed

    +561
    -565
    lines changed

    best_practices/configuration.rst

    Lines changed: 5 additions & 5 deletions

    Original file line numberDiff line numberDiff line change
    @@ -103,20 +103,20 @@ to control the number of posts to display on the blog homepage:
    103103
    104104
    # config/services.yaml
    105105
    parameters:
    106-
    homepage.num_items: 10
    106+
    homepage.number_of_items: 10
    107107
    108108
    If you've done something like this in the past, it's likely that you've in fact
    109109
    *never* actually needed to change that value. Creating a configuration
    110110
    option for a value that you are never going to configure just isn't necessary.
    111111
    Our recommendation is to define these values as constants in your application.
    112-
    You could, for example, define a ``NUM_ITEMS`` constant in the ``Post`` entity::
    112+
    You could, for example, define a ``NUMBER_OF_ITEMS`` constant in the ``Post`` entity::
    113113

    114114
    // src/Entity/Post.php
    115115
    namespace App\Entity;
    116116

    117117
    class Post
    118118
    {
    119-
    const NUM_ITEMS = 10;
    119+
    const NUMBER_OF_ITEMS = 10;
    120120
    121121
    // ...
    122122
    }
    @@ -131,7 +131,7 @@ Constants can be used for example in your Twig templates thanks to the
    131131
    .. code-block:: html+twig
    132132

    133133
    <p>
    134-
    Displaying the {{ constant('NUM_ITEMS', post) }} most recent results.
    134+
    Displaying the {{ constant('NUMBER_OF_ITEMS', post) }} most recent results.
    135135
    </p>
    136136

    137137
    And Doctrine entities and repositories can now easily access these values,
    @@ -146,7 +146,7 @@ whereas they cannot access the container parameters:
    146146
    147147
    class PostRepository extends EntityRepository
    148148
    {
    149-
    public function findLatest($limit = Post::NUM_ITEMS)
    149+
    public function findLatest($limit = Post::NUMBER_OF_ITEMS)
    150150
    {
    151151
    // ...
    152152
    }

    best_practices/forms.rst

    Lines changed: 3 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -175,9 +175,9 @@ Handling a form submit usually follows a similar template:
    175175
    $form->handleRequest($request);
    176176
    177177
    if ($form->isSubmitted() && $form->isValid()) {
    178-
    $em = $this->getDoctrine()->getManager();
    179-
    $em->persist($post);
    180-
    $em->flush();
    178+
    $entityManager = $this->getDoctrine()->getManager();
    179+
    $entityManager->persist($post);
    180+
    $entityManager->flush();
    181181
    182182
    return $this->redirectToRoute('admin_post_show', [
    183183
    'id' => $post->getId()

    bundles/configuration.rst

    Lines changed: 3 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -258,9 +258,9 @@ In your extension, you can load this and dynamically set its arguments::
    258258
    $configuration = new Configuration();
    259259
    $config = $this->processConfiguration($configuration, $configs);
    260260

    261-
    $def = $container->getDefinition('acme.social.twitter_client');
    262-
    $def->replaceArgument(0, $config['twitter']['client_id']);
    263-
    $def->replaceArgument(1, $config['twitter']['client_secret']);
    261+
    $definition = $container->getDefinition('acme.social.twitter_client');
    262+
    $definition->replaceArgument(0, $config['twitter']['client_id']);
    263+
    $definition->replaceArgument(1, $config['twitter']['client_secret']);
    264264
    }
    265265

    266266
    .. tip::

    components/asset.rst

    Lines changed: 13 additions & 13 deletions
    Original file line numberDiff line numberDiff line change
    @@ -179,9 +179,9 @@ that path over and over again::
    179179
    use Symfony\Component\Asset\PathPackage;
    180180
    // ...
    181181

    182-
    $package = new PathPackage('/static/images', new StaticVersionStrategy('v1'));
    182+
    $pathPackage = new PathPackage('/static/images', new StaticVersionStrategy('v1'));
    183183

    184-
    echo $package->getUrl('logo.png');
    184+
    echo $pathPackage->getUrl('logo.png');
    185185
    // result: /static/images/logo.png?v1
    186186

    187187
    // Base path is ignored when using absolute paths
    @@ -199,13 +199,13 @@ class can take into account the context of the current request::
    199199
    use Symfony\Component\Asset\Context\RequestStackContext;
    200200
    // ...
    201201

    202-
    $package = new PathPackage(
    202+
    $pathPackage = new PathPackage(
    203203
    '/static/images',
    204204
    new StaticVersionStrategy('v1'),
    205205
    new RequestStackContext($requestStack)
    206206
    );
    207207

    208-
    echo $package->getUrl('logo.png');
    208+
    echo $pathPackage->getUrl('logo.png');
    209209
    // result: /somewhere/static/images/logo.png?v1
    210210

    211211
    // Both "base path" and "base url" are ignored when using absolute path for asset
    @@ -230,25 +230,25 @@ class to generate absolute URLs for their assets::
    230230
    use Symfony\Component\Asset\UrlPackage;
    231231
    // ...
    232232

    233-
    $package = new UrlPackage(
    233+
    $urlPackage = new UrlPackage(
    234234
    'http://static.example.com/images/',
    235235
    new StaticVersionStrategy('v1')
    236236
    );
    237237

    238-
    echo $package->getUrl('/logo.png');
    238+
    echo $urlPackage->getUrl('/logo.png');
    239239
    // result: http://static.example.com/images/logo.png?v1
    240240

    241241
    You can also pass a schema-agnostic URL::
    242242

    243243
    use Symfony\Component\Asset\UrlPackage;
    244244
    // ...
    245245

    246-
    $package = new UrlPackage(
    246+
    $urlPackage = new UrlPackage(
    247247
    '//static.example.com/images/',
    248248
    new StaticVersionStrategy('v1')
    249249
    );
    250250

    251-
    echo $package->getUrl('/logo.png');
    251+
    echo $urlPackage->getUrl('/logo.png');
    252252
    // result: //static.example.com/images/logo.png?v1
    253253

    254254
    This is useful because assets will automatically be requested via HTTPS if
    @@ -266,11 +266,11 @@ constructor::
    266266
    '//static1.example.com/images/',
    267267
    '//static2.example.com/images/',
    268268
    );
    269-
    $package = new UrlPackage($urls, new StaticVersionStrategy('v1'));
    269+
    $urlPackage = new UrlPackage($urls, new StaticVersionStrategy('v1'));
    270270

    271-
    echo $package->getUrl('/logo.png');
    271+
    echo $urlPackage->getUrl('/logo.png');
    272272
    // result: http://static1.example.com/images/logo.png?v1
    273-
    echo $package->getUrl('/icon.png');
    273+
    echo $urlPackage->getUrl('/icon.png');
    274274
    // result: http://static2.example.com/images/icon.png?v1
    275275

    276276
    For each asset, one of the URLs will be randomly used. But, the selection
    @@ -289,13 +289,13 @@ protocol-relative URLs for HTTPs requests, any base URL for HTTP requests)::
    289289
    use Symfony\Component\Asset\Context\RequestStackContext;
    290290
    // ...
    291291

    292-
    $package = new UrlPackage(
    292+
    $urlPackage = new UrlPackage(
    293293
    array('http://example.com/', 'https://example.com/'),
    294294
    new StaticVersionStrategy('v1'),
    295295
    new RequestStackContext($requestStack)
    296296
    );
    297297

    298-
    echo $package->getUrl('/logo.png');
    298+
    echo $urlPackage->getUrl('/logo.png');
    299299
    // assuming the RequestStackContext says that we are on a secure host
    300300
    // result: https://example.com/logo.png?v1
    301301

    components/browser_kit.rst

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -140,8 +140,8 @@ retrieve any cookie while making requests with the client::
    140140
    // Get cookie data
    141141
    $name = $cookie->getName();
    142142
    $value = $cookie->getValue();
    143-
    $raw = $cookie->getRawValue();
    144-
    $secure = $cookie->isSecure();
    143+
    $rawValue = $cookie->getRawValue();
    144+
    $isSecure = $cookie->isSecure();
    145145
    $isHttpOnly = $cookie->isHttpOnly();
    146146
    $isExpired = $cookie->isExpired();
    147147
    $expires = $cookie->getExpiresTime();

    components/cache/cache_pools.rst

    Lines changed: 4 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -175,10 +175,10 @@ its compatibe cache adapters (and those that do not implement ``PruneableInterfa
    175175
    silently ignored)::
    176176

    177177
    use Symfony\Component\Cache\Adapter\ApcuAdapter;
    178-
    use Syfmony\Component\Cache\Adapter\ChainAdapter;
    179-
    use Syfmony\Component\Cache\Adapter\FilesystemAdapter;
    180-
    use Syfmony\Component\Cache\Adapter\PdoAdapter;
    181-
    use Syfmony\Component\Cache\Adapter\PhpFilesAdapter;
    178+
    use Symfony\Component\Cache\Adapter\ChainAdapter;
    179+
    use Symfony\Component\Cache\Adapter\FilesystemAdapter;
    180+
    use Symfony\Component\Cache\Adapter\PdoAdapter;
    181+
    use Symfony\Component\Cache\Adapter\PhpFilesAdapter;
    182182

    183183
    $cache = new ChainAdapter(array(
    184184
    new ApcuAdapter(), // does NOT implement PruneableInterface

    components/config/definition.rst

    Lines changed: 7 additions & 7 deletions
    Original file line numberDiff line numberDiff line change
    @@ -565,8 +565,8 @@ tree with ``append()``::
    565565

    566566
    public function addParametersNode()
    567567
    {
    568-
    $builder = new TreeBuilder();
    569-
    $node = $builder->root('parameters');
    568+
    $treeBuilder = new TreeBuilder();
    569+
    $node = $treeBuilder->root('parameters');
    570570

    571571
    $node
    572572
    ->isRequired()
    @@ -803,18 +803,18 @@ Otherwise the result is a clean array of configuration values::
    803803
    use Symfony\Component\Config\Definition\Processor;
    804804
    use Acme\DatabaseConfiguration;
    805805

    806-
    $config1 = Yaml::parse(
    806+
    $config = Yaml::parse(
    807807
    file_get_contents(__DIR__.'/src/Matthias/config/config.yaml')
    808808
    );
    809-
    $config2 = Yaml::parse(
    809+
    $extraConfig = Yaml::parse(
    810810
    file_get_contents(__DIR__.'/src/Matthias/config/config_extra.yaml')
    811811
    );
    812812

    813-
    $configs = array($config1, $config2);
    813+
    $configs = array($config, $extraConfig);
    814814

    815815
    $processor = new Processor();
    816-
    $configuration = new DatabaseConfiguration();
    816+
    $databaseConfiguration = new DatabaseConfiguration();
    817817
    $processedConfiguration = $processor->processConfiguration(
    818-
    $configuration,
    818+
    $databaseConfiguration,
    819819
    $configs
    820820
    );

    components/config/resources.rst

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -21,7 +21,7 @@ files. This can be done with the :class:`Symfony\\Component\\Config\\FileLocator
    2121

    2222
    $configDirectories = array(__DIR__.'/config');
    2323

    24-
    $locator = new FileLocator($configDirectories);
    24+
    $fileLocator = new FileLocator($configDirectories);
    2525
    $yamlUserFiles = $locator->locate('users.yaml', null, false);
    2626

    2727
    The locator receives a collection of locations where it should look for
    @@ -84,7 +84,7 @@ the resource::
    8484
    use Symfony\Component\Config\Loader\LoaderResolver;
    8585
    use Symfony\Component\Config\Loader\DelegatingLoader;
    8686

    87-
    $loaderResolver = new LoaderResolver(array(new YamlUserLoader($locator)));
    87+
    $loaderResolver = new LoaderResolver(array(new YamlUserLoader($fileLocator)));
    8888
    $delegatingLoader = new DelegatingLoader($loaderResolver);
    8989

    9090
    // YamlUserLoader is used to load this resource because it supports

    components/console/helpers/progressbar.rst

    Lines changed: 23 additions & 23 deletions
    +
    $progressBar->advance();
    Original file line numberDiff line numberDiff line change
    @@ -16,24 +16,24 @@ number of units, and advance the progress as the command executes::
    1616
    use Symfony\Component\Console\Helper\ProgressBar;
    1717

    1818
    // creates a new progress bar (50 units)
    19-
    $progress = new ProgressBar($output, 50);
    19+
    $progressBar = new ProgressBar($output, 50);
    2020

    2121
    // starts and displays the progress bar
    22-
    $progress->start();
    22+
    $progressBar->start();
    2323

    2424
    $i = 0;
    2525
    while ($i++ < 50) {
    2626
    // ... do some work
    2727

    2828
    // advances the progress bar 1 unit
    29-
    $progress->advance();
    29
    3030

    3131
    // you can also advance the progress bar by more than 1 unit
    32-
    // $progress->advance(3);
    32+
    // $progressBar->advance(3);
    3333
    }
    3434

    3535
    // ensures that the progress bar is at 100%
    36-
    $progress->finish();
    36+
    $progressBar->finish();
    3737

    3838
    .. tip::
    3939

    @@ -59,7 +59,7 @@ If you don't know the number of steps in advance, just omit the steps argument
    5959
    when creating the :class:`Symfony\\Component\\Console\\Helper\\ProgressBar`
    6060
    instance::
    6161

    62-
    $progress = new ProgressBar($output);
    62+
    $progressBar = new ProgressBar($output);
    6363

    6464
    The progress will then be displayed as a throbber:
    6565

    @@ -126,7 +126,7 @@ level of verbosity of the ``OutputInterface`` instance:
    126126
    Instead of relying on the verbosity mode of the current command, you can also
    127127
    force a format via ``setFormat()``::
    128128

    129-
    $bar->setFormat('verbose');
    129+
    $progressBar->setFormat('verbose');
    130130

    131131
    The built-in formats are the following:
    132132

    @@ -148,7 +148,7 @@ Custom Formats
    148148

    149149
    Instead of using the built-in formats, you can also set your own::
    150150

    151-
    $bar->setFormat('%bar%');
    151+
    $progressBar->setFormat('%bar%');
    152152

    153153
    This sets the format to only display the progress bar itself:
    154154

    @@ -175,7 +175,7 @@ current progress of the bar. Here is a list of the built-in placeholders:
    175175
    For instance, here is how you could set the format to be the same as the
    176176
    ``debug`` one::
    177177

    178-
    $bar->setFormat(' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%');
    178+
    $progressBar->setFormat(' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%');
    179179

    180180
    Notice the ``:6s`` part added to some placeholders? That's how you can tweak
    181181
    the appearance of the bar (formatting and alignment). The part after the colon
    @@ -186,8 +186,8 @@ also define global formats::
    186186

    187187
    ProgressBar::setFormatDefinition('minimal', 'Progress: %percent%%');
    188188

    189-
    $bar = new ProgressBar($output, 3);
    190-
    $bar->setFormat('minimal');
    189+
    $progressBar = new ProgressBar($output, 3);
    190+
    $progressBar->setFormat('minimal');
    191191

    192192
    This code defines a new ``minimal`` format that you can then use for your
    193193
    progress bars:
    @@ -211,8 +211,8 @@ variant::
    211211
    ProgressBar::setFormatDefinition('minimal', '%percent%% %remaining%');
    212212
    ProgressBar::setFormatDefinition('minimal_nomax', '%percent%%');
    213213

    214-
    $bar = new ProgressBar($output);
    215-
    $bar->setFormat('minimal');
    214+
    $progressBar = new ProgressBar($output);
    215+
    $progressBar->setFormat('minimal');
    216216

    217217
    When displaying the progress bar, the format will automatically be set to
    218218
    ``minimal_nomax`` if the bar does not have a maximum number of steps like in
    @@ -241,16 +241,16 @@ Amongst the placeholders, ``bar`` is a bit special as all the characters used
    241241
    to display it can be customized::
    242242

    243243
    // the finished part of the bar
    244-
    $progress->setBarCharacter('<comment>=</comment>');
    244+
    $progressBar->setBarCharacter('<comment>=</comment>');
    245245

    246246
    // the unfinished part of the bar
    247-
    $progress->setEmptyBarCharacter(' ');
    247+
    $progressBar->setEmptyBarCharacter(' ');
    248248

    249249
    // the progress character
    250-
    $progress->setProgressCharacter('|');
    250+
    $progressBar->setProgressCharacter('|');
    251251

    252252
    // the bar width
    253-
    $progress->setBarWidth(50);
    253+
    $progressBar->setBarWidth(50);
    254254

    255255
    .. caution::
    256256

    @@ -260,17 +260,17 @@ to display it can be customized::
    260260
    :method:`Symfony\\Component\\Console\\Helper\\ProgressBar::setRedrawFrequency`,
    261261
    so it updates on only some iterations::
    262262

    263-
    $progress = new ProgressBar($output, 50000);
    264-
    $progress->start();
    263+
    $progressBar = new ProgressBar($output, 50000);
    264+
    $progressBar->start();
    265265

    266266
    // update every 100 iterations
    267-
    $progress->setRedrawFrequency(100);
    267+
    $progressBar->setRedrawFrequency(100);
    268268

    269269
    $i = 0;
    270270
    while ($i++ < 50000) {
    271271
    // ... do some work
    272272

    273-
    $progress->advance();
    273+
    $progressBar->advance();
    274274
    }
    275275

    276276
    Custom Placeholders
    @@ -283,8 +283,8 @@ that displays the number of remaining steps::
    283283

    284284
    ProgressBar::setPlaceholderFormatterDefinition(
    285285
    'remaining_steps',
    286-
    function (ProgressBar $bar, OutputInterface $output) {
    287-
    return $bar->getMaxSteps() - $bar->getProgress();
    286+
    function (ProgressBar $progressBar, OutputInterface $output) {
    287+
    return $progressBar->getMaxSteps() - $progressBar->getProgress();
    288288
    }
    289289
    );
    290290

    0 commit comments

    Comments
     (0)
    0