luna/vnstat

PHP wrapper for the command line app 'vnstat'

1.1.1 2016-12-23 15:02 UTC

This package is auto-updated.

Last update: 2024-10-29 04:58:51 UTC


README

vnstat json output parser for PHP

StyleCI License Total Downloads

Usage

use Luna\Vnstat\Vnstat;

class YourClass extends Awesomeness implements Ideas
{
  protected $interface = 'eth0';

  public function runWithStaticMethod()
  {    
    $jsonObject = Vnstat::get($this->interface);
  }
  
  public function runWithNewInstance()
  {
    $vnstat = new Vnstat($this->interface);
    $vnstat->run();
    
    $rawJson = $vnstat->getJson();
    $response = $vnstat->getResponse();
  }
}

Methods

public function Vnstat::__construct(string $interface): void
public function Vnstat::get(string $interface): \Luna\Vnstat\VnstatResponse
public function Vnstat::getResponse(): \Luna\Vnstat\VnstatResponse
public function Vnstat::setExecutablePath(string $executable): $this
public function Vnstat::getExecutablePath(): string
public function Vnstat::setJson(string $json): $this
public function Vnstat::getJson(): string

Errors/Exceptions

Throws Luna\Vnstat\Exceptions\InvalidJsonException if the string returned by Vnstat::getJson() was an invalid json string.

Throws Luna\Vnstat\Exceptions\ExecutableNotFoundException if which vnstat failed.

Throws \Symfony\Component\Process\Exception\ProcessFailedException if vnstat --query --json -i $interface failed.