Laravel Hetzner Cloud

PHP MIT

Production-ready Laravel SDK for the Hetzner Cloud API with support for servers, volumes, networks, firewalls, load balancers, SSH keys, floating IPs, and more.

Stars
19
Forks
0
Downloads
2,275
Open Issues
0
Files main

Repository Files

Loading file structure...
src/Managers/DatacenterManager.php
<?php

namespace Vendor\HetznerCloud\Managers;

use Vendor\HetznerCloud\Collections\DatacenterCollection;
use Vendor\HetznerCloud\DTOs\Datacenter;

class DatacenterManager extends AbstractManager
{
    public function all()
    {
        $response = $this->getRequest('datacenters', $this->buildQueryParams());

        return $this->hydrate($response, function (array $data) {
            $dcs = array_map(fn (array $item) => Datacenter::fromArray($item), $data['datacenters'] ?? []);

            return new DatacenterCollection($dcs);
        });
    }

    public function get()
    {
        return $this->all();
    }

    public function find(int $id)
    {
        $response = $this->getRequest("datacenters/{$id}");

        return $this->hydrate($response, function (array $data) {
            return Datacenter::fromArray($data['datacenter'] ?? []);
        });
    }
}