1. Go to this page and download the library: Download webinarium/linode-api 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/ */
webinarium / linode-api example snippets
use Linode\LinodeClient;
$client = new LinodeClient();
$regions = $client->regions->findAll();
use Linode\LinodeClient;
$client = new LinodeClient('03d084436a6c91fbafd5c4b20c82e5056a2e9ce1635920c30dc8d81dc7a6665c');
$linodes = $client->linodes->findAll();
use Linode\Exception\LinodeException;
use Linode\LinodeClient;
use Linode\LinodeInstances\Linode;
$client = new LinodeClient('03d084436a6c91fbafd5c4b20c82e5056a2e9ce1635920c30dc8d81dc7a6665c');
try {
$linode = $client->linodes->create([
Linode::FIELD_TYPE => 'g6-standard-2',
Linode::FIELD_REGION => 'us-east',
]);
}
catch (LinodeException $exception) {
// This is the same as the reason of the very first error below.
$message = $exception->getMessage();
foreach ($exception->getErrors() as $error) {
echo $error->field;
echo $error->reason;
}
}
use Linode\LinodeClient;
use Linode\LinodeInstances\Linode;
use Linode\LinodeInstances\LinodeRepositoryInterface;
$client = new LinodeClient('03d084436a6c91fbafd5c4b20c82e5056a2e9ce1635920c30dc8d81dc7a6665c');
/** @var LinodeRepositoryInterface $repository */
$repository = $client->linodes;
/** @var Linode $linode */
$linode = $repository->find(123);
echo $linode->label;
echo $linode->hypervisor;
use Linode\Domains\Domain;
use Linode\Domains\DomainRecord;
use Linode\LinodeClient;
$client = new LinodeClient('03d084436a6c91fbafd5c4b20c82e5056a2e9ce1635920c30dc8d81dc7a6665c');
/** @var Domain $domain */
$domain = $client->domains->findOneBy([
Domain::FIELD_DOMAIN => 'example.com',
]);
/** @var DomainRecord[] $records */
$records = $domain->records->findAll();
foreach ($records as $record) {
echo $record->type;
}
use Linode\LinodeClient;
use Linode\LinodeInstances\Linode;
$client = new LinodeClient('03d084436a6c91fbafd5c4b20c82e5056a2e9ce1635920c30dc8d81dc7a6665c');
/** @var Linode $linode */
$linode = $client->linodes->find(123);
use Linode\LinodeClient;
use Linode\LinodeInstances\Linode;
$client = new LinodeClient('03d084436a6c91fbafd5c4b20c82e5056a2e9ce1635920c30dc8d81dc7a6665c');
/** @var Linode[] $linodes */
$linodes = $client->linodes->findAll();
printf('Found %d linode(s).', count($linodes));
foreach ($linodes as $linode) {
// ...
}
use Linode\LinodeClient;
$client = new LinodeClient('03d084436a6c91fbafd5c4b20c82e5056a2e9ce1635920c30dc8d81dc7a6665c');
$linodes = $client->linodes->findAll();
foreach ($linodes as $linode) {
echo $linode->label;
}
use Linode\LinodeClient;
$client = new LinodeClient('03d084436a6c91fbafd5c4b20c82e5056a2e9ce1635920c30dc8d81dc7a6665c');
$linodes = $client->linodes->findAll();
// This will make three API requests.
foreach ($linodes as $linode) {
echo $linode->label;
}
// This will make no API requests at all.
foreach ($linodes as $linode) {
echo $linode->type;
}
$linodes2 = $client->linodes->findAll();
// This will make three API requests again, as this is another collection.
foreach ($linodes2 as $linode) {
echo $linode->type;
}
use Linode\LinodeClient;
use Linode\LinodeInstances\Linode;
use Linode\RepositoryInterface;
$client = new LinodeClient('03d084436a6c91fbafd5c4b20c82e5056a2e9ce1635920c30dc8d81dc7a6665c');
$linodes = $client->linodes->findAll(Linode::FIELD_LABEL, RepositoryInterface::SORT_DESC);
use Linode\LinodeClient;
use Linode\LinodeInstances\Linode;
$client = new LinodeClient('03d084436a6c91fbafd5c4b20c82e5056a2e9ce1635920c30dc8d81dc7a6665c');
$linodes = $client->linodes->findBy([
Linode::FIELD_REGION => 'us-west',
Linode::FIELD_TAGS => 'app-server',
]);
use Linode\LinodeClient;
use Linode\LinodeInstances\Linode;
$client = new LinodeClient('03d084436a6c91fbafd5c4b20c82e5056a2e9ce1635920c30dc8d81dc7a6665c');
$linode = $client->linodes->findOneBy([
Linode::FIELD_LABEL => 'mysql-server-02',
]);
use Linode\LinodeClient;
$client = new LinodeClient();
$types = $client->linodeTypes->query('(class == "standard" or class == "highmem") or (vcpus >= 12 and vcpus <= 20)');
foreach ($types as $type) {
echo $type->class;
echo $type->vcpus;
}
use Linode\LinodeClient;
$client = new LinodeClient();
$parameters = [
'class1' => 'standard',
'class2' => 'highmem',
'min' => 12,
'max' => 20,
];
$types = $client->linodeTypes->query('(class == :class1 or class == :class2) or (vcpus >= :min and vcpus <= :max)', $parameters);
use Linode\LinodeClient;
use Linode\LinodeTypes\LinodeType;
use Linode\RepositoryInterface;
$client = new LinodeClient();
$parameters = [
'class1' => 'standard',
'class2' => 'highmem',
'min' => 12,
'max' => 20,
];
$types = $client->linodeTypes->query(
'(class == :class1 or class == :class2) or (vcpus >= :min and vcpus <= :max)',
$parameters,
LinodeType::FIELD_MEMORY,
RepositoryInterface::SORT_DESC);