Skip to content

Commit 48e8872

Browse files
committed
Merge branch '4.1'
* 4.1: Fix and improve JSON login docs [Configuration] Change the configuration to match framework.yaml/php [Serializer] Updated the list of loaded encoders [VarDumper] Enhance the ServerDumper documentation
2 parents fbe9b73 + 1019797 commit 48e8872

File tree

5 files changed

+142
-28
lines changed

5 files changed

+142
-28
lines changed

components/var_dumper.rst

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ current PHP SAPI:
100100
.. versionadded:: 4.1
101101
The ``dd()`` helper method was introduced in Symfony 4.1.
102102

103+
.. _var-dumper-dump-server:
104+
103105
The Dump Server
104106
---------------
105107

@@ -126,22 +128,71 @@ server, which outputs it to its own console or to an HTML file:
126128
127129
Inside a Symfony application, the output of the dump server is configured with
128130
the :ref:`dump_destination option <configuration-debug-dump_destination>` of the
129-
``debug`` package.
131+
``debug`` package:
132+
133+
.. configuration-block::
134+
135+
.. code-block:: yaml
136+
137+
# config/packages/debug.yaml
138+
debug:
139+
dump_destination: "tcp://%env(VAR_DUMPER_SERVER)%"
140+
141+
.. code-block:: xml
142+
143+
<!-- config/packages/debug.xml -->
144+
<?xml version="1.0" encoding="UTF-8" ?>
145+
<container xmlns="http://symfony.com/schema/dic/debug"
146+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
147+
xmlns:debug="http://symfony.com/schema/dic/debug"
148+
xsi:schemaLocation="http://symfony.com/schema/dic/services
149+
http://symfony.com/schema/dic/services/services-1.0.xsd
150+
http://symfony.com/schema/dic/debug http://symfony.com/schema/dic/debug/debug-1.0.xsd">
151+
152+
<debug:config dump-destination="tcp://%env(VAR_DUMPER_SERVER)%" />
153+
</container>
154+
155+
.. code-block:: php
156+
157+
// config/packages/debug.php
158+
$container->loadFromExtension('debug', array(
159+
'dump_destination' => 'tcp://%env(VAR_DUMPER_SERVER)%',
160+
));
130161
131-
Outside a Symfony application, use the ``ServerDumper`` class::
162+
Outside a Symfony application, use the :class:`Symfony\\Component\\VarDumper\\Dumper\\ServerDumper` class::
132163

133164
require __DIR__.'/vendor/autoload.php';
134165

135166
use Symfony\Component\VarDumper\VarDumper;
136167
use Symfony\Component\VarDumper\Cloner\VarCloner;
137168
use Symfony\Component\VarDumper\Dumper\ServerDumper;
138169

139-
VarDumper::setHandler(function ($var) {
140-
$cloner = new VarCloner();
141-
$dumper = new ServerDumper('tcp://127.0.0.1:9912');
142-
$dumper->dump($cloner->cloneVar($var));
170+
$cloner = new VarCloner();
171+
$fallbackDumper = \in_array(\PHP_SAPI, array('cli', 'phpdbg')) ? new CliDumper() : new HtmlDumper();
172+
$dumper = new ServerDumper('tcp://127.0.0.1:9912', $fallbackDumper, [
173+
'cli' => new CliContextProvider(),
174+
'source' => new SourceContextProvider(),
175+
]);
176+
177+
VarDumper::setHandler(function ($var) use ($cloner, $dumper) {
178+
$dumper->dump($cloner->cloneVar($var));
143179
});
144180

181+
.. note::
182+
183+
The second argument of :class:`Symfony\\Component\\VarDumper\\Dumper\\ServerDumper`
184+
is a :class:`Symfony\\Component\\VarDumper\\Dumper\\DataDumperInterface` instance
185+
used as a fallback when the server is unreachable. The third argument are the
186+
context providers, which allow to gather some info about the context in which the
187+
data was dumped. The built-in contexts providers are: ``cli``, ``request`` and ``source``.
188+
189+
Then you can use the following command to start a server out-of-the-box:
190+
191+
.. code-block:: terminal
192+
193+
$ ./vendor/bin/var-dump-server
194+
[OK] Server listening on tcp://127.0.0.1:9912
195+
145196
DebugBundle and Twig Integration
146197
--------------------------------
147198

configuration.rst

Lines changed: 70 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,34 @@ instance, the framework bundle is configured in ``config/packages/framework.yaml
2323
framework:
2424
secret: '%env(APP_SECRET)%'
2525
#default_locale: en
26-
#csrf_protection: ~
26+
#csrf_protection: true
2727
#http_method_override: true
28-
#trusted_hosts: ~
29-
# https://symfony.com/doc/current/reference/configuration/framework.html#handler-id
30-
#session:
31-
# # The native PHP session handler will be used
32-
# handler_id: ~
33-
#esi: ~
34-
#fragments: ~
28+
29+
# Enables session support. Note that the session will ONLY be started if you read or write from it.
30+
# Remove or comment this section to explicitly disable session support.
31+
session:
32+
handler_id: ~
33+
34+
#esi: true
35+
#fragments: true
3536
php_errors:
3637
log: true
3738
39+
cache:
40+
# Put the unique name of your app here: the prefix seed
41+
# is used to compute stable namespaces for cache keys.
42+
#prefix_seed: your_vendor_name/app_name
43+
44+
# The app cache caches to the filesystem by default.
45+
# Other options include:
46+
47+
# Redis
48+
#app: cache.adapter.redis
49+
#default_redis_provider: redis://localhost
50+
51+
# APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
52+
#app: cache.adapter.apcu
53+
3854
.. code-block:: xml
3955
4056
<!-- config/packages/framework.xml -->
@@ -46,6 +62,30 @@ instance, the framework bundle is configured in ``config/packages/framework.yaml
4662
http://symfony.com/schema/dic/framework http://symfony.com/schema/dic/framework/framework-1.0.xsd"
4763
>
4864
<framework:config secret="%env(APP_SECRET)%">
65+
<!--<framework:csrf-protection enabled="true“ />-->
66+
<!--<framework:esi enabled="true" />-->
67+
<!--<framework:fragments enabled="true" />-->
68+
69+
<!-- Enables session support. Note that the session will ONLY be started if you read or write from it.
70+
Remove or comment this section to explicitly disable session support. -->
71+
<framework:session />
72+
73+
<!-- Put the unique name of your app here: the prefix seed
74+
is used to compute stable namespaces for cache keys.
75+
<framework:cache prefix-seed="your_vendor_name/app_name">
76+
-->
77+
<framework:cache>
78+
<!-- The app cache caches to the filesystem by default.
79+
Other options include: -->
80+
81+
<!-- Redis -->
82+
<!--<framework:app>cache.adapter.redis</framework:app>-->
83+
<!--<framework:default-redis-provider>redis://localhost</framework:default-redis-provider>-->
84+
85+
<!-- APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues) -->
86+
<!--<framework:app>cache.adapter.apcu</framework:app>-->
87+
</framework:cache>
88+
4989
<framework:php-errors log="true" />
5090
</framework:config>
5191
</container>
@@ -56,19 +96,32 @@ instance, the framework bundle is configured in ``config/packages/framework.yaml
5696
$container->loadFromExtension('framework', [
5797
'secret' => '%env(APP_SECRET)%',
5898
//'default_locale' => 'en',
59-
//'csrf_protection' => null,
99+
//'csrf_protection' => true,
60100
//'http_method_override' => true,
61-
//'trusted_hosts' => null,
62-
// https://symfony.com/doc/current/reference/configuration/framework.html#handler-id
63-
//'session' => [
64-
// // The native PHP session handler will be used
65-
// 'handler_id' => null,
66-
//],
67-
//'esi' => null,
68-
//'fragments' => null,
101+
102+
// Enables session support. Note that the session will ONLY be started if you read or write from it.
103+
// Remove or comment this section to explicitly disable session support.
104+
'session' => [
105+
'handler_id' => null,
106+
],
107+
//'esi' => true,
108+
//'fragments' => true,
69109
'php_errors' => [
70110
'log' => true,
71111
],
112+
'cache' => [
113+
//'prefix_seed' => 'your_vendor_name/app_name',
114+
115+
// The app cache caches to the filesystem by default.
116+
// Other options include:
117+
118+
// Redis
119+
//'app' => 'cache.adapter.redis',
120+
//'default_redis_provider: 'redis://localhost',
121+
122+
// APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
123+
//'app' => 'cache.adapter.apcu',
124+
],
72125
]);
73126
74127
The top-level key (here ``framework``) references configuration for a specific

reference/configuration/debug.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,5 @@ destination for dumps. Typically, you would set this to ``php://stderr``:
9999
$container->loadFromExtension('debug', array(
100100
'dump_destination' => 'php://stderr',
101101
));
102+
103+
Configure it to ``"tcp://%env(VAR_DUMPER_SERVER)%"`` in order to use the :ref:`ServerDumper feature <var-dumper-dump-server>`.

security/json_login_setup.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ path:
8080
*/
8181
public function login(Request $request)
8282
{
83+
$user = $this->getUser();
84+
85+
return $this->json(array(
86+
'username' => $user->getUsername(),
87+
'roles' => $user->getRoles(),
88+
));
8389
}
8490
}
8591
@@ -117,11 +123,11 @@ path:
117123
118124
return $routes;
119125
120-
Don't let this empty controller confuse you. When you submit a ``POST`` request
121-
to the ``/login`` URL with the following JSON document as the body, the security
122-
system intercepts the requests. It takes care of authenticating the user with
123-
the submitted username and password or triggers an error in case the authentication
124-
process fails:
126+
When you submit a ``POST`` request to the ``/login`` URL with the following JSON
127+
document as the body, the security system intercepts the requests.
128+
It takes care of authenticating the user with the submitted username and password
129+
or triggers an error in case the authentication process fails.
130+
If the authentication is successful, the controller defined earlier will be executed.
125131

126132
.. code-block:: json
127133

serializer.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ Encoders supporting the following formats are enabled:
5252

5353
* JSON: :class:`Symfony\\Component\\Serializer\\Encoder\\JsonEncoder`
5454
* XML: :class:`Symfony\\Component\\Serializer\\Encoder\\XmlEncoder`
55+
* CSV: :class:`Symfony\\Component\\Serializer\\Encoder\\CsvEncoder`
56+
* YAML: :class:`Symfony\\Component\\Serializer\\Encoder\\YamlEncoder`
5557

5658
As well as the following normalizers:
5759

0 commit comments

Comments
 (0)