Skip to content

Commit 997aa8c

Browse files
committed
Initial Import
Signed-off-by: Chris Hallgren <challgren@gmail.com>
0 parents  commit 997aa8c

21 files changed

+639
-0
lines changed

.editorconfig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
indent_style = tab
8+
indent_size = 4
9+
end_of_line = lf
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true
12+
13+
[*.bat]
14+
end_of_line = crlf
15+
16+
[*.yml]
17+
indent_style = space
18+
indent_size = 2
19+
20+
[*.md]
21+
indent_style = space

.gitattributes

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Define the line ending behavior of the different file extensions
2+
# Set default behavior, in case users don't have core.autocrlf set.
3+
* text text=auto eol=lf
4+
5+
# Denote all files that are truly binary and should not be modified.
6+
*.png binary
7+
*.jpg binary
8+
*.gif binary
9+
*.ico binary
10+
*.mo binary
11+
*.pdf binary
12+
13+
# Remove files for archives generated using `git archive`
14+
phpunit.xml.dist export-ignore
15+
.travis.yml export-ignore
16+
.gitignore export-ignore
17+
.gitattributes export-ignore
18+
.editorconfig export-ignore
19+
tests/test_app export-ignore

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/phpunit.phar
2+
/vendor/
3+
/tmp/
4+
.idea/
5+
composer.lock
6+
schema-dump-default.lock
7+
composer.phar
8+
/.phpunit.result.cache
9+
.DS_Store

.travis.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
language: php
2+
3+
php:
4+
- 7.4
5+
6+
env:
7+
global:
8+
- DEFAULT=1
9+
10+
matrix:
11+
fast_finish: true
12+
13+
include:
14+
- php: 7.1
15+
16+
- php: 7.2
17+
18+
- php: 7.0
19+
env: PREFER_LOWEST=1
20+
21+
- php: 7.3
22+
env: CODECOVERAGE=1 DEFAULT=0
23+
24+
- php: 7.3
25+
env: CHECKS=1 DEFAULT=0
26+
27+
before_install:
28+
- phpenv config-rm xdebug.ini
29+
30+
before_script:
31+
- if [[ $CHECKS != 1 ]]; then composer require --dev phpunit/phpunit:"^5.7.14|^6.0"; fi
32+
33+
- if [[ $PREFER_LOWEST != 1 ]]; then composer install --prefer-source --no-interaction; fi
34+
- if [[ $PREFER_LOWEST == 1 ]]; then composer update --prefer-lowest --prefer-stable --prefer-dist --no-interaction; fi
35+
- if [[ $PREFER_LOWEST == 1 ]]; then composer require --dev dereuromark/composer-prefer-lowest:dev-master; fi
36+
37+
script:
38+
- if [[ $DEFAULT == 1 ]]; then vendor/bin/phpunit; fi
39+
- if [[ $PREFER_LOWEST == 1 ]]; then vendor/bin/validate-prefer-lowest; fi
40+
41+
- if [[ $CHECKS == 1 ]]; then composer phpstan-setup && composer phpstan; fi
42+
- if [[ $CHECKS == 1 ]]; then composer cs-check; fi
43+
44+
- if [[ $CODECOVERAGE == 1 ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=clover.xml; fi
45+
46+
after_success:
47+
- if [[ $CODECOVERAGE == 1 ]]; then bash <(curl -s https://codecov.io/bash); fi
48+
49+
cache:
50+
directories:
51+
- $HOME/.composer/cache

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) 2020 challgren@gmail.com
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
13+
all 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
21+
THE SOFTWARE.

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Cloudflare Deploy Plugin for CakePHP
2+
3+
[![Build Status](https://travis-ci.com/challgren/cakephp-cloudflare-deploy.svg?branch=master)](https://travis-ci.com/challgren/cakephp-cloudflare-deploy)
4+
[![Coverage Status](https://codecov.io/gh/challgren/cakephp-cloudflare-deploy/branch/master/graph/badge.svg)](https://codecov.io/gh/challgren/cakephp-cloudflare-deploy)
5+
[![Latest Stable Version](https://img.shields.io/packagist/v/challgren/cakephp-cloudflare-deploy)](https://packagist.org/packages/challgren/cakephp-cloudflare-deploy)
6+
![PHP from Packagist](https://img.shields.io/packagist/php-v/challgren/cakephp-cloudflare-deploy)
7+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
8+
[![Total Downloads](https://img.shields.io/packagist/dt/challgren/cakephp-cloudflare-deploy)](https://packagist.org/packages/challgren/cakephp-cloudflare-deploy)
9+
[![PHPStan Level](https://img.shields.io/badge/PHPStan%20Level-7-brightgreen)](https://github.com/phpstan/phpstan)
10+
11+
This plugin provides userful commands when deploying with [Cloudflare](https://cloudflare.com/).
12+
13+
This branch is for use with **CakePHP 3.8+**. For details see [version map](https://github.com/challgren/cakephp-cloudflare-deploy/wiki)
14+
15+
## Installation and Usage
16+
17+
See [documentation](https://github.com/challgren/cakephp-cloudflare-deploy/tree/master/docs)
18+
19+
## Contributing
20+
You can [fork](https://help.github.com/articles/fork-a-repo) the project, add features, and send [pull requests](https://help.github.com/articles/using-pull-requests) or open [issues](https://github.com/challgren/cakephp-cloudflare-deploy/issues).
21+
22+
## Reporting Issues
23+
24+
If you are facing a problem with this plugin or found any bug, please open an issue on [GitHub](https://github.com/challgren/cakephp-cloudflare-deploy/issues).

composer.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "challgren/cakephp-cloudflare-deploy",
3+
"type": "cakephp-plugin",
4+
"description": "Useful console commands for deploying CakePHP apps using Cloudflare.",
5+
"keywords": ["cakephp","cloudflare","deploy"],
6+
"homepage": "https://github.com/challgren/cakephp-cloudflare-deploy",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Chris Hallgren",
11+
"homepage": "https://www.hallgren.net",
12+
"role": "Maintainer"
13+
},
14+
{
15+
"name": "Contributors",
16+
"homepage": "https://github.com/challgren/cakephp-cloudflare-deploy/graphs/contributors",
17+
"role": "Contributor"
18+
}
19+
],
20+
"require": {
21+
"php": ">=7.0",
22+
"cakephp/cakephp": "^3.8",
23+
"cloudflare/sdk": "^1.1"
24+
},
25+
"require-dev": {
26+
"cakephp/cakephp-codesniffer": "^3.0"
27+
},
28+
"support": {
29+
"source": "https://github.com/challgren/cakephp-cloudflare-deploy"
30+
},
31+
"autoload": {
32+
"psr-4": {
33+
"CloudflareDeploy\\": "src/"
34+
}
35+
},
36+
"autoload-dev": {
37+
"psr-4": {
38+
"CloudflareDeploy\\Test\\": "tests/",
39+
"App\\": "tests/test_app/src/",
40+
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/"
41+
}
42+
},
43+
"scripts": {
44+
"phpstan": "phpstan analyse -c tests/phpstan.neon src/",
45+
"phpstan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^0.12 && mv composer.backup composer.json",
46+
"test": "php phpunit.phar",
47+
"test-setup": "[ ! -f phpunit.phar ] && wget https://phar.phpunit.de/phpunit-6.5.13.phar && mv phpunit-6.5.13.phar phpunit.phar || true",
48+
"cs-check": "phpcs --colors -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
49+
"cs-fix": "phpcbf --colors --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/"
50+
}
51+
}

config/app_cloudflare.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
return [
4+
'Cloudflare' => [
5+
'apiUser' => '',
6+
'apiKey' => '',
7+
'zoneId' => ''
8+
]
9+
];

config/bootstrap.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
use Cake\Core\Configure;
3+
4+
// Optionally load additional queue config defaults from local app config
5+
if (file_exists(ROOT . DS . 'config' . DS . 'app_cloudflare.php')) {
6+
Configure::load('app_cloudflare');
7+
}

config/routes.php

Whitespace-only changes.

docs/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# CakePHP Cloudflare Deploy Plugin Documentation
2+
## Version Map
3+
See [Version Map](https://github.com/challgren/cakephp-cloudflare-deploy/wiki)
4+
5+
## Installation
6+
You can install this plugin into your CakePHP application using [composer](http://getcomposer.org).
7+
8+
```sh
9+
$ composer require challgren/cakephp-cloudflare-deploy
10+
```
11+
12+
[Load the plugin](https://book.cakephp.org/3.8/en/plugins.html#loading-a-plugin) in your `src/Application.php`'s boostrap() using:
13+
```sh
14+
$ bin/cake plugin load CloudflareDeploy
15+
```
16+
17+
## Configuration
18+
19+
Set your Cloudflare AAP User, API key and zoneId in `Cloudflare` settings in `app.php`.
20+
21+
_You can get your zone ID by viewing the Overview of the domain controlled by Cloudflare._
22+
23+
```php
24+
return [
25+
'Cloudflare' => [
26+
'apiUser' => 'API Username',
27+
'apiKey' => 'API Key',
28+
'zoneId' => 'Zone ID'
29+
]
30+
];
31+
```
32+
33+
## Usage
34+
35+
Run `bin/cake clear_cloudflare` this will enable Development on Cloudflare and purge the entire cache.

phpunit.xml.dist

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<phpunit
2+
bootstrap="tests/bootstrap.php"
3+
colors="true"
4+
>
5+
<php>
6+
<!-- E_ALL => 32767 -->
7+
<!-- E_ALL & ~E_USER_DEPRECATED => 16383 -->
8+
<ini name="error_reporting" value="32767"/>
9+
</php>
10+
<testsuites>
11+
<testsuite name="queue">
12+
<directory>tests/</directory>
13+
</testsuite>
14+
</testsuites>
15+
16+
<listeners>
17+
<listener class="Cake\TestSuite\Fixture\FixtureInjector">
18+
<arguments>
19+
<object class="Cake\TestSuite\Fixture\FixtureManager"/>
20+
</arguments>
21+
</listener>
22+
</listeners>
23+
24+
<!-- Prevent coverage reports from looking in tests, vendors, config folders -->
25+
<filter>
26+
<whitelist>
27+
<directory suffix=".php">src/</directory>
28+
</whitelist>
29+
</filter>
30+
31+
</phpunit>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
namespace CloudflareDeploy\Command;
3+
4+
use Cake\Console\Arguments;
5+
use Cake\Console\Command;
6+
use Cake\Console\ConsoleIo;
7+
use Cake\Console\ConsoleOptionParser;
8+
use Cake\Core\Configure;
9+
use Cloudflare\API\Adapter\Guzzle;
10+
use Cloudflare\API\Auth\APIKey;
11+
use Cloudflare\API\Endpoints\Zones;
12+
13+
/**
14+
* ClearCloudflare command.
15+
*/
16+
class ClearCloudflareCommand extends Command
17+
{
18+
/**
19+
* @var \Cloudflare\API\Endpoints\Zones|null $zones
20+
*/
21+
public $zones;
22+
23+
/**
24+
* @var \Cloudflare\API\Auth\APIKey|null $api_key
25+
*/
26+
public $api_key;
27+
28+
/**
29+
* @var \Cloudflare\API\Adapter\Guzzle $adapter
30+
*/
31+
public $adapter;
32+
33+
/**
34+
* {@inheritDoc}
35+
*/
36+
public function __construct()
37+
{
38+
parent::__construct();
39+
$apiUser = Configure::read('Cloudflare.apiUser');
40+
$apiKey = Configure::read('Cloudflare.apiKey');
41+
42+
if (!$apiKey || !$apiUser) {
43+
return;
44+
}
45+
46+
$this->api_key = new APIKey($apiUser, $apiKey);
47+
$this->adapter = new Guzzle($this->api_key);
48+
49+
$this->zones = new Zones($this->adapter);
50+
}
51+
52+
/**
53+
* Hook method for defining this command's option parser.
54+
*
55+
* @see https://book.cakephp.org/3.0/en/console-and-shells/commands.html#defining-arguments-and-options
56+
*
57+
* @param \Cake\Console\ConsoleOptionParser $parser The parser to be defined
58+
* @return \Cake\Console\ConsoleOptionParser The built parser.
59+
*/
60+
public function buildOptionParser(ConsoleOptionParser $parser)
61+
{
62+
$parser = parent::buildOptionParser($parser);
63+
64+
$parser->setDescription('Sets the Cloudflare zone into dev mode and purges the whole cache.');
65+
66+
return $parser;
67+
}
68+
69+
/**
70+
* Implement this method with your command's logic.
71+
*
72+
* @param \Cake\Console\Arguments $args The command arguments.
73+
* @param \Cake\Console\ConsoleIo $io The console io
74+
* @return null|int The exit code or null for success
75+
*/
76+
public function execute(Arguments $args, ConsoleIo $io)
77+
{
78+
$apiUser = Configure::read('Cloudflare.apiUser');
79+
$apiKey = Configure::read('Cloudflare.apiKey');
80+
$zoneId = Configure::read('Cloudflare.zoneId');
81+
if (!$apiUser || !$apiKey || !$zoneId) {
82+
$io->error('Cloudflare settings are not configured correctly.');
83+
84+
return 489;
85+
}
86+
87+
$this->zones->changeDevelopmentMode($zoneId, true);
88+
89+
if ($this->zones->cachePurgeEverything($zoneId)) {
90+
$io->out('Cloudflare cache has been purged.');
91+
} else {
92+
$io->out('Cloudflare cache could not be purged.');
93+
}
94+
95+
return null;
96+
}
97+
}

src/Plugin.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
namespace CloudflareDeploy;
3+
4+
use Cake\Core\BasePlugin;
5+
6+
class Plugin extends BasePlugin
7+
{
8+
9+
}

0 commit comments

Comments
 (0)