Skip to content

Commit 55a4254

Browse files
committed
feature #8882 Documented the reset() method of data collectors (javiereguiluz)
This PR was merged into the 4.0 branch. Discussion ---------- Documented the reset() method of data collectors This fixes #8862. Commits ------- 0bfa226 Documented the reset() method of data collectors
2 parents 6aabf2f + 0bfa226 commit 55a4254

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

profiler/data_collector.rst

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,43 @@ Creating a custom data collector is as simple as implementing the
1717
interface DataCollectorInterface
1818
{
1919
function collect(Request $request, Response $response, \Exception $exception = null);
20+
public function reset();
2021
function getName();
2122
}
2223

23-
The
24-
:method:`Symfony\\Component\\HttpKernel\\DataCollector\\DataCollectorInterface::getName`
25-
method returns the name of the data collector and must be unique in the
26-
application. This value is also used to access the information later on (see
27-
:doc:`/testing/profiling` for instance).
24+
The :method:`Symfony\\Component\\HttpKernel\\DataCollector\\DataCollectorInterface::getName`
25+
method returns the collector identifier, which must be unique in the
26+
application. You can choose any arbitrary name, but it's recommended to return
27+
a string which is short, lowercased and without white spaces, because this value
28+
is used later to access the collector information (see :doc:`/testing/profiling`
29+
for instance).
30+
31+
The :method:`Symfony\\Component\\HttpKernel\\DataCollector\\DataCollectorInterface::reset`
32+
method is called between requests to reset the state of the profiler. Use it to
33+
remove all the information collected with the ``collect()`` method::
34+
35+
// src/DataCollector/RequestCollector.php
36+
namespace App\DataCollector;
37+
38+
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
39+
use Symfony\Component\HttpFoundation\Request;
40+
use Symfony\Component\HttpFoundation\Response;
41+
42+
class RequestCollector extends DataCollector
43+
{
44+
public function collect(Request $request, Response $response, \Exception $exception = null)
45+
{
46+
// this method saves some information in $this->data
47+
// ...
48+
}
49+
50+
public function reset()
51+
{
52+
// if the data collector is more complex, here you can call other
53+
// services to reset their states or data
54+
$this->data = array();
55+
}
56+
}
2857

2958
The
3059
:method:`Symfony\\Component\\HttpKernel\\DataCollector\\DataCollectorInterface::collect`

0 commit comments

Comments
 (0)