Skip to content

Commit fb417f5

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [#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 391799d + 78b3c10 commit fb417f5

File tree

9 files changed

+105
-19
lines changed

9 files changed

+105
-19
lines changed

components/property_access.rst

+13-5
Original file line numberDiff line numberDiff line change
@@ -259,23 +259,31 @@ can use setters, the magic ``__set()`` method or properties to set values::
259259
$this->lastName = $name;
260260
}
261261

262+
public function getLastName()
263+
{
264+
return $this->lastName;
265+
}
266+
267+
public function getChildren()
268+
{
269+
return $this->children;
270+
}
271+
262272
public function __set($property, $value)
263273
{
264274
$this->$property = $value;
265275
}
266-
267-
// ...
268276
}
269277

270278
$person = new Person();
271279

272280
$accessor->setValue($person, 'firstName', 'Wouter');
273-
$accessor->setValue($person, 'lastName', 'de Jong');
274-
$accessor->setValue($person, 'children', array(new Person()));
281+
$accessor->setValue($person, 'lastName', 'de Jong'); // setLastName is called
282+
$accessor->setValue($person, 'children', array(new Person())); // __set is called
275283

276284
var_dump($person->firstName); // 'Wouter'
277285
var_dump($person->getLastName()); // 'de Jong'
278-
var_dump($person->children); // array(Person());
286+
var_dump($person->getChildren()); // array(Person());
279287

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

configuration/override_dir_structure.rst

+46
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ directory structure is:
1515
│ ├─ cache/
1616
│ ├─ config/
1717
│ ├─ logs/
18+
│ ├─ Resources/
19+
│ │ └─ views/
1820
│ └─ ...
1921
├─ src/
2022
│ └─ ...
@@ -80,6 +82,50 @@ method::
8082

8183
Here you have changed the location of the directory to ``app/{environment}/logs``.
8284

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

85131
Override the ``web`` Directory

create_framework/unit_testing.rst

+6
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ We are now ready to write our first test::
9393
private function getFrameworkForException($exception)
9494
{
9595
$matcher = $this->createMock(Routing\Matcher\UrlMatcherInterface::class);
96+
// use getMock() on PHPUnit 5.3 or below
97+
// $matcher = $this->getMock(Routing\Matcher\UrlMatcherInterface::class);
98+
9699
$matcher
97100
->expects($this->once())
98101
->method('match')
@@ -149,6 +152,9 @@ Response::
149152
public function testControllerResponse()
150153
{
151154
$matcher = $this->createMock(Routing\Matcher\UrlMatcherInterface::class);
155+
// use getMock() on PHPUnit 5.3 or below
156+
// $matcher = $this->getMock(Routing\Matcher\UrlMatcherInterface::class);
157+
152158
$matcher
153159
->expects($this->once())
154160
->method('match')

form/unit_testing.rst

+2
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ allows you to return a list of extensions to register::
189189
protected function getExtensions()
190190
{
191191
$this->validator = $this->createMock(ValidatorInterface::class);
192+
// use getMock() on PHPUnit 5.3 or below
193+
// $this->validator = $this->getMock(ValidatorInterface::class);
192194
$this->validator
193195
->method('validate')
194196
->will($this->returnValue(new ConstraintViolationList()));

reference/configuration/twig.rst

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

252+
.. _config-twig-paths:
253+
252254
paths
253255
~~~~~
254256

reference/events.rst

+2-13
Original file line numberDiff line numberDiff line change
@@ -241,19 +241,8 @@ and set a new ``Exception`` object, or do nothing::
241241

242242
.. note::
243243

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

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

security/custom_authentication_provider.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ to service ids that do not exist yet: ``wsse.security.authentication.provider``
465465
))
466466
->setPublic(false);
467467
468-
$container->setDefinition('wsse.security.authentication.listener', WsseListener::class)
468+
$container->register('wsse.security.authentication.listener', WsseListener::class)
469469
->setArguments(array(
470470
new Reference('security.token_storage'),
471471
new Reference('security.authentication.manager'),

testing/database.rst

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ it's easy to pass a mock object within a test::
7171
{
7272
// First, mock the object to be used in the test
7373
$employee = $this->createMock(Employee::class);
74+
// use getMock() on PHPUnit 5.3 or below
75+
// $employee = $this->getMock(Employee::class);
7476
$employee->expects($this->once())
7577
->method('getSalary')
7678
->will($this->returnValue(1000));

translation/lint.rst

+31
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)