PHP code example of enlight / pingping

1. Go to this page and download the library: Download enlight/pingping 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/ */

    

enlight / pingping example snippets


Enlight\PingPing\Providers\PingPingServiceProvider::class

$response->body() : string;
$response->json() : array|mixed;
$response->collect() : Illuminate\Support\Collection;
$response->status() : int;
$response->ok() : bool;
$response->successful() : bool;
$response->failed() : bool;
$response->serverError() : bool;
$response->clientError() : bool;
$response->header($header) : string;
$response->headers() : array;

    use Enlight\PingPing\Client;
    
    public function index(Client $client)
    {
        $response = $client->monitors();

        if ($response->failed()) {
            return $response->json();
        }

        return $response->json();
    }

    use Enlight\PingPing\Client;
    
    public function show($id, Client $client)
    {
        $response = $client->monitors((int) $id);

        if ($response->failed()) {
            return $response->json();
        }

        return $response->json();
    }

    use Enlight\PingPing\Client;
    use Enlight\PingPing\Exceptions\MonitorIDRequiredException;
    
    /**
     * @throws MonitorIDRequiredException
     */
    public function show($id, Client $client)
    {
        $response = $client->statistics((int) $id);

        if ($response->failed()) {
            return $response->json();
        }

        return $response->json();
    }

    use Enlight\PingPing\Client;
    use Enlight\PingPing\Exceptions\ValidUrlRequiredException;
   
    /**
     * @throws ValidUrlRequiredException
     */
    public function store(Client $client)
    {
        $url = 'https://my-cool-website.test';

        $response = $client->createMonitor($url);

        if ($response->failed()) {
            return $response->json();
        }

        return $response->json();
    }

    use Enlight\PingPing\Client;
    use Enlight\PingPing\Exceptions\AliasRequiredException;
    use Enlight\PingPing\Exceptions\ValidUrlRequiredException;
    use Enlight\PingPing\Exceptions\MonitorIDRequiredException;
    
    /**
     * @throws AliasRequiredException
     * @throws ValidUrlRequiredException
     * @throws MonitorIDRequiredException
     */
    public function update($id, Client $client)
    {
        $url = 'https://my-cool-website2.test';
        $alias = 'My cool website2';

        $response = $client->updateMonitor((int) $id, $url, $alias);

        if ($response->failed()) {
            return $response->json();
        }

        return $response->json();
    }

    use Enlight\PingPing\Client;
    use Enlight\PingPing\Exceptions\MonitorIDRequiredException;
    
    /**
     * @throws MonitorIDRequiredException
     */
    public function destroy($id, Client $client)
    {
        $response = $client->deleteMonitor((int) $id);

        if ($response->failed()) {
            return $response->json();
        }

        return $response->json();
    }



declare(strict_types=1);

namespace App\Http\Controllers;

use Enlight\PingPing\Client;
use Enlight\PingPing\Exceptions\AliasRequiredException;
use Enlight\PingPing\Exceptions\ValidUrlRequiredException;
use Enlight\PingPing\Exceptions\MonitorIDRequiredException;

class MonitorController extends Controller
{
    /** @var Client */
    private $client;

    public function __construct(Client $client)
    {
        $this->client = $client;
    }

    public function index()
    {
        $response = $this->client->monitors();

        if ($response->failed()) {
            return $response->json();
        }

        return $response->json();
    }

    public function show($id)
    {
        $response = $this->client->monitors((int) $id);

        if ($response->failed()) {
            return $response->json();
        }

        return $response->json();
    }

    /**
     * @throws ValidUrlRequiredException
     */
    public function store()
    {
        $url = 'https://my-cool-website.test';

        $response = $this->client->createMonitor($url);

        if ($response->failed()) {
            return $response->json();
        }

        return $response->json();
    }

    /**
     * @throws AliasRequiredException
     * @throws ValidUrlRequiredException
     * @throws MonitorIDRequiredException
     */
    public function update($id)
    {
        $url = 'https://my-cool-website2.test';
        $alias = 'My cool website2';

        $response = $this->client->updateMonitor((int) $id, $url, $alias);

        if ($response->failed()) {
            return $response->json();
        }

        return $response->json();
    }

    /**
     * @throws MonitorIDRequiredException
     */
    public function destroy($id)
    {
        $response = $this->client->deleteMonitor((int) $id);

        if ($response->failed()) {
            return $response->json();
        }

        return $response->json();
    }
}



declare(strict_types=1);

namespace App\Http\Controllers;

use Enlight\PingPing\Client;
use Enlight\PingPing\Exceptions\MonitorIDRequiredException;

class StatisticsController extends Controller
{
    /**
     * @throws MonitorIDRequiredException
     */
    public function show($id, Client $client)
    {
        $response = $client->statistics((int) $id);

        if ($response->failed()) {
            return $response->json();
        }

        return $response->json();
    }
}
bash
php artisan vendor:publish --provider="Enlight\PingPing\Providers\PingPingServiceProvider" --tag="config"