Skip to content

Commit d085989

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 8fcc599 + 2b027a9 commit d085989

22 files changed

+370
-132
lines changed

best_practices/business-logic.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Inside here, you can create whatever directories you want to organize things:
1515

1616
.. code-block:: text
1717
18-
symfony2-project/
18+
symfony-project/
1919
├─ app/
2020
├─ src/
2121
│ └─ AppBundle/
@@ -35,7 +35,7 @@ and put things there:
3535

3636
.. code-block:: text
3737
38-
symfony2-project/
38+
symfony-project/
3939
├─ app/
4040
├─ src/
4141
│ ├─ Acme/
@@ -180,7 +180,7 @@ The three entities defined by our sample blog application are a good example:
180180

181181
.. code-block:: text
182182
183-
symfony2-project/
183+
symfony-project/
184184
├─ ...
185185
└─ src/
186186
└─ AppBundle/

best_practices/controllers.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ it more difficult to know which template is being rendered. It also makes
8585
it less obvious to beginners that a controller should always return a Response
8686
object (unless you're using a view layer).
8787

88-
How the Controller Looks
89-
------------------------
88+
What does the Controller look like
89+
----------------------------------
9090

91-
Considering all this, here is an example of how the controller should look
91+
Considering all this, here is an example of what the controller should look like
9292
for the homepage of our app:
9393

9494
.. code-block:: php

components/cache/cache_pools.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ is ``getItem($key)``, which returns the cache item identified by the given key::
169169

170170
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
171171

172-
$cache = new FilesystemAdapter('app.cache')
172+
$cache = new FilesystemAdapter('app.cache');
173173
$latestNews = $cache->getItem('latest_news');
174174

175175
If no item is defined for the given key, the method doesn't return a ``null``

components/console/single_command_tool.rst

Lines changed: 48 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -6,68 +6,51 @@ Building a single Command Application
66

77
When building a command line tool, you may not need to provide several commands.
88
In such case, having to pass the command name each time is tedious. Fortunately,
9-
it is possible to remove this need by extending the application::
10-
11-
namespace Acme\Tool;
12-
13-
use Symfony\Component\Console\Application;
14-
use Symfony\Component\Console\Input\InputInterface;
15-
16-
class MyApplication extends Application
17-
{
18-
/**
19-
* Gets the name of the command based on input.
20-
*
21-
* @param InputInterface $input The input interface
22-
*
23-
* @return string The command name
24-
*/
25-
protected function getCommandName(InputInterface $input)
26-
{
27-
// This should return the name of your command.
28-
return 'my_command';
29-
}
30-
31-
/**
32-
* Gets the default commands that should always be available.
33-
*
34-
* @return array An array of default Command instances
35-
*/
36-
protected function getDefaultCommands()
37-
{
38-
// Keep the core default commands to have the HelpCommand
39-
// which is used when using the --help option
40-
$defaultCommands = parent::getDefaultCommands();
41-
42-
$defaultCommands[] = new MyCommand();
43-
44-
return $defaultCommands;
45-
}
46-
47-
/**
48-
* Overridden so that the application doesn't expect the command
49-
* name to be the first argument.
50-
*/
51-
public function getDefinition()
52-
{
53-
$inputDefinition = parent::getDefinition();
54-
// clear out the normal first argument, which is the command name
55-
$inputDefinition->setArguments();
56-
57-
return $inputDefinition;
58-
}
59-
}
60-
61-
When calling your console script, the command ``MyCommand`` will then always
62-
be used, without having to pass its name.
63-
64-
You can also simplify how you execute the application::
65-
66-
#!/usr/bin/env php
67-
<?php
68-
// command.php
69-
70-
use Acme\Tool\MyApplication;
71-
72-
$application = new MyApplication();
73-
$application->run();
9+
it is possible to remove this need by declaring a single command application::
10+
11+
#!/usr/bin/env php
12+
<?php
13+
require __DIR__.'/vendor/autoload.php';
14+
15+
use Symfony\Component\Console\Application;
16+
use Symfony\Component\Console\Input\InputArgument;
17+
use Symfony\Component\Console\Input\InputInterface;
18+
use Symfony\Component\Console\Input\InputOption;
19+
use Symfony\Component\Console\Output\OutputInterface;
20+
21+
(new Application('echo', '1.0.0'))
22+
->register('echo')
23+
->addArgument('foo', InputArgument::OPTIONAL, 'The directory')
24+
->addOption('bar', null, InputOption::VALUE_REQUIRED)
25+
->setCode(function(InputInterface $input, OutputInterface $output) {
26+
// output arguments and options
27+
})
28+
->getApplication()
29+
->setDefaultCommand('echo', true) // Single command application
30+
->run();
31+
32+
The method :method:`Symfony\\Component\\Console\\Application::setDefaultCommand`
33+
accepts a boolean as second parameter. If true, the command ``echo`` will then
34+
always be used, without having to pass its name.
35+
36+
Of course, you can still register a command as usual::
37+
38+
#!/usr/bin/env php
39+
<?php
40+
require __DIR__.'/vendor/autoload.php';
41+
42+
use Symfony\Component\Console\Application;
43+
use Symfony\Component\Console\Input\InputArgument;
44+
use Symfony\Component\Console\Input\InputInterface;
45+
use Symfony\Component\Console\Input\InputOption;
46+
use Symfony\Component\Console\Output\OutputInterface;
47+
48+
use Acme\Command\DefaultCommand;
49+
50+
$application = new Application('echo', '1.0.0');
51+
$command = new DefaultCommand();
52+
53+
$application->add($command);
54+
55+
$application->setDefaultCommand($command->getName(), true);
56+
$application->run();

components/expression_language.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ How can the Expression Engine Help Me?
2121
--------------------------------------
2222

2323
The purpose of the component is to allow users to use expressions inside
24-
configuration for more complex logic. For some examples, the Symfony2 Framework
24+
configuration for more complex logic. For some examples, the Symfony Framework
2525
uses expressions in security, for validation rules and in route matching.
2626

2727
Besides using the component in the framework itself, the ExpressionLanguage

components/filesystem.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ On POSIX filesystems, directories are created with a default mode value
6060
You can pass an array or any :phpclass:`Traversable` object as the first
6161
argument.
6262

63+
.. note::
64+
65+
This function ignores already existing directories.
66+
6367
exists
6468
~~~~~~
6569

components/routing.rst

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,185 @@ automatically in the background if you want to use it. A basic example of the
346346
are saved in the ``cache_dir``. This means your script must have write
347347
permissions for that location.
348348

349+
Unicode Routing Support
350+
~~~~~~~~~~~~~~~~~~~~~~~
351+
352+
.. versionadded:: 3.2
353+
UTF-8 support for route paths and requirements was introduced in
354+
Symfony 3.2.
355+
356+
The Routing component supports UTF-8 characters in route paths and requirements.
357+
Thanks to the ``utf8`` route option, you can make Symfony match and generate
358+
routes with UTF-8 characters:
359+
360+
.. configuration-block::
361+
362+
.. code-block:: php-annotations
363+
364+
// src/AppBundle/Controller/DefaultController.php
365+
namespace AppBundle\Controller;
366+
367+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
368+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
369+
370+
class DefaultController extends Controller
371+
{
372+
/**
373+
*
374+
* @Route("/category/{name}", name="route1", options={"utf8": true})
375+
*
376+
*/
377+
public function categoryAction()
378+
{
379+
// ...
380+
}
381+
382+
.. code-block:: yaml
383+
384+
# app/config/routing.yml
385+
route1:
386+
path: /category/{name}
387+
defaults: { _controller: 'AppBundle:Default:category' }
388+
options:
389+
utf8: true
390+
391+
.. code-block:: xml
392+
393+
<!-- app/config/routing.xml -->
394+
<?xml version="1.0" encoding="UTF-8" ?>
395+
<routes xmlns="http://symfony.com/schema/routing"
396+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
397+
xsi:schemaLocation="http://symfony.com/schema/routing
398+
http://symfony.com/schema/routing/routing-1.0.xsd">
399+
400+
<route id="route1" path="/category/{name}">
401+
<default key="_controller">AppBundle:Default:category</default>
402+
<option key="utf8">true</option>
403+
</route>
404+
</routes>
405+
406+
.. code-block:: php
407+
408+
// app/config/routing.php
409+
use Symfony\Component\Routing\RouteCollection;
410+
use Symfony\Component\Routing\Route;
411+
412+
$collection = new RouteCollection();
413+
$collection->add('route1', new Route('/category/{name}',
414+
array(
415+
'_controller' => 'AppBundle:Default:category',
416+
),
417+
array(),
418+
array(
419+
'utf8' => true,
420+
)
421+
);
422+
423+
// ...
424+
425+
return $collection;
426+
427+
428+
In this route, the ``utf8`` option set to ``true`` makes Symfony consider the
429+
``.`` requirement to match any UTF-8 characters instead of just a single
430+
byte character. This means that so the following URLs would match:
431+
``/category/日本語``, ``/category/فارسی``, ``/category/한국어``, etc. In case you
432+
are wondering, this option also allows to include and match emojis in URLs.
433+
434+
You can also include UTF-8 strings as routing requirements:
435+
436+
.. configuration-block::
437+
438+
.. code-block:: php-annotations
439+
440+
// src/AppBundle/Controller/DefaultController.php
441+
namespace AppBundle\Controller;
442+
443+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
444+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
445+
446+
class DefaultController extends Controller
447+
{
448+
/**
449+
*
450+
* @Route(
451+
* "/category/{name}",
452+
* name="route2",
453+
* requirements={"default"="한국어"},
454+
* options={"utf8": true}
455+
* )
456+
*
457+
*/
458+
public function defaultAction()
459+
{
460+
// ...
461+
}
462+
463+
.. code-block:: yaml
464+
465+
# app/config/routing.yml
466+
route2:
467+
path: /default/{default}
468+
defaults: { _controller: 'AppBundle:Default:default' }
469+
requirements:
470+
default: "한국어"
471+
options:
472+
utf8: true
473+
474+
.. code-block:: xml
475+
476+
<!-- app/config/routing.xml -->
477+
<?xml version="1.0" encoding="UTF-8" ?>
478+
<routes xmlns="http://symfony.com/schema/routing"
479+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
480+
xsi:schemaLocation="http://symfony.com/schema/routing
481+
http://symfony.com/schema/routing/routing-1.0.xsd">
482+
483+
<route id="route2" path="/default/{default}">
484+
<default key="_controller">AppBundle:Default:default</default>
485+
<requirement key="default">한국어</requirement>
486+
<option key="utf8">true</option>
487+
</route>
488+
</routes>
489+
490+
.. code-block:: php
491+
492+
// app/config/routing.php
493+
use Symfony\Component\Routing\RouteCollection;
494+
use Symfony\Component\Routing\Route;
495+
496+
$collection = new RouteCollection();
497+
$collection->add('route2', new Route('/default/{default}',
498+
array(
499+
'_controller' => 'AppBundle:Default:default',
500+
),
501+
array(
502+
'default' => '한국어',
503+
),
504+
array(
505+
'utf8' => true,
506+
)
507+
);
508+
509+
// ...
510+
511+
return $collection;
512+
513+
.. tip::
514+
515+
In addition to UTF-8 characters, the Routing component also supports all
516+
the `PCRE Unicode properties`_, which are escape sequences that match
517+
generic character types. For example, ``\p{Lu}`` matches any uppercase
518+
character in any language, ``\p{Greek}`` matches any Greek character,
519+
``\P{Han}`` matches any character not included in the Chinese Han script.
520+
521+
.. note::
522+
523+
In Symfony 3.2 there is no need to set the ``utf8`` option explicitly. As
524+
soon as Symfony finds a UTF-8 character in the route path or requirements,
525+
it will turn the UTF-8 support automatically. However, this behaviour is
526+
deprecated and setting the option will be required in Symfony 4.0.
527+
349528
Learn more
350529
----------
351530

@@ -360,3 +539,4 @@ Learn more
360539
/configuration/apache_router
361540

362541
.. _Packagist: https://packagist.org/packages/symfony/routing
542+
.. _PCRE Unicode properties: http://php.net/manual/en/regexp.reference.unicode.php

components/yaml/yaml_format.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ YAML uses the ISO-8601 standard to express dates:
158158

159159
.. code-block:: yaml
160160
161-
2001-12-14t21:59:43.10-05:00
161+
2001-12-14T21:59:43.10-05:00
162162
163163
.. code-block:: yaml
164164

0 commit comments

Comments
 (0)