Skip to content

Documented the reset() method of data collectors #8882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions profiler/data_collector.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,43 @@ Creating a custom data collector is as simple as implementing the
interface DataCollectorInterface
{
function collect(Request $request, Response $response, \Exception $exception = null);
public function reset();
function getName();
}

The
:method:`Symfony\\Component\\HttpKernel\\DataCollector\\DataCollectorInterface::getName`
method returns the name of the data collector and must be unique in the
application. This value is also used to access the information later on (see
:doc:`/testing/profiling` for instance).
The :method:`Symfony\\Component\\HttpKernel\\DataCollector\\DataCollectorInterface::getName`
method returns the collector identifier, which must be unique in the
application. You can choose any arbitrary name, but it's recommended to return
a string which is short, lowercased and without white spaces, because this value
is used later to access the collector information (see :doc:`/testing/profiling`
for instance).

The :method:`Symfony\\Component\\HttpKernel\\DataCollector\\DataCollectorInterface::reset`
method is called between requests to reset the state of the profiler. Use it to
remove all the information collected with the ``collect()`` method::

// src/DataCollector/RequestCollector.php
namespace App\DataCollector;

use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class RequestCollector extends DataCollector
{
public function collect(Request $request, Response $response, \Exception $exception = null)
{
// this method saves some information in $this->data
// ...
}

public function reset()
{
// if the data collector is more complex, here you can call other
// services to reset their states or data
$this->data = array();
}
}

The
:method:`Symfony\\Component\\HttpKernel\\DataCollector\\DataCollectorInterface::collect`
Expand Down