PHP code example of divineomega / cachetphp

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

    

divineomega / cachetphp example snippets




use \DivineOmega\CachetPHP\Factories\CachetInstanceFactory;

// The API token for the demo instance is 9yMHsdioQosnyVK4iCVR.
$cachetInstance = CachetInstanceFactory::create('https://demo.cachethq.io/api/v1/', '9yMHsdioQosnyVK4iCVR');

$components = $cachetInstance->getAllComponents();         // Components
$incidents = $cachetInstance->getAllIncidents();           // Incidents
$incidentUpdates = $incidents[0]->getAllIncidentUpdates(); // Incident Updates (Cachet 2.4.0 or above 

// Get incident by id
$incident = $cachetInstance->getIncidentById($incidentId);

// Get components sorted by name ascending
$components = $cachetInstance->getAllComponents('name', 'asc');

// Get components
$components = $cachetInstance->getAllComponents();

// Display components
foreach ($components as $component) {
    echo $component->id.' - '.$component->name.' - '.$component->description.' - '.$component->status;
    echo "<br/>";
}

$componentDetails = ['name' => 'Test Component '.rand(1, 99999), 'status' => 1];

$component = $cachetInstance->createComponent($componentDetails);

echo $component->id.' - '.$component->name.' - '.$component->description.' - '.$component->status;

$incidentDetails = ['name' => 'Test Incident '.rand(1, 99999), 'message' => 'Incident message '.rand(1, 99999), 'status' => 1, 'visible' => 1];

$incident = $cachetInstance->createIncident($incidentDetails);

$incidentUpdateDetails = ['status' => 2, 'message' => 'Test incident update '.rand(1, 99999)];

$incidentUpdate = $incident->createIncidentUpdate($incidentUpdateDetails);

echo $incidentUpdate->id.' - '.$incidentUpdate->incident_id.' - '.$incidentUpdate->status.' - '.$incidentUpdate->message;

// Get components
$components = $cachetInstance->getAllComponents();

// Change component details
$component[0]->name = 'My awesome component';
$component[0]->status = 1;
$component[0]->save();

$incidentDetails = ['name' => 'Test Incident '.rand(1, 99999), 'message' => 'Incident message '.rand(1, 99999), 'status' => 1, 'visible' => 1,
    'component_id' => 1, 'component_status' => 1];

$incident = $cachetInstance->createIncident($incidentDetails);

$incidentUpdateDetails = ['status' => 2, 'message' => 'Test incident update '.rand(1, 99999), 'component_status' => 2];

$incidentUpdate = $incident->createIncidentUpdate($incidentUpdateDetails);

$incident->component_status = 2;
$incident->save();

$incidentUpdate->component_status = 3;
$incidentUpdate->save();

// Get incidents
$incidents = $cachetInstance->getAllIncidents();

// Delete the first one
$incidents[0]->delete();