Skip to content

Commit

Permalink
Merge pull request #16 from ADmad/cake-3.5
Browse files Browse the repository at this point in the history
Lower CakePHP version requirement to 3.5.
  • Loading branch information
HavokInspiration authored Jun 11, 2018
2 parents 8e2c42a + 46decaa commit eef3d13
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 17 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ matrix:
- php: 7.1
env: CODECOVERAGE=1 DEFAULT=0

- php: 5.6
env: PREFER_LOWEST=1

before_script:
- composer self-update
- composer install --prefer-source --no-interaction
- if [[ $PREFER_LOWEST != 1 ]]; then composer update --no-interaction; fi
- if [[ $PREFER_LOWEST == 1 ]]; then composer update --no-interaction --prefer-lowest --prefer-stable; fi

- sh -c "if [ '$PHPCS' = '1' ]; then composer require cakephp/cakephp-codesniffer:dev-master; fi"

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ for your CakePHP website / applications.

## About the plugin versions

| CakePHP < 3.3.0 | CakePHP >= 3.3.0 | CakePHP >= 3.6.0 |
| CakePHP < 3.3.0 | CakePHP >= 3.3.0 | CakePHP >= 3.5.0 |
| --------------- | ---------------- | ---------------- |
| Wrench 1.X | Wrench 2.X | Wrench 3.X |
| PHP >= 5.4.16 | PHP >= 5.5.9 | PHP >= 5.6.0 |
Expand Down Expand Up @@ -64,15 +64,15 @@ use Wrench\Middleware\MaintenanceMiddleware;
public function middleware($middleware)
{
$middleware->add(new MaintenanceMiddleware());

// Other middleware configuration

return $middleware;
}
```

Since this Middleware is here to prevent the application from responding, it should be the first to be treated by the Dispatcher and should,
as such, be configured as the first one, either by adding it in the beginning of the method with the ``push()`` method or using the
as such, be configured as the first one, either by adding it in the beginning of the method with the ``push()`` method or using the
``prepend()`` method anywhere you want in your middlewares configuration.

By default, only adding it with the previous line will make use of the **Redirect** mode. More informations on maintenance Modes below.
Expand Down Expand Up @@ -120,7 +120,7 @@ $middleware->add(new MaintenanceMiddleware([

While you put your application under maintenance, you might want, as the project administrator or developer, to be able
to access the application. You can do so using the IP whitelisting feature.
When configuring the `MaintenanceMiddleware`, just pass an array of allowed IP addresses to the `whitelist` key in the
When configuring the `MaintenanceMiddleware`, just pass an array of allowed IP addresses to the `whitelist` key in the
Middleware configuration array. All those IP will be allowed to access the application, even if the maintenance mode is
on:

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
},
"require": {
"php": ">=5.6.0",
"cakephp/cakephp": "~3.6"
"cakephp/cakephp": "^3.5"
},
"require-dev": {
"phpunit/phpunit": "<6.0",
"phpunit/phpunit": "^5.7.14|^6.0",
"cakephp/bake": "@stable"
},
"autoload": {
Expand Down
18 changes: 13 additions & 5 deletions src/Shell/Task/MaintenanceModeTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Wrench\Shell\Task;

use Bake\Shell\Task\SimpleBakeTask;
use Cake\Utility\Inflector;

/**
* Bake task responsible of generating Maintenance Mode skeleton
Expand Down Expand Up @@ -56,13 +57,20 @@ public function template()
*/
public function bakeTest($className)
{
if (!isset($this->Test->classSuffixes[$this->name()])) {
$this->Test->classSuffixes[$this->name()] = '';
$suffixName = $typeName = $this->name();

if (isset($this->Test->classSuffixes['entity'])) {
$typeName = ucfirst($typeName);
} else {
$suffixName = $typeName = Inflector::camelize($typeName);
}

if (!isset($this->Test->classSuffixes[$suffixName])) {
$this->Test->classSuffixes[$suffixName] = '';
}

$name = ucfirst($this->name());
if (!isset($this->Test->classTypes[$name])) {
$this->Test->classTypes[$name] = 'Maintenance\Mode';
if (!isset($this->Test->classTypes[$typeName])) {
$this->Test->classTypes[$typeName] = 'Maintenance\Mode';
}

return parent::bakeTest($className);
Expand Down
48 changes: 48 additions & 0 deletions src/Template/Bake/mode.ctp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<%
/**
* Copyright (c) Yves Piquel (http://www.havokinspiration.fr)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Yves Piquel (http://www.havokinspiration.fr)
* @link http://github.com/HavokInspiration/wrench
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
%>
<?php
namespace <%= $namespace %>\Maintenance\Mode;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Wrench\Mode\Mode;

/**
* <%= $name %> Maintenance Mode
*/
class <%= $name %> extends Mode
{

/**
* Array containing the default config value for your maintenance mode
* This value can be overridden when loading the mode
* You can access a config value using $this->getConfig('configkey');
*
* @see \Cake\Core\InstanceConfigTrait
*/
protected $_defaultConfig = [];

/**
* Main method of the mode.
*
* If the mode is to take over the response of the current request, this
* method should return a Response object. It can return null if the request
* should follow the classic request cycle
*
* {@inheritDoc}
*/
public function process(ServerRequestInterface $request, ResponseInterface $response)
{
return $response;
}
}
9 changes: 6 additions & 3 deletions tests/TestCase/Shell/Task/MaintenanceModeTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Wrench\Test\TestCase\Shell\Task;

use Bake\Shell\Task\BakeTemplateTask;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\TestSuite\StringCompareTrait;
use Cake\TestSuite\TestCase;
Expand All @@ -32,9 +33,11 @@ public function setUp()
{
parent::setUp();

Plugin::load('WyriHaximus/TwigView', [
'bootstrap' => true,
]);
if (version_compare(Configure::version(), '3.6.0', '>=')) {
Plugin::load('WyriHaximus/TwigView', [
'bootstrap' => true,
]);
}

$this->_compareBasePath = Plugin::path('Wrench') . 'tests' . DS . 'comparisons' . DS . 'Maintenance' . DS . 'Mode' . DS;

Expand Down

0 comments on commit eef3d13

Please sign in to comment.