PHP code example of yproximite / influxdb-preset-bundle

1. Go to this page and download the library: Download yproximite/influxdb-preset-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yproximite / influxdb-preset-bundle example snippets


// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Yproximite\Bundle\InfluxDbPresetBundle\YproximiteInfluxDbPresetBundle(),
        new Yproximite\InfluxDbBundle\InfluxDbBundle(),
    );
}

use Yproximite\Bundle\InfluxDbPresetBundle\Event\InfluxDbEvent;

// Symfony\Component\EventDispatcher\EventDispatcherInterface
$eventDispatcher = $this->get('event_dispatcher');

// Preset from default profile
$eventDispatcher->dispatch('app.user.created', new InfluxDbEvent(1));

// Advanced event parameters
$event = new InfluxDbEvent(
    $value = 1, // will be converted to float
    string $profileName = 'other',
    ?\DateTimeInterface $dateTime = new \DateTime()
);

$eventDispatcher->dispatch('app.order.requested', $event);

// Yproximite\Bundle\InfluxDbPresetBundle\Client\ClientInterface
$client = $this->get('yproximite.influx_db_preset.client.client');

$client->sendPoint(
    string $profileName = 'other',
    string $presetName = 'app.user.created',
    float $value = 0.5,
    ?\DateTimeInterface $dateTime = new \DateTime()
);

use Yproximite\Bundle\InfluxDbPresetBundle\Event\ClientRequestEvent;

final class MyAppListener
{
    public function onClientRequest(ClientRequestEvent $event)
    {
        dump(
            $event->getProfileName(),
            $event->getPresetName(),
            $event->getValue(),
            $event->getDateTime()
        );
    }
}