From 5142505117c982d96a0aa142d0385e20fee2af6f Mon Sep 17 00:00:00 2001 From: ADmad Date: Sat, 2 Jun 2018 18:34:04 +0530 Subject: [PATCH 1/2] Lower CakePHP version requirement to 3.5. --- .travis.yml | 7 ++- README.md | 10 ++-- composer.json | 4 +- src/Template/Bake/mode.ctp | 48 +++++++++++++++++++ .../Shell/Task/MaintenanceModeTaskTest.php | 9 ++-- 5 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 src/Template/Bake/mode.ctp diff --git a/.travis.yml b/.travis.yml index 2ce285b..b0fd62b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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" diff --git a/README.md b/README.md index 9a50774..425cc4f 100644 --- a/README.md +++ b/README.md @@ -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 | @@ -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. @@ -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: diff --git a/composer.json b/composer.json index fc5a0db..f2eded0 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/src/Template/Bake/mode.ctp b/src/Template/Bake/mode.ctp new file mode 100644 index 0000000..3976268 --- /dev/null +++ b/src/Template/Bake/mode.ctp @@ -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 + */ +%> +\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; + } +} diff --git a/tests/TestCase/Shell/Task/MaintenanceModeTaskTest.php b/tests/TestCase/Shell/Task/MaintenanceModeTaskTest.php index ef8bcbe..54d4364 100644 --- a/tests/TestCase/Shell/Task/MaintenanceModeTaskTest.php +++ b/tests/TestCase/Shell/Task/MaintenanceModeTaskTest.php @@ -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; @@ -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; From 46decaafeba5918d8563ced1a7e223a8e322b608 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sat, 2 Jun 2018 19:50:16 +0530 Subject: [PATCH 2/2] Conditionally do inflections used in TestTask. This hack is required due to cakephp/bake#438. --- src/Shell/Task/MaintenanceModeTask.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Shell/Task/MaintenanceModeTask.php b/src/Shell/Task/MaintenanceModeTask.php index 1433f52..f1f7341 100644 --- a/src/Shell/Task/MaintenanceModeTask.php +++ b/src/Shell/Task/MaintenanceModeTask.php @@ -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 @@ -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);