Laravel Cloudflare

PHP MIT

Complete Laravel Cloudflare API SDK for managing DNS records, zones, cache, SSL, firewall rules, workers, analytics, and Cloudflare services with a fluent Laravel-first developer experience.

Stars
2
Forks
0
Downloads
N/A
Open Issues
0
Files main

Repository Files

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

namespace Vendor\Cloudflare\Managers;

use Vendor\Cloudflare\Collections\R2BucketCollection;
use Vendor\Cloudflare\DTOs\R2Bucket;

class R2BucketManager extends AbstractManager
{
    public function all(string $accountId)
    {
        $response = $this->getRequest("accounts/{$accountId}/r2/buckets");

        return $this->hydrate($response, function (array $data) {
            $items = array_map(fn (array $item) => R2Bucket::fromArray($item), $data['result']['buckets'] ?? []);

            return new R2BucketCollection($items);
        });
    }

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

    public function find(string $accountId, string $name)
    {
        $response = $this->getRequest("accounts/{$accountId}/r2/buckets/{$name}");

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

    public function create(string $accountId, array $data)
    {
        $response = $this->postRequest("accounts/{$accountId}/r2/buckets", $data);

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

    public function delete(string $accountId, string $name)
    {
        return $this->deleteRequest("accounts/{$accountId}/r2/buckets/{$name}");
    }
}