Laravel Hetzner Storagebox

PHP MIT

Production-ready Laravel package for integrating Hetzner Storage Box into Laravel applications using the native Storage facade and filesystem API.

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

Repository Files

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

namespace GhostCompiler\Hetzner\StorageBox\Managers;

use GhostCompiler\Hetzner\StorageBox\Collections\LocationCollection;
use GhostCompiler\Hetzner\StorageBox\DTOs\Location;
use GuzzleHttp\Promise\PromiseInterface;

class LocationManager extends AbstractManager
{
    /**
     * Get all locations.
     *
     * @return LocationCollection|PromiseInterface
     */
    public function all()
    {
        $response = $this->getRequest('locations', $this->buildQueryParams());

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

            return new LocationCollection($locs);
        });
    }

    /**
     * Alias for all().
     *
     * @return LocationCollection|PromiseInterface
     */
    public function get()
    {
        return $this->all();
    }

    /**
     * Find a location by ID.
     *
     * @return Location|PromiseInterface
     */
    public function find(int $id)
    {
        $response = $this->getRequest("locations/{$id}");

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