Skip to content

Commit 6ec52ca

Browse files
author
Michael Rook
committed
Initial Release!
1 parent 4508d67 commit 6ec52ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1534
-1
lines changed

.gitattributes

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Path-based git attributes
2+
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
3+
4+
# Ignore all test and documentation with "export-ignore".
5+
* text=auto
6+
/.github export-ignore
7+
/tests export-ignore
8+
.gitattributes export-ignore
9+
.gitignore export-ignore
10+
.styleci.yml export-ignore
11+
.editorconfig export-ignore
12+
CONTRIBUTING.md export-ignore
13+
phpunit.xml export-ignore
14+
phpunit.xml.dist export-ignore

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/node_modules
2+
/vendor
3+
.DS_Store
4+
.env
5+
.env.backup
6+
.phpunit.result.cache
7+
.php_cs.cache
8+
composer.lock
9+
npm-debug.log
10+
yarn-error.log

.styleci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
preset: laravel
2+
disabled:
3+
- no_unused_imports

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Changelog
2+
3+
All notable changes to `statamic-cloudflare` will be documented in this file
4+
5+
## 1.0.0 - 29/07/2021 (dd/mm/yyyy)
6+
7+
- Initial release

CONTRIBUTING.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Contributing
2+
3+
Contributions are **welcome** and will be fully **credited**.
4+
5+
Please read and understand the contribution guide before creating an issue or pull request.
6+
7+
## Etiquette
8+
9+
This project is open source, and as such, the maintainers give their free time to build and maintain the source code
10+
held within. They make the code freely available in the hope that it will be of use to other developers. It would be
11+
extremely unfair for them to suffer abuse or anger for their hard work.
12+
13+
Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
14+
world that developers are civilized and selfless people.
15+
16+
It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
17+
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
18+
19+
## Viability
20+
21+
When requesting or submitting new features, first consider whether it might be useful to others. Open
22+
source projects are used by many developers, who may have entirely different needs to your own. Think about
23+
whether or not your feature is likely to be used by other users of the project.
24+
25+
## Procedure
26+
27+
Before filing an issue:
28+
29+
- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
30+
- Check to make sure your feature suggestion isn't already present within the project.
31+
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
32+
- Check the pull requests tab to ensure that the feature isn't already in progress.
33+
34+
Before submitting a pull request:
35+
36+
- Check the codebase to ensure that your feature doesn't already exist.
37+
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
38+
39+
## Requirements
40+
41+
If the project maintainer has any additional requirements, you will find them listed here.
42+
43+
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer).
44+
45+
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
46+
47+
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
48+
49+
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
50+
51+
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
52+
53+
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
54+
55+
**Happy coding**!

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Handmade Web & Design
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 162 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,162 @@
1-
# statamic-cloudflare
1+
[![MIT Licensed](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE.md)
2+
3+
Cloudflare integration for Statamic with CLI, static caching integration and control panel integration.
4+
5+
Inspired by [sebdesign/artisan-cloudflare](https://github.com/sebdesign/artisan-cloudflare)
6+
7+
## Requirements
8+
9+
* Statamic 3.1.2 or higher
10+
11+
## Installation
12+
13+
You can install the package via composer:
14+
15+
```shell
16+
composer require handmadeweb/statamic-cloudflare
17+
```
18+
19+
#### Copy the package config to your local config with the publish command:
20+
21+
```shell
22+
php artisan vendor:publish --provider="HandmadeWeb\StatamicCloudflare\ServiceProvider"
23+
```
24+
25+
Then add your cloudflare details to your `.env` file.
26+
27+
```env
28+
CLOUDFLARE_KEY=
29+
CLOUDFLARE_EMAIL=
30+
```
31+
32+
And configure your `zones` in your `statamic-cloudflare.php`
33+
34+
```php
35+
/*
36+
* Array of zones.
37+
*
38+
* Each zone must have its domain as the key. The value should be your zoneId.
39+
*
40+
* you can find your zoneId under 'Account Home > site > Api'.
41+
*
42+
* E.g.
43+
*
44+
* 'example.com' => '023e105f4ecef8ad9ca31a8372d0c353'
45+
*/
46+
'zones' => [
47+
//
48+
],
49+
```
50+
51+
By default all purge actions `except the Cli commands` will be queued with your default queue.
52+
53+
This can be changed in the configuration.
54+
55+
```php
56+
/*
57+
* Should purges be processed in a queue?
58+
* CLI commands will always run on request.
59+
*/
60+
'queued' => true,
61+
```
62+
63+
## Usage
64+
65+
### Cli
66+
67+
You can purge everything via the following commands.
68+
69+
```shell
70+
php artisan cloudflare:cache:purge:everything
71+
```
72+
73+
```shell
74+
php please cloudflare:cache:purge:everything
75+
```
76+
77+
### Static Caching
78+
79+
If you want to use `statamic-cloudflare` as a static cache strategy then you will need to manually register the cacher in the register method of your `App\Providers\AppServiceProvider` class.
80+
81+
```php
82+
/**
83+
* Register any application services.
84+
*
85+
* @return void
86+
*/
87+
public function register()
88+
{
89+
\HandmadeWeb\StatamicCloudflare\Cloudflare::registerCacher();
90+
}
91+
```
92+
93+
Then update your `static_cache` config.
94+
95+
```php
96+
'strategies' => [
97+
98+
'half' => [
99+
'driver' => 'application',
100+
'expiry' => null,
101+
],
102+
103+
'full' => [
104+
'driver' => 'file',
105+
'path' => public_path('static'),
106+
'lock_hold_length' => 0,
107+
],
108+
109+
'cloudflare' => [
110+
'driver' => 'cloudflare',
111+
'strategy' => 'null',
112+
],
113+
],
114+
```
115+
116+
Then update the `static_cache` strategy at the top of the configuration to:
117+
118+
```php
119+
'strategy' => 'cloudflare',
120+
```
121+
122+
Currently the Cloudflare integration is only used for purging, If you would like to use another caching strategy in combination with this caching strategy, then you are free to do that.
123+
124+
This can be done by updating the `strategy` section within the `cloudflare` strategy, below is an example where we will be caching the application using the [half measure](https://statamic.dev/static-caching#application-driver)
125+
126+
```php
127+
'cloudflare' => [
128+
'driver' => 'cloudflare',
129+
'strategy' => 'half',
130+
],
131+
```
132+
133+
In theory, you should be able to use any caching strategy here, such as the [full measure](https://statamic.dev/static-caching#file-driver) or any other first or third party strategies, `statamic-cloudfare` will simply pass requests to the defined strategy and will just hook into the purge actions to also purge the page in Cloudflare.
134+
135+
### Control Panel
136+
137+
`statamic-cloudflare` will add a utility to your Statamic CP.
138+
139+
route: `/cp/utilities/cloudflare`
140+
141+
This will be available to `Super Users` and Users who have the `
142+
Cloudflare Manager` permission.
143+
144+
You can purge everything quickly from here.
145+
146+
## Changelog
147+
148+
Please see [CHANGELOG](https://github.com/handmadeweb/statamic-cloudflare/blob/main/CHANGELOG.md) for more information what has changed recently.
149+
150+
## Contributing
151+
152+
Please see [CONTRIBUTING](https://github.com/handmadeweb/statamic-cloudflare/blob/main/CONTRIBUTING.md) for details.
153+
154+
## Credits
155+
156+
- [Handmade Web & Design](https://github.com/handmadeweb)
157+
- [Michael Rook](https://github.com/michaelr0)
158+
- [All Contributors](https://github.com/handmadeweb/statamic-cloudflare/graphs/contributors)
159+
160+
## License
161+
162+
The MIT License (MIT). Please see [License File](https://github.com/handmadeweb/statamic-cloudflare/blob/main/LICENSE.md) for more information.

composer.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "handmadeweb/statamic-cloudflare",
3+
"license": "MIT",
4+
"description": "",
5+
"keywords": [
6+
"statamic",
7+
"statamic-addon",
8+
"statamic-plugin",
9+
"statamic-cache",
10+
"cloudflare"
11+
],
12+
"require": {
13+
"php": "^7.3 || ^8.0",
14+
"statamic/cms": "^3.1.2",
15+
"cloudflare/sdk": "^1.2"
16+
},
17+
"require-dev": {
18+
"orchestra/testbench": "^4.0 || ^5.0 || ^6.0"
19+
},
20+
"scripts": {
21+
"test": "vendor/bin/phpunit",
22+
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
23+
},
24+
"autoload": {
25+
"psr-4": {
26+
"HandmadeWeb\\StatamicCloudflare\\": "src"
27+
}
28+
},
29+
"autoload-dev": {
30+
"psr-4": {
31+
"HandmadeWeb\\StatamicCloudflare\\Tests\\": "tests"
32+
}
33+
},
34+
"extra": {
35+
"statamic": {
36+
"name": "Statamic Cloudflare",
37+
"description": "Statamic Cloudflare addon"
38+
},
39+
"laravel": {
40+
"providers": [
41+
"HandmadeWeb\\StatamicCloudflare\\ServiceProvider"
42+
]
43+
}
44+
}
45+
}

config/statamic-cloudflare.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
* Global API Key on the "My Profile > Api Tokens > API Keys" page.
7+
*/
8+
'key' => env('CLOUDFLARE_KEY', null),
9+
10+
/*
11+
* Email address associated with your account.
12+
*/
13+
'email' => env('CLOUDFLARE_EMAIL', null),
14+
15+
/*
16+
* Should purges be processed in a queue?
17+
* CLI commands will always run on request.
18+
*/
19+
'queued' => true,
20+
21+
/*
22+
* Array of zones.
23+
*
24+
* Each zone must have its domain as the key. The value should be your zoneId.
25+
*
26+
* you can find your zoneId under 'Account Home > site > Api'.
27+
*
28+
* E.g.
29+
*
30+
* 'example.com' => '023e105f4ecef8ad9ca31a8372d0c353'
31+
*/
32+
'zones' => [
33+
//
34+
],
35+
];

phpunit.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage processUncoveredFiles="true">
4+
<include>
5+
<directory suffix=".php">./src</directory>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="Test Suite">
10+
<directory suffix="Test.php">./tests</directory>
11+
</testsuite>
12+
</testsuites>
13+
<php>
14+
<env name="APP_ENV" value="testing"/>
15+
<env name="APP_URL" value="http://localhost" />
16+
<env name="APP_KEY" value="base64:QeU8nSJFKtBB3Y9SdxH0U4xH/1rsFd4zNfOLTeK/DUw=" />
17+
<env name="CACHE_DRIVER" value="array"/>
18+
<env name="SESSION_DRIVER" value="array"/>
19+
<env name="QUEUE_DRIVER" value="sync"/>
20+
<env name="MAIL_DRIVER" value="array"/>
21+
<env name="DB_CONNECTION" value="sqlite"/>
22+
<env name="DB_DATABASE" value=":memory:"/>
23+
</php>
24+
</phpunit>

0 commit comments

Comments
 (0)