Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7f814e2
Add `composer require cloudflare/sdk` in how to install doc
PululuK May 30, 2022
20da7aa
Adding semgrep yaml file
Sep 20, 2024
2d3f198
make cache purge environment aware (#267)
jafowler Dec 17, 2024
33cba42
Upgrade PSR HTTP Message
davidbarratt Apr 20, 2025
57f157d
Fix Deprecations
davidbarratt Apr 20, 2025
a9e2377
Remove composer.lock and make tests run on lowest and furthest deps
davidbarratt Apr 20, 2025
3c471d5
Linter does not run on PHP 8.4
davidbarratt Apr 20, 2025
5716458
Lining only needs to happen once
davidbarratt Apr 20, 2025
5bb58bd
Fix PHP 8.4 implicit-nullable deprecations (#277)
andreicotaga-ebank May 14, 2026
2add4e2
Merge pull request #275 from davidbarratt/psr-http-upgrade
ssicard Jun 18, 2026
7002792
Merge pull request #280 from transferfintech/fix/php-84-nullable
ssicard Jun 18, 2026
9185639
Merge pull request #217 from PululuK/patch-1
ssicard Jun 18, 2026
78cae5a
fix: update CI workflows, linter config, and PHP version constraint
ssicard Jun 18, 2026
d7fc209
fix: remove --prefer-stable from composer install args
ssicard Jun 18, 2026
dfbb2ed
fix: add missing use import for InvalidArgumentException
ssicard Jun 18, 2026
dc73beb
fix: add PHPMD ruleset and fix pre-existing lint violations
ssicard Jun 18, 2026
de59dde
fix: update semgrep workflow to ubuntu-latest
ssicard Jun 18, 2026
9d09daf
Merge pull request #283 from cloudflare/fix/ci-and-linter
ssicard Jun 18, 2026
2c15d68
docs: update README and add CHANGELOG for 2.0.0 release
ssicard Jun 18, 2026
e571eed
Merge pull request #284 from cloudflare/docs/readme-and-changelog
ssicard Jun 18, 2026
c16707f
Merge upstream/master (2.0.0) into fork
Sep 22, 2026
e8438b5
Apply upstream PSR-12 spacing to WorkersRoute
Sep 22, 2026
0abb510
fix(ci): make the prefer-lowest matrix real and raise the PHPUnit floor
Sep 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,28 @@ jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: ['8.2', '8.3']
env:
PHP_VERSION: '8.3'

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
php-version: ${{ env.PHP_VERSION }}

- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-php${{ matrix.php-versions }}-${{ hashFiles('**/composer.lock') }}
key: ${{ runner.os }}-php${{ env.PHP_VERSION }}-${{ hashFiles('**/composer.json') }}

- name: Install dependencies
uses: php-actions/composer@v5
uses: php-actions/composer@v6
with:
command: install
args: --prefer-dist --no-progress --no-suggest --verbose
php_version: ${{ matrix.php-versions }}
version: 1
args: --prefer-dist --no-progress --verbose
php_version: ${{ env.PHP_VERSION }}

- name: Run lint
run: make lint
25 changes: 25 additions & 0 deletions .github/workflows/semgrep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

on:
pull_request: {}
workflow_dispatch: {}
push:
branches:
- main
- master
schedule:
- cron: '0 0 * * *'
name: Semgrep config
jobs:
semgrep:
name: semgrep/ci
runs-on: ubuntu-latest
env:
SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}
SEMGREP_URL: https://cloudflare.semgrep.dev
SEMGREP_APP_URL: https://cloudflare.semgrep.dev
SEMGREP_VERSION_CHECK_URL: https://cloudflare.semgrep.dev/api/check-version
container:
image: returntocorp/semgrep
steps:
- uses: actions/checkout@v3
- run: semgrep ci
16 changes: 9 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: ['8.2', '8.3']
lowest: ['0', '1']
php-versions: ['8.1', '8.2', '8.3', '8.4']

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
Expand All @@ -26,15 +27,16 @@ jobs:
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-php${{ matrix.php-versions }}-${{ hashFiles('**/composer.lock') }}
key: ${{ runner.os }}-php${{ matrix.php-versions }}-lowest${{ matrix.lowest }}-${{ hashFiles('**/composer.json') }}

- name: Install dependencies
uses: php-actions/composer@v5
uses: php-actions/composer@v6
env:
COMPOSER_PREFER_LOWEST: ${{ matrix.lowest }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer-lowest CI installs incompatible PHPUnit

Low Severity

The new test matrix sets COMPOSER_PREFER_LOWEST while phpunit/phpunit is constrained to ^9.0. Prefer-lowest resolves PHPUnit 9.0, which does not define assertObjectHasProperty (added in 9.6.11) that the suite already calls, so the lowest=1 jobs fail.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e8438b5. Configure here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0abb510 — the constraint bug is real, though the symptom isn't quite what's described here.

The lowest=1 jobs weren't failing — they were passing without testing anything. Composer only honours COMPOSER_PREFER_LOWEST on update; this workflow ran install, so the variable was inert and those four jobs silently re-resolved the highest versions, duplicating the lowest=0 jobs:

$ COMPOSER_PREFER_LOWEST=1 composer install
$ composer show phpunit/phpunit
versions : * 9.6.36     # highest, not lowest

So the matrix was reporting green for work it never did. The constraint problem was sitting behind that, latent — with prefer-lowest genuinely applied, ^9.0 resolves 9.3.0 and the suite errors 28 times on assertObjectHasProperty(), exactly as described.

The fix needed both halves: correcting only the constraint would have left the matrix still inert, and correcting only the workflow would have turned the PR red.

One correction worth flagging: ^9.6 is not a sufficient floor. assertObjectHasProperty() landed in 9.6.11, so prefer-lowest on ^9.6 resolves 9.6.0 and still fails. Measured both:

constraint prefer-lowest resolves result
^9.6 9.6.0 28 errors
^9.6.11 9.6.11 OK (156 tests, 994 assertions)

Landed as command: install → update and ^9.0 → ^9.6.11. Both arms now pass and genuinely differ — the lowest arm installs psr/http-message 1.1 and the highest 2.0, so this PR's ^1.0 || ^2.0 change is actually exercised across PHP 8.1–8.4 rather than merely asserted.

with:
command: install
args: --prefer-dist --no-progress --no-suggest --verbose
command: update
args: --prefer-dist --no-progress --verbose
php_version: ${{ matrix.php-versions }}
version: 1

- name: Run tests
run: make test
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/.idea
/vendor/
/composer.lock
/vendor/
/.phpunit.result.cache
6 changes: 3 additions & 3 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
->in(__DIR__ . '/tests')
;

$config = new PhpCsFixer\Config();
$config->setUsingCache(false);
return $config->setRules([
return (new PhpCsFixer\Config())
->setUsingCache(false)
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
])
Expand Down
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Changelog

## 2.0.0

### Breaking Changes

- **Minimum PHP version raised from 7.2.5 to 8.1.** PHP 7.x and 8.0 are no
longer supported. All of these versions are past end-of-life upstream.

### Changes

- Add support for `psr/http-message` v2.0 (constraint is now `^1.1 || ^2.0`).
This resolves dependency conflicts with libraries that require PSR-7 v2,
including `league/oauth2-server` and newer Drupal modules.
([#275](https://github.com/cloudflare/cloudflare-php/pull/275))
- Fix PHP 8.4 implicit-nullable deprecation warnings in `Guzzle::__construct()`
and `Zones::cachePurge()`.
([#280](https://github.com/cloudflare/cloudflare-php/pull/280))
- Upgrade `guzzlehttp/guzzle` constraint from `^7.0.1` to `^7.4`.
- Upgrade `phpunit/phpunit` from `^5.7` to `^9.6 || ^10.0 || ^11.0`.
- Upgrade `friendsofphp/php-cs-fixer` from `^2.6` to `^3.0`.
- Remove committed `composer.lock` (correct practice for libraries).
- Update GitHub Actions workflows: `actions/checkout` v4, `actions/cache` v4,
`php-actions/composer` v6, Semgrep runner to `ubuntu-latest`.
- Fix PHP test matrix to 8.1, 8.2, 8.3, 8.4.
- Migrate linter config from `.php_cs` to `.php-cs-fixer.php`.
- Add PHPMD ruleset file (`phpmd.xml`).
- Remove unused test variables in `DNSAnalyticsTest`.
- Update README to reflect PHP 8.1+ requirement and current project status.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
all: lint test

fix:
php vendor/bin/php-cs-fixer fix --config=.php_cs
php vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php

lint:
php vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --dry-run
php vendor/bin/phpmd src/ text cleancode,codesize,controversial,design,naming,unusedcode
php vendor/bin/phpmd tests/ text cleancode,codesize,controversial,design,naming,unusedcode
php vendor/bin/phpmd src/ text phpmd.xml
php vendor/bin/phpmd tests/ text phpmd.xml

test:
php vendor/bin/phpunit --configuration phpunit.xml
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
# Cloudflare SDK (v4 API Binding for PHP 7)
# Cloudflare SDK (v4 API Binding for PHP)

[![Build Status](https://travis-ci.org/cloudflare/cloudflare-php.svg?branch=master)](https://travis-ci.org/cloudflare/cloudflare-php)
> **Note:** This is a community-maintained PHP SDK covering a subset of the
> Cloudflare API. A comprehensive, auto-generated PHP SDK is planned for the
> future. In the meantime, for full API coverage consider using the
> [Cloudflare API](https://developers.cloudflare.com/api/) directly.

## Requirements

- PHP 8.1 or later

## Installation

The recommended way to install this package is via the Packagist Dependency Manager ([cloudflare/sdk](https://packagist.org/packages/cloudflare/sdk)). You can get specific usage examples on the Cloudflare Knowledge Base under: [Cloudflare PHP API Binding](https://support.cloudflare.com/hc/en-us/articles/115001661191)
Install via Composer ([cloudflare/sdk](https://packagist.org/packages/cloudflare/sdk)):

```
composer require cloudflare/sdk
```

## Cloudflare API version 4

The Cloudflare API can be found [here](https://api.cloudflare.com/).
The Cloudflare API can be found [here](https://developers.cloudflare.com/api/).
Each API call is provided via a similarly named function within various classes in the **Cloudflare\API\Endpoints** namespace:

- [x] [DNS Records](https://www.cloudflare.com/dns/)
- [x] [DNS Analytics](https://api.cloudflare.com/#dns-analytics-table)
- [x] DNS Analytics
- [x] Zones
- [x] User Administration (partial)
- [x] [Cloudflare IPs](https://www.cloudflare.com/ips/)
- [x] [Page Rules](https://support.cloudflare.com/hc/en-us/articles/200168306-Is-there-a-tutorial-for-Page-Rules-)
- [x] Page Rules
- [x] [Web Application Firewall (WAF)](https://www.cloudflare.com/waf/)
- [ ] Virtual DNS Management
- [x] Custom hostnames
Expand All @@ -30,8 +41,6 @@ Each API call is provided via a similarly named function within various classes
- [x] Load Balancers
- [x] Firewall Settings

Note that this repository is currently under development, additional classes and endpoints being actively added.

## Getting Started

```php
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"description": "PHP binding for v4 of the Cloudflare Client API.",
"type": "library",
"require": {
"guzzlehttp/guzzle": "^7.3.0",
"php": ">=8.2",
"psr/http-message": "~1.0",
"guzzlehttp/guzzle": "^7.0.1",
"php": ">=8.1",
"psr/http-message": "^1.0 || ^2.0",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^9.1.2",
"phpunit/phpunit": "^9.6.11",
"phpmd/phpmd" : "@stable",
"friendsofphp/php-cs-fixer": "^3.13"
"friendsofphp/php-cs-fixer": "^3.0"
},
"license": "BSD-3-Clause",
"authors": [
Expand Down
Loading
Loading