sergkeim/php-cloudflare-api

PHP Client for Cloudflare API.

Maintainers

Package info

github.com/SergkeiM/php-cloudflare-api

Documentation

pkg:composer/sergkeim/php-cloudflare-api

Transparency log

Statistics

Installs: 7 402

Dependents: 0

Suggesters: 0

Stars: 19

Open Issues: 7

v1.0.0 2026-08-16 16:49 UTC

This package is auto-updated.

Last update: 2026-08-16 16:57:26 UTC


README

A simple PHP Client for Cloudflare API.

Banner

Build Status Software License Coverage Packagist Downloads Latest Version

This package provides convenient access to the Cloudflare REST API using PHP.

Features โœจ

  • PHP >= 8.2
  • Minimal API around the Guzzle HTTP client
  • Framework agnostic โ€” Guzzle and the PSR interfaces are the only runtime dependencies
  • Light and fast thanks to lazy loading of API classes
  • Lazy pagination โ€” iterate every page of a list endpoint without tracking cursors or page counters
  • Extensively documented
  • Optional Laravel integration (service provider + facade), tested against Laravel 12 and 13

Quick install ๐Ÿš€

Via Composer.

This command will get you up and running quickly.

composer require sergkeim/php-cloudflare-api

Versioning and compatibility ๐Ÿ”’

This package follows Semantic Versioning. Breaking changes to the public API happen only in a major release, and each release notes what changed and how to move across on the releases page.

The public API is:

  • Cloudflare\Client โ€” its constructor, paginate(), api(), getHttpClient(), getOptions(), and every endpoint accessor
  • Cloudflare\ClientOptions โ€” its constructor arguments and public properties
  • Every class under Cloudflare\Endpoints, and their public methods
  • Cloudflare\HttpClient\HttpClient, Response and Paginator โ€” the first of these is the supported way to reach endpoints this package does not wrap yet
  • Everything under Cloudflare\Contracts, Cloudflare\Exceptions and Cloudflare\HttpClient\Exceptions
  • Everything under Cloudflare\Configurations, and Cloudflare\ExpressionBuilder
  • The Laravel service provider, the Cloudflare facade, and the published config keys

Not covered, and free to change in any release:

  • Anything marked @internal, and Cloudflare\HttpClient\Retry
  • protected and private members. Endpoint classes are not designed to be extended โ€” compose around them instead
  • The shape of the data inside a response. Response::json() hands back what Cloudflare sent, so those structures follow Cloudflare's API, not this package's version number
  • Everything in bin/, which is tooling for building this package's own documentation

Two more promises worth stating:

  • Dropping a PHP version that has reached end of life, or a Laravel version that has, is a minor release โ€” not a major one
  • New Cloudflare endpoints arrive in minor releases. Cloudflare removing or deprecating an endpoint may mean this package removes it in the next major

Running Tests ๐Ÿงช

If you don't have PHP/Composer installed locally, a Docker setup is provided so you can install dependencies and run the test suite without installing anything on your machine.

A ./dock helper script wraps the common docker compose commands (it starts the container automatically if it isn't already running):

./dock build           # Build the image (only needed once, or after Dockerfile changes)
./dock install          # composer install
./dock test              # Run the full PHPUnit suite
./dock test --filter=SslTest  # Pass any args straight through to phpunit
./dock cs                 # Check code style (php-cs-fixer, dry run)
./dock analyse            # Run static analysis (phpstan)
./dock coverage           # Run the suite with coverage and check the threshold
./dock fix                # Fix code style (php-cs-fixer)
./dock sh                # Open a shell in the container
./dock down               # Stop and remove the container
./dock matrix              # Run the full PHP x Laravel support matrix locally (mirrors CI)
./dock help               # List all commands

Static analysis

src is analysed with PHPStan at level 8, on the lowest supported PHP version, and CI fails on any error. Run it locally with ./dock analyse (or composer analyse); the configuration lives in phpstan.neon.dist.

Support matrix

This package requires PHP >= 8.2.

The Laravel service provider and facade ship in the package but are an optional integration. The integration is tested against Laravel 12 and 13. ./dock matrix builds and tests every supported PHP/Laravel combination locally, in isolated containers, mirroring .github/workflows/tests.yml:

PHP Laravel 12 Laravel 13
8.2 โœ… โŒ
8.3 โœ… โœ…
8.4 โœ… โœ…
8.5 โœ… โœ…

Each matrix cell runs composer update and the full test suite inside its own container/vendor volume, so runs never interfere with each other or with your host composer.json/composer.lock.

Or use docker compose directly if you prefer:

docker compose build
docker compose up -d
docker compose exec php composer install
docker compose exec php composer test
docker compose down

The php service mounts the repository into the container, so changes you make on your host are picked up immediately without rebuilding.

Thanks ๐Ÿ™

License ๐Ÿ“Ž

php-cloudflare-api is licensed under the MIT License - see the LICENSE file for details

Cloudflare, the Cloudflare logo, and Cloudflare Workers are trademarks and/or registered trademarks of Cloudflare, Inc. in the United States and other jurisdictions.