Skip to content

Commit a834741

Browse files
committed
Untested first verison of update to Cake 4
1 parent c1b6d99 commit a834741

19 files changed

+135
-83
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ vendor
22
composer.lock
33
.DS_Store
44
build
5+
/.phpunit.result.cache
6+
.idea

.travis.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
language: php
22

33
php:
4-
- 7.1
4+
- 7.2
5+
- 7.3
6+
- 7.4snapshot
57

68
services:
79
- mysql
@@ -11,10 +13,7 @@ before_script:
1113
- composer install --prefer-dist
1214

1315
script:
14-
- vendor/bin/phpunit
15-
- vendor/bin/phpcs -pn --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests ./config
16-
- vendor/bin/phpcs --colors -pn --standard=vendor/scherersoftware/coding-standard/scherersoftware ./src ./tests
17-
- php -d memory_limit=-1 vendor/bin/phpstan analyse -c phpstan.neon -l 1 ./src
16+
- composer check
1817

1918
after_success:
2019
- bash <(curl -s https://codecov.io/bash)

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015-2018 scherer software (http://scherer-software.de)
3+
Copyright (c) 2015-2019 scherer software (http://scherer-software.de)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

composer.json

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
"type": "cakephp-plugin",
66
"homepage": "https://github.com/scherersoftware/cake-cktools",
77
"require": {
8-
"php": ">=7.1.0",
9-
"cakephp/cakephp": ">= 3.8",
10-
"mpdf/mpdf": "^7.0",
8+
"php": ">=7.2.0",
9+
"cakephp/cakephp": "^4.0.0-RC1",
10+
"mpdf/mpdf": "^8.0",
1111
"gettext/gettext": "^4.1",
12-
"scherersoftware/cake-api-baselayer": "^2.0",
13-
"codekanzlei/cake-frontend-bridge": "3.0.*",
14-
"codekanzlei/cake-auth-actions": "3.0.*"
12+
"scherersoftware/cake-api-baselayer": "dev-cake-3.8",
13+
"codekanzlei/cake-frontend-bridge": "4.x-dev",
14+
"codekanzlei/cake-auth-actions": "^4.0.0-rc5"
1515
},
1616
"require-dev": {
17-
"phpunit/phpunit": "^6.0",
17+
"phpunit/phpunit": "^8.3.3|^8.4",
1818
"phpstan/phpstan": "^0.11",
19-
"cakephp/cakephp-codesniffer": "^3.1",
20-
"scherersoftware/coding-standard": "^3.1"
19+
"cakephp/cakephp-codesniffer": "^4.0.0-beta4",
20+
"scherersoftware/coding-standard": "4.0.x-dev"
2121
},
2222
"autoload": {
2323
"psr-4": {
@@ -28,11 +28,13 @@
2828
"scripts": {
2929
"check": [
3030
"@php-check",
31-
"@php-check-strict",
32-
"@phpstan"
31+
"@phpstan",
32+
"@test"
3333
],
34-
"php-check": "vendor/bin/phpcs --colors -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./config",
35-
"php-check-strict": "vendor/bin/phpcs -p --standard=vendor/scherersoftware/coding-standard/scherersoftware ./src ./config",
36-
"phpstan": "php -d memory_limit=-1 vendor/bin/phpstan analyse -c phpstan.neon -l 5 ./src"
37-
}
34+
"php-check": "vendor/bin/phpcs -p --standard=vendor/scherersoftware/coding-standard/scherersoftware ./src ./config",
35+
"phpstan": "php -d memory_limit=-1 vendor/bin/phpstan analyse -c phpstan.neon -l 5 ./src",
36+
"test": "vendor/bin/phpunit --colors=always"
37+
},
38+
"minimum-stability": "dev",
39+
"prefer-stable": true
3840
}

phpstan.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ parameters:
44
ignoreErrors:
55
- '#Call to static method read\(\) on an unknown class App\\Lib\\Environment.#'
66
- '#Parameter \$user of method CkTools\\Utility\\UserToken::getTokenForUser\(\) has invalid typehint type App\\Model\\Entity\\User.#'
7+
- '#Constant ROOT not found#'
8+
- '#Access to an undefined property Cake\\Datasource\\EntityInterface::\$(last_|)password#'
9+
- '#App\\Model\\Entity\\User#'

phpunit.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
colors="true"
33
processIsolation="false"
44
stopOnFailure="false"
5-
syntaxCheck="false"
65
bootstrap="./tests/bootstrap.php"
76
>
87
<php>

src/Controller/Component/MaintenanceComponent.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
use App\Lib\Environment;
66
use Cake\Controller\Component;
77
use Cake\Controller\ComponentRegistry;
8+
use Cake\Http\Cookie\Cookie;
89

910
/**
1011
* Maintenance component
11-
*
12-
* @property \App\Lib\Environment
1312
*/
1413
class MaintenanceComponent extends Component
1514
{
@@ -21,8 +20,8 @@ class MaintenanceComponent extends Component
2120
/**
2221
* Constructor
2322
*
24-
* @param \Cake\Controller\ComponentRegistry; $registry A ComponentRegistry object.
25-
* @param string:mixed[] $config Array of configuration settings.
23+
* @param \Cake\Controller\ComponentRegistry $registry A ComponentRegistry object.
24+
* @param array $config Array of configuration settings.
2625
*/
2726
public function __construct(ComponentRegistry $registry, array $config = [])
2827
{
@@ -59,7 +58,10 @@ public function beforeFilter()
5958

6059
if (!self::isMaintenanceActive()) {
6160
// if maintenance is not active but maintenance page is requested -> redirect to default page
62-
if (in_array($currentUrl, $accessibleUrls) && substr($maintenancePage, -strlen($currentUrl)) === $currentUrl) {
61+
if (
62+
in_array($currentUrl, $accessibleUrls)
63+
&& substr($maintenancePage, -strlen($currentUrl)) === $currentUrl
64+
) {
6365
$maintenanceBasePage = Environment::read('MAINTENANCE_BASE_URL');
6466

6567
return $this->_controller->redirect($maintenanceBasePage);
@@ -69,18 +71,21 @@ public function beforeFilter()
6971
}
7072

7173
$cookieName = Environment::read('MAINTENANCE_COOKIE_NAME');
72-
$cookieExists = ($this->_controller->Cookie->read($cookieName) !== null);
74+
$cookieExists = ($this->_controller->getRequest()->getCookie($cookieName) !== null);
7375
if ($cookieExists) {
7476
return;
7577
}
7678
$headerActive = Environment::read('MAINTENANCE_HEADER_ACTIVE');
7779
$headerName = Environment::read('MAINTENANCE_HEADER_NAME');
7880
$headerValue = Environment::read('MAINTENANCE_HEADER_VALUE');
7981
$successUrl = Environment::read('MAINTENANCE_PASSWORD_SUCCESS_URL');
80-
if ($headerActive && !empty($this->_controller->request->getHeader($headerName))
81-
&& $this->_controller->request->getHeader($headerName) === $headerValue
82+
$cookie = new Cookie($cookieName, '1');
83+
if (
84+
$headerActive
85+
&& !empty($this->_controller->getRequest()->getHeader($headerName))
86+
&& $this->_controller->getRequest()->getHeader($headerName) === $headerValue
8287
) {
83-
$this->_controller->Cookie->write($cookieName, true);
88+
$this->_controller->getRequest()->getCookieCollection()->add($cookie);
8489

8590
return $this->_controller->redirect($successUrl);
8691
}
@@ -104,7 +109,7 @@ public function beforeFilter()
104109
}
105110

106111
if ($_SERVER['PHP_AUTH_USER'] === $user && $_SERVER['PHP_AUTH_PW'] === $password) {
107-
$this->_controller->Cookie->write($cookieName, true);
112+
$this->_controller->getRequest()->getCookieCollection()->add($cookie);
108113

109114
return $this->_controller->redirect($successUrl);
110115
}

src/Controller/Component/ToolsComponent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ToolsComponent extends Component
1717
/**
1818
* {@inheritDoc}
1919
*/
20-
public function initialize(array $config)
20+
public function initialize(array $config): void
2121
{
2222
parent::initialize($config);
2323

src/Lib/PdfGenerator.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
use Cake\Core\InstanceConfigTrait;
66
use Cake\Utility\Hash;
77
use Cake\View\View;
8+
use InvalidArgumentException;
89
use Mpdf\Mpdf;
10+
use RuntimeException;
911

1012
/**
1113
* Wrapper for generating PDF files with MPDF using CakePHP's view files.
@@ -18,19 +20,19 @@ class PdfGenerator
1820
use InstanceConfigTrait;
1921

2022
// Return the MPDF instance
21-
const TARGET_RETURN = 'return';
23+
public const TARGET_RETURN = 'return';
2224

2325
// send the file to the browser
24-
const TARGET_BROWSER = 'browser';
26+
public const TARGET_BROWSER = 'browser';
2527

2628
// write the PDF to a file
27-
const TARGET_FILE = 'file';
29+
public const TARGET_FILE = 'file';
2830

2931
// Will return the rendered PDF's binary data
30-
const TARGET_BINARY = 'binary';
32+
public const TARGET_BINARY = 'binary';
3133

3234
// Will download the file to the browser
33-
const TARGET_DOWNLOAD = 'download';
35+
public const TARGET_DOWNLOAD = 'download';
3436

3537
/**
3638
* Defaut config
@@ -64,13 +66,12 @@ class PdfGenerator
6466
* Constructor
6567
*
6668
* @param array $config Instance Config
67-
* @return void
6869
*/
6970
public function __construct(array $config = [])
7071
{
7172
$this->setConfig($config);
7273
if ($this->_config['pdfSourceFile'] && !is_readable($this->_config['pdfSourceFile'])) {
73-
throw new \Exception("pdfSourceFile {$this->_config['pdfSourceFile']} is not readable.");
74+
throw new RuntimeException("pdfSourceFile {$this->_config['pdfSourceFile']} is not readable.");
7475
}
7576
}
7677

@@ -101,7 +102,7 @@ protected function _getView(): View
101102
* @param array $viewVars View variables
102103
* @return \Mpdf\Mpdf
103104
*/
104-
protected function _preparePdf($viewFile, $viewVars): Mpdf
105+
protected function _preparePdf($viewFile, array $viewVars): Mpdf
105106
{
106107
$mpdf = new Mpdf($this->_config['mpdfSettings']);
107108

@@ -121,7 +122,6 @@ protected function _preparePdf($viewFile, $viewVars): Mpdf
121122
}
122123

123124
if ($this->_config['pdfSourceFile']) {
124-
$mpdf->SetImportUse();
125125
$pagecount = $mpdf->SetSourceFile($this->_config['pdfSourceFile']);
126126
if ($pagecount > 1) {
127127
for ($i = 0; $i <= $pagecount; ++$i) {
@@ -196,7 +196,7 @@ public function render($viewFile, array $options = [])
196196
case self::TARGET_BINARY:
197197
return $mpdf->Output('', 'S');
198198
default:
199-
throw new \InvalidArgumentException("{$options['target']} is not a valid target");
199+
throw new InvalidArgumentException("{$options['target']} is not a valid target");
200200
}
201201
}
202202
}

src/Model/Behavior/SortableBehavior.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class SortableBehavior extends Behavior
1616
/**
1717
* Stores the original value of sortField in beforeSave for later comparisons.
1818
*
19-
* @var string|int
19+
* @var string|int|null
2020
*/
2121
private $__originalSortValue;
2222

@@ -184,6 +184,6 @@ public function getNextSortValue(array $scope = []): int
184184
return 1;
185185
}
186186

187-
return ($res['maxSort'] + 1);
187+
return $res['maxSort'] + 1;
188188
}
189189
}

0 commit comments

Comments
 (0)