8000 Merge branch '2.8' into 3.2 · symfony/symfony-docs@89e5c4f · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 89e5c4f

Browse files
committed
Merge branch '2.8' into 3.2
* 2.8: [#7844] add XML and PHP config examples Property access fix remaining setDefinition() call mention old way to create PHPUnit mock objects Explain how to override the default templates directory Added a new article about linting translation files Removed any reference to X-Status-Code
2 parents a6c5de8 + fb417f5 commit 89e5c4f

File tree

9 files changed

+105
-19
lines changed

9 files changed

+105
-19
lines changed

components/property_access.rst

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,23 +252,31 @@ can use setters, the magic ``__set()`` method or properties to set values::
252252
$this->lastName = $name;
253253
}
254254

255+
public function getLastName()
256+
{
257+
return $this->lastName;
258+
}
259+
260+
public function getChildren()
261+
{
262+
return $this->children;
263+
}
264+
255265
public function __set($property, $value)
256266
{
257267
$this->$property = $value;
258268
}
259-
260-
// ...
261269
}
262270

263271
$person = new Person();
264272

265273
$accessor->setValue($person, 'firstName', 'Wouter');
266-
$accessor->setValue($person, 'lastName', 'de Jong');
267-
$accessor->setValue($person, 'children', array(new Person()));
274+
$accessor->setValue($person, 'lastName', 'de Jong'); // setLastName is called
275+
$accessor->setValue($person, 'children', array(new Person())); // __set is called
268276

269277
var_dump($person->firstName); // 'Wouter'
270278
var_dump($person->getLastName()); // 'de Jong'
271-
var_dump($person->children); // array(Person());
279+
var_dump($person->getChildren()); // array(Person());
272280

273281
You can also use ``__call()`` to set values but you need to enable the feature,
274282
see `Enable other Features`_.

configuration/override_dir_structure.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ directory structure is:
1313
your-project/
1414
├─ app/
1515
│ ├─ config/
16+
│ ├─ Resources/
17+
│ │ └─ views/
1618
│ └─ ...
1719
├─ bin/
1820
│ └─ ...
@@ -86,6 +88,50 @@ method::
8688

8789
Here you have changed the location of the directory to ``var/{environment}/logs``.
8890

91+
.. _override-templates-dir:
92+
93+
Override the Templates Directory
94+
--------------------------------
95+
96+
If your templates are not stored in the default ``app/Resources/views/``
97+
directory, use the :ref:`twig.paths <config-twig-paths>` configuration option to
98+
define your own templates directory (or directories):
99+
100+
.. configuration-block::
101+
102+
.. code-block:: yaml
103+
104+
# app/config/config.yml
105+
twig:
106+
# ...
107+
paths: ["%kernel.root_dir%/../templates"]
108+
109+
.. code-block:: xml
110+
111+
<!-- app/config/config.xml -->
112+
<?xml version="1.0" ?>
113+
<container xmlns="http://symfony.com/schema/dic/services"
114+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
115+
xmlns:twig="http://symfony.com/schema/dic/twig"
116+
xsi:schemaLocation="http://symfony.com/schema/dic/services
117+
http://symfony.com/schema/dic/services/services-1.0.xsd
118+
http://symfony.com/schema/dic/twig
119+
http://symfony.com/schema/dic/twig/twig-1.0.xsd">
120+
121+
<twig:config>
122+
<twig:path>%kernel.root_dir%/../templates</twig:path>
123+
</twig:config>
124+
</container>
125+
126+
.. code-block:: php
127+
128+
// app/config/config.php
129+
$container->loadFromExtension('twig', array(
130+
'paths' => array(
131+
'%kernel.root_dir%/../templates',
132+
),
133+
));
134+
89135
.. _override-web-dir:
90136

91137
Override the ``web`` Directory

create_framework/unit_testing.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ We are now ready to write our first test::
9797
private function getFrameworkForException($exception)
9898
{
9999
$matcher = $this->createMock(Routing\Matcher\UrlMatcherInterface::class);
100+
// use getMock() on PHPUnit 5.3 or below
101+
// $matcher = $this->getMock(Routing\Matcher\UrlMatcherInterface::class);
102+
100103
$matcher
101104
->expects($this->once())
102105
->method('match')
@@ -155,6 +158,9 @@ Response::
155158
public function testControllerResponse()
156159
{
157160
$matcher = $this->createMock(Routing\Matcher\UrlMatcherInterface::class);
161+
// use getMock() on PHPUnit 5.3 or below
162+
// $matcher = $this->getMock(Routing\Matcher\UrlMatcherInterface::class);
163+
158164
$matcher
159165
->expects($this->once())
160166
->method('match')

form/unit_testing.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ allows you to return a list of extensions to register::
184184
protected function getExtensions()
185185
{
186186
$this->validator = $this->createMock(ValidatorInterface::class);
187+
// use getMock() on PHPUnit 5.3 or below
188+
// $this->validator = $this->getMock(ValidatorInterface::class);
187189
$this->validator
188190
->method('validate')
189191
->will($this->returnValue(new ConstraintViolationList()));

reference/configuration/twig.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ on. Set it to ``0`` to disable all the optimizations. You can even enable or
248248
disable these optimizations selectively, as explained in the Twig documentation
249249
about `the optimizer extension`_.
250250

251+
.. _config-twig-paths:
252+
251253
paths
252254
~~~~~
253255

reference/events.rst

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -242,19 +242,8 @@ and set a new ``Exception`` object, or do nothing::
242242

243243
.. note::
244244

245-
If you want to overwrite the status code (which you should do not without a good
246-
reason), set the ``X-Status-Code`` header::
247-
248-
$response = new Response(
249-
'Error',
250-
404, // this status code will be ignored
251-
array(
252-
'X-Status-Code' => 200 // this status code will actually be sent to the client
253-
)
254-
);
255-
256-
If you do **not** set the ``X-Status-Code`` header, then Symfony uses the following
257-
logic to determine the status code:
245+
Symfony uses the following logic to determine the HTTP status code of the
246+
response:
258247

259248
* If :method:`Symfony\\Component\\HttpFoundation\\Response::isClientError`,
260249
:method:`Symfony\\Component\\HttpFoundation\\Response::isServerError` or

security/custom_authentication_provider.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ to service ids that do not exist yet: ``wsse.security.authentication.provider``
460460
))
461461
->setPublic(false);
462462
463-
$container->setDefinition('wsse.security.authentication.listener', WsseListener::class)
463+
$container->register('wsse.security.authentication.listener', WsseListener::class)
464464
->setArguments(array(
465465
new Reference('security.token_storage'),
466466
new Reference('security.authentication.manager'),

testing/database.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ it's easy to pass a mock object within a test::
7575
{
7676
// First, mock the object to be used in the test
7777
$employee = $this->createMock(Employee::class);
78+
// use getMock() on PHPUnit 5.3 or below
79+
// $employee = $this->getMock(Employee::class);
7880
$employee->expects($this->once())
7981
->method('getSalary')
8082
->will($this->returnValue(1000));

translation/lint.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.. index::
2+
single: Translation; Lint
3+
single: Translation; Translation File Errors
4+
5+
How to Find Errors in Translation Files
6+
=======================================
7+
8+
Symfony processes all the application translation files as part of the process
9+
that compiles the application code before executing it. If there's an error in
10+
any translation file, you'll see an error message explaining the problem.
11+
12+
If you prefer, you can also validate the contents of any YAML translation file
13+
using the ``lint:yaml`` command:
14+
15+
.. code-block:: terminal
16+
17+
# lint a single file
18+
$ ./bin/console lint:yaml app/Resources/translations/messages.en.yml
19+
20+
# lint a whole directory
21+
$ ./bin/console lint:yaml app/Resources/translations
22+
23+
# lint a specific bundle
24+
$ ./bin/console lint:yaml @AppBundle
25+
26+
The linter results can be exported to JSON using the ``--format`` option:
27+
28+
.. code-block:: terminal
29+
30+
# lint a single file
31+
$ ./bin/console lint:yaml app/Resources/translations --format=json

0 commit comments

Comments
 (0)
0