Permalink
Browse files

Initial import.

  • Loading branch information...
0 parents commit da12788822d44cd04737d5396f9c8b1279041f8d @johannes committed Oct 2, 2011
No changes.
@@ -0,0 +1,78 @@
+<?php
+
+namespace JS\MysqlndBundle\DataCollector;
+
+use Symfony\Component\HttpKernel\DataCollector\DataCollector;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+
+/**
+ * Data collector collecting mysqlnd statistics.
+ *
+ * @author johannes
+ */
+class MysqlndDataCollector extends DataCollector
+{
+ private $initialData = false;
+
+ public function __construct()
+ {
+ if (function_exists('mysqli_get_client_stats')) {
+ $this->initialData = mysqli_get_client_stats();
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function collect(Request $request, Response $response, \Exception $exception = null)
+ {
+ if (function_exists('mysqli_get_client_stats')) {
+ $this->data = $this->initialData;
+ array_walk($this->data, function (&$value, $key, $current_values) {
+ $value = $current_values[$key] - $value;
+ }, mysqli_get_client_stats());
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getName()
+ {
+ return 'mysqlnd';
+ }
+
+ /**
+ * Returns the collected data to be used by the view.
+ *
+ * @return array
+ */
+ public function getData()
+ {
+ return $this->data;
+ }
+
+ /**
+ * Dump information about mysqli.
+ *
+ * This is used by the view in case no statistics were collected to
+ * ease the debugging
+ *
+ * @return string
+ */
+ function getMysqlInfo()
@lsmith77

lsmith77 Oct 2, 2011

its part of the Symfony2 CS to include public

@johannes

johannes Oct 2, 2011

Owner

Since when do I care about CS :) But I'll fix it.

+ {
+ if (!extension_loaded("mysqli")) {
+ return "The mysqli extension is not available at all.";
+ }
+
+ ob_start();
+ $re = new \ReflectionExtension("mysqli");
+ $re->info();
+ $info = ob_get_contents();
+ ob_end_clean();
+
+ return str_replace('<h2><a name="module_mysqli">mysqli</a></h2>', '', $info);
+ }
+}
@@ -0,0 +1,29 @@
+<?php
+
+namespace JS\MysqlndBundle\DependencyInjection;
+
+use Symfony\Component\Config\Definition\Builder\TreeBuilder;
+use Symfony\Component\Config\Definition\ConfigurationInterface;
+
+/**
+ * This is the class that validates and merges configuration from your app/config files
+ *
+ * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
+ */
+class Configuration implements ConfigurationInterface
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function getConfigTreeBuilder()
+ {
+ $treeBuilder = new TreeBuilder();
+ $rootNode = $treeBuilder->root('js_mysqlnd');
+
+ // Here you should define the parameters that are allowed to
+ // configure your bundle. See the documentation linked above for
+ // more information on that topic.
+
+ return $treeBuilder;
+ }
+}
@@ -0,0 +1,28 @@
+<?php
+
+namespace JS\MysqlndBundle\DependencyInjection;
+
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\Config\FileLocator;
+use Symfony\Component\HttpKernel\DependencyInjection\Extension;
+use Symfony\Component\DependencyInjection\Loader;
+
+/**
+ * This is the class that loads and manages your bundle configuration
+ *
+ * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
+ */
+class JSMysqlndExtension extends Extension
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function load(array $configs, ContainerBuilder $container)
+ {
+ $configuration = new Configuration();
+ $config = $this->processConfiguration($configuration, $configs);
@lsmith77

lsmith77 Oct 2, 2011

since your package currently does not provide any app config options, you can remove the above 2 lines and the entire Configuration class

+
+ $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
+ $loader->load('services.xml');
+ }
+}
@@ -0,0 +1,9 @@
+<?php
+
+namespace JS\MysqlndBundle;
+
+use Symfony\Component\HttpKernel\Bundle\Bundle;
+
+class JSMysqlndBundle extends Bundle
+{
+}
@@ -0,0 +1,17 @@
+<?xml version="1.0" ?>
+
+<container xmlns="http://symfony.com/schema/dic/services"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
+
+ <parameters>
+ <parameter key="js_mysqlnd.data_collector.class">JS\MysqlndBundle\DataCollector\MysqlndDataCollector</parameter>
+ </parameters>
+
+ <services>
+ <service id="data_collector.mysqlnd" class="%js_mysqlnd.data_collector.class%" public="false">
+ <tag name="data_collector" template="JSMysqlndBundle:Collector:mysqlnd" id="mysqlnd" />
+ </service>
+ </services>
+
+</container>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,42 @@
+{% extends 'WebProfilerBundle:Profiler:layout.html.twig' %}
+
+{% block toolbar %}
+ {% if collector.data %}
+ {% set icon %}
+ <img width="20" height="28" alt="mysqlnd" style="border-width: 0; vertical-align: middle; margin-right: 5px;" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAcCAYAAABh2p9gAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sKAgoBDqegD/YAAAEVSURBVEjH7ZOxSgNBFEXvisVqFVJFsTFlqmh+QfyAFBZbpraztBQr8QMCmyJgJVuFwSK4Cgs2C5NCWAMhjGAxEYRRRAa7ayfRrMhuAmn2dG/gHd67vAEKCpaPM12IgeHteAjAxflBw8kjXJ0ualsunj9KaNZrqPQlh5NP7G64ONzPJwcA+DeKfCfDB0MAkMrSawvmFmpjGcR6RuB15pAe95KZZqUtjy7Df6UraY/N+jbuRj+nrG6uO3BL0MZmn9SPktQmY7h3ciWZecJXrAEAfmdZLjvXjy9v2TMUA8Mg1tw5vUjN0msLSpVx9VY3pHyy/Gt9ca94Fiku7IsFsWKrK1NPLBdeR3wf/8Lwo4RBrIiCgvn4Aogkh81eljaPAAAAAElFTkSuQmCC"/>
+ {% endset %}
+ {% set text %}
+ <span>{{ collector.data["bytes_received"] }}</span>
+ {% endset %}
+ {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %}
+ {% endif %}
+{% endblock %}
+
+
+{% block menu %}
+<span class="label">
+ <span class="icon"><img src="{{ asset('bundles/jsmysqlnd/images/mysqlnd.png') }}" alt="" /></span>
+ <strong>mysqlnd</strong>
+ {% if collector.data %}
+ <span class="count">
+ <span>{{ collector.data["bytes_received"] }}</span>
+ </span>
+ {% endif %}
+</span>
+{% endblock %}
+
+{% block panel %}
+ <h2>mysqlnd Statistics</h2>
+
+ {% if collector.data %}
+ <table>
+ {% for key, value in collector.data %}
+ <tr><td>{{ key }}</td><td>{{ value }}</td></tr>
+ {% endfor %}
+ </table>
+ {% else %}
+ <strong>No statistics collected for this request.</strong>
+ <p>For collecting data PHP requires the mysqli extension and must use mysqlnd as Client API Library.</p>
+ {{ collector.mysqlInfo|raw }}
+ {%endif %}
+{% endblock %}

4 comments on commit da12788

guess the Controller dir can be removed as well

Owner

johannes replied Oct 2, 2011

Removing that dir caused an error, that's why I've added that .keep file there. :-/

err .. what kind of error?

Owner

johannes replied Oct 3, 2011

Ah, due to me stupid :)
app/console added some stuff in my routing configuration when creating the bundle and I didn't kick that out :)

Please sign in to comment.