1
0
mirror of https://github.com/maximebf/php-debugbar.git synced 2025-06-23 03:04:39 +02:00
Files
php-debugbar/docs/data-collectors.html
Barry vd. Heuvel d07c5fc73a Add canonical
2025-02-13 20:23:44 +01:00

445 lines
12 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>PHP Debug Bar</title>
<link rel="canonical" href="https://php-debugbar.com/docs/data-collectors/" />
<link type="text/css" rel="stylesheet" href="/docs/assets/css/reset.css">
<link type="text/css" rel="stylesheet" href="http://yandex.st/highlightjs/6.1/styles/sunburst.min.css">
<link type="text/css" rel="stylesheet" href="/docs/assets/css/docs.css">
<link type="text/css" rel="stylesheet" href="/docs/assets/css/print.css" media="print">
<link type="text/css" rel="stylesheet" href="style.css">
<script type="text/javascript" src="/docs/assets/js/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="http://yandex.st/highlightjs/6.1/highlight.min.js"></script>
<script type="text/javascript" src="/docs/assets/js/lunr.min.js"></script>
<script type="text/javascript">var BASE_URL = "/docs/";</script>
<script type="text/javascript" src="/docs/assets/js/viewer.js"></script>
</head>
<body>
<div id="page">
<a name="top" />
<header id="header">
<h1><a href="/docs/">PHP Debug Bar</a></h1>
</header>
<div id="sidebar">
<form action="/docs/search.html"><input id="search" type="text" placeholder="Search" name="q" /></form>
<nav id="toc">
<ol>
<li>
<a href="/docs/readme.html#php-debug-bar">PHP Debug Bar</a>
<ol>
<li>
<a href="/docs/readme.html#installation">Installation</a>
</li>
<li>
<a href="/docs/readme.html#quick-start">Quick start</a>
</li>
</ol>
</li>
<li>
<a href="/docs/data-collectors.html#collecting-data">Collecting Data</a>
<ol>
<li>
<a href="/docs/data-collectors.html#using-collectors">Using collectors</a>
</li>
<li>
<a href="/docs/data-collectors.html#creating-collectors">Creating collectors</a>
</li>
</ol>
</li>
<li>
<a href="/docs/rendering.html#rendering">Rendering</a>
<ol>
<li>
<a href="/docs/rendering.html#assets">Assets</a>
</li>
<li>
<a href="/docs/rendering.html#managing-jquery-conflicts">Managing jQuery conflicts</a>
</li>
<li>
<a href="/docs/rendering.html#the-javascript-object">The javascript object</a>
</li>
</ol>
</li>
<li>
<a href="/docs/ajax-and-stack.html#ajax-and-stacked-data">AJAX and Stacked data</a>
<ol>
<li>
<a href="/docs/ajax-and-stack.html#ajax">AJAX</a>
</li>
<li>
<a href="/docs/ajax-and-stack.html#stacked-data">Stacked data</a>
</li>
</ol>
</li>
<li>
<a href="/docs/base-collectors.html#base-collectors">Base collectors</a>
<ol>
<li>
<a href="/docs/base-collectors.html#messages">Messages</a>
</li>
<li>
<a href="/docs/base-collectors.html#timedata">TimeData</a>
</li>
<li>
<a href="/docs/base-collectors.html#exceptions">Exceptions</a>
</li>
<li>
<a href="/docs/base-collectors.html#pdo">PDO</a>
</li>
<li>
<a href="/docs/base-collectors.html#requestdata">RequestData</a>
</li>
<li>
<a href="/docs/base-collectors.html#config">Config</a>
</li>
<li>
<a href="/docs/base-collectors.html#aggregatedcollector">AggregatedCollector</a>
</li>
<li>
<a href="/docs/base-collectors.html#others">Others</a>
</li>
</ol>
</li>
<li>
<a href="/docs/bridge-collectors.html#bridge-collectors">Bridge collectors</a>
<ol>
<li>
<a href="/docs/bridge-collectors.html#cachecache">CacheCache</a>
</li>
<li>
<a href="/docs/bridge-collectors.html#doctrine">Doctrine</a>
</li>
<li>
<a href="/docs/bridge-collectors.html#monolog">Monolog</a>
</li>
<li>
<a href="/docs/bridge-collectors.html#propel">Propel</a>
</li>
<li>
<a href="/docs/bridge-collectors.html#slim">Slim</a>
</li>
<li>
<a href="/docs/bridge-collectors.html#swift-mailer">Swift Mailer</a>
</li>
<li>
<a href="/docs/bridge-collectors.html#twig">Twig</a>
</li>
</ol>
</li>
<li>
<a href="/docs/data-formatter.html#data-formatter">Data Formatter</a>
<ol>
</ol>
</li>
<li>
<a href="/docs/storage.html#storage">Storage</a>
<ol>
<li>
<a href="/docs/storage.html#available-storage">Available storage</a>
</li>
<li>
<a href="/docs/storage.html#creating-your-own-storage">Creating your own storage</a>
</li>
<li>
<a href="/docs/storage.html#request-id-generator">Request ID generator</a>
</li>
</ol>
</li>
<li>
<a href="/docs/openhandler.html#open-handler">Open handler</a>
<ol>
</ol>
</li>
<li>
<a href="/docs/http-drivers.html#http-drivers">HTTP drivers</a>
<ol>
</ol>
</li>
<li>
<a href="/docs/javascript-bar.html#javascript-bar">Javascript Bar</a>
<ol>
<li>
<a href="/docs/javascript-bar.html#tabs-and-indicators">Tabs and indicators</a>
</li>
<li>
<a href="/docs/javascript-bar.html#data-mapping">Data mapping</a>
</li>
<li>
<a href="/docs/javascript-bar.html#datasets">Datasets</a>
</li>
<li>
<a href="/docs/javascript-bar.html#widgets">Widgets</a>
</li>
<li>
<a href="/docs/javascript-bar.html#custom-tabs-and-indicators">Custom tabs and indicators</a>
</li>
<li>
<a href="/docs/javascript-bar.html#openhandler">OpenHandler</a>
</li>
</ol>
</li>
</ol>
</nav>
<nav id="links">
<ul>
</ul>
</nav>
</div>
<div id="content">
<a name="collecting-data"></a><h1>Collecting Data</h1>
<a name="using-collectors"></a><h2>Using collectors</h2>
<p>Collectors can be added to your debug bar using <code>addCollector()</code>.</p>
<pre><code>$debugbar = new DebugBar();
$debugbar-&gt;addCollector(new DataCollector\RequestDataCollector());</code></pre>
<p>Each collector as a unique name as defined by its <code>getName()</code> method. You can
access collectors using <code>getCollector($name)</code>.</p>
<pre><code>$debugbar-&gt;addCollector(new DataCollector\MessagesCollector());
$debugbar-&gt;getCollector(&#39;messages&#39;)-&gt;addMessage(&quot;foobar&quot;);
// or:
$debugbar[&#39;messages&#39;]-&gt;addMessage(&quot;foobar&quot;);</code></pre>
<p>Data will be collected from them when the debug bar is rendered. You can however
collect the data earlier using <code>collect()</code>.</p>
<pre><code>$debugbar-&gt;collect();</code></pre>
<a name="creating-collectors"></a><h2>Creating collectors</h2>
<p>Collectors must implement the <code>DebugBar\DataCollector\DataCollectorInterface</code>. They
may subclass <code>DebugBar\DataCollector\DataCollector</code> which provides utility methods.</p>
<p>Collectors must provide a <code>getName()</code> function returning their unique name and a
<code>collect()</code> function returning some json-encodable data. The latter will be called at the
same time the <code>DebugBar::collect()</code> method is called.</p>
<pre><code>class MyDataCollector extends DebugBar\DataCollector\DataCollector
{
public function collect()
{
return array(&quot;uniqid&quot; =&gt; uniqid());
}
public function getName()
{
return &#39;mycollector&#39;;
}
}
$debugbar-&gt;addCollector(new MyDataCollector());</code></pre>
<p>This however won&#39;t show anything in the debug bar as no information are provided
on how to display these data. You could do that manually as you&#39;ll see in later chapter
or implement the <code>DebugBar\DataSource\Renderable</code> interface.</p>
<p>To implement it, you must define a <code>getWidgets()</code> function which returns an array
of key/value pairs where key are control names and values control options as defined
in <code>JavascriptRenderer::addControl($name, $options)</code> (see Rendering chapter).</p>
<pre><code>class MyDataCollector extends DebugBar\DataCollector\DataCollector implements DebugBar\DataCollector\Renderable
{
// ...
public function getWidgets()
{
return array(
&quot;mycollector&quot; =&gt; array(
&quot;icon&quot; =&gt; &quot;cogs&quot;,
&quot;tooltip&quot; =&gt; &quot;uniqid()&quot;,
&quot;map&quot; =&gt; &quot;uniqid&quot;,
&quot;default&quot; =&gt; &quot;&#39;&#39;&quot;
)
);
}
}</code></pre>
<p>This will have the result of adding a new indicator to the debug bar.</p>
<p>When implementing the Renderable interface, you may use widgets which are not provided
with the default install. You can add new assets by implementing the <code>DebugBar\DataCollector\AssetProvider</code> interface.</p>
<p>to implement it, you must define the <code>getAssets()</code> method. It must return an array with the
following keys:</p>
<ul>
<li>base_path: base path of assets (optional, if omitted or null, will use the base path of the JavascriptRenderer)</li>
<li>base_url: base url of assets (optional, same as base_path)</li>
<li>css: an array of css filenames</li>
<li>js: an array of javascript filenames</li>
</ul>
<p>Example:</p>
<pre><code>class MyDbCollector extends DebugBar\DataCollector\DataCollector implements DebugBar\DataCollector\Renderable, DebugBar\DataCollector\AssetProvider
{
// ...
public function getWidgets()
{
return array(
&quot;database&quot; =&gt; array(
&quot;icon&quot; =&gt; &quot;inbox&quot;,
&quot;widget&quot; =&gt; &quot;PhpDebugBar.Widgets.SQLQueriesWidget&quot;,
&quot;map&quot; =&gt; &quot;pdo&quot;,
&quot;default&quot; =&gt; &quot;[]&quot;
)
);
}
public function getAssets()
{
return array(
&#39;css&#39; =&gt; &#39;widgets/sqlqueries/widget.css&#39;,
&#39;js&#39; =&gt; &#39;widgets/sqlqueries/widget.js&#39;
);
}
}</code></pre>
</div>
<footer id="footer">
Powered by <a href="http://github.com/maximebf/beautiful-docs">beautiful-docs</a> -
<a href="#top">Back to top</a> - <a href="/docs/all.html">Everything on a single page</a>
- <a href="?print=1">Print current page</a> - <a href="/docs/all.html?print=1">Print all pages</a>
</footer>
</div>
</body>
</html>