-
Create the script file in the bin/ directory using snake_case naming.
Verify the method you need exists in src/Cpanel.php before proceeding.
-
Add the boilerplate header — always exactly this structure:
<?php
include '../src/Cpanel.php';
$cpl = new \Detain\Cpanel\Cpanel($_SERVER['argv'][1], $_SERVER['argv'][2]);
-
Capture any additional CLI args starting at argv[3]:
$ipAddress = $_SERVER['argv'][3];
Use placeholder strings ('__IP__', '__GROUPNAME__', '__PACKAGENAME__', '__SOURCEIP__', '__DESTINATIONIP__') when the value is a constant the caller will edit in-place.
-
Set output format if you need JSON (list results, raw lookups):
$cpl->format = 'json';
Default format (simplexml) returns an object — cast to array with (array). JSON format requires json_decode(..., true).
-
Call the method and decode the result using the format-appropriate pattern:
simplexml (default) — status/action methods:
$result = (array) $cpl->someMethod(['param' => $value]);
if ($result['@attributes']['status'] > 0) {
print 'success: ' . $result['@attributes']['relevantField'] . PHP_EOL;
} else {
print 'failed: ' . $result['@attributes']['reason'] . PHP_EOL;
}
JSON — list/lookup methods:
$result = json_decode($cpl->someMethod(['param' => $value]), true);
echo json_encode($result, JSON_PRETTY_PRINT);
fetchLicenseId — always guard the returned id:
$lisc = (array) $cpl->fetchLicenseId(['ip' => $ipAddress]);
$id = $lisc['licenseid'];
$id = is_array($id) ? $id[0] : $id;
if ($id) {
print "The license id for $ipAddress is $id\n";
} else {
print "No valid license exists for $ipAddress\n";
}
-
Verify manually after writing:
php bin/your_script.php USERNAME PASSWORD [extra_args]