1. Go to this page and download the library: Download sentinelphp/drift 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/ */
sentinelphp / drift example snippets
use SentinelPHP\Drift\Detector;
use SentinelPHP\Schema\Validator;
$detector = new Detector(new Validator());
$schema = [
'type' => 'object',
'properties' => [
'id' => ['type' => 'integer'],
'name' => ['type' => 'string'],
],
'tf(
"[%s] %s at %s\n",
$drift->severity->value,
$drift->type->value,
$drift->path
);
}
use SentinelPHP\Drift\Classifier;
use SentinelPHP\Drift\Enum\DriftType;
use SentinelPHP\Drift\Enum\DriftSeverity;
$classifier = new Classifier();
// Field removed = Critical
$severity = $classifier->classify(DriftType::FieldRemoved, 'email', null);
// Returns: DriftSeverity::Critical
// Field added = Info
$severity = $classifier->classify(DriftType::FieldAdded, null, 'extra_field');
// Returns: DriftSeverity::Info
// Type changed (object → primitive) = Critical
$severity = $classifier->classify(DriftType::TypeChanged, 'object', 'string');
// Returns: DriftSeverity::Critical
$classifier = new Classifier(defaultThreshold: DriftSeverity::Warning);
// Check if drift should trigger an alert
if ($classifier->shouldAlert($drift->severity)) {
// Send notification
}
// Override threshold per-check
$classifier->shouldAlert($drift->severity, DriftSeverity::Critical);