Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cakephp 5 #104

Draft
wants to merge 36 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b4836ad
refactor: cakephp 5...
didoda Feb 27, 2025
7269ca0
fix: phpdoc
didoda Feb 27, 2025
f7c00b7
fix: nullable vars phpdoc
didoda Feb 27, 2025
8f3e4a0
fix: paths
didoda Feb 27, 2025
5b3a809
fix: phpstan
didoda Feb 27, 2025
3a7b8cc
refactor: replace @dataProvider with DataProvider
didoda Feb 27, 2025
860f866
refactor: make data provider functions static
didoda Feb 27, 2025
78d5311
tests: fix Oauth2Authenticator
didoda Feb 28, 2025
e1198be
tests: ThumbHelper
didoda Feb 28, 2025
27ec703
tests: fix HtmlHelper and strategies
didoda Feb 28, 2025
8a085e0
chore fix: phpcs
didoda Feb 28, 2025
c87f4d2
fix: phpunit.xml.dist extentsions bootstrap
didoda Feb 28, 2025
56a8df6
fix: phpunix.xml.dist
didoda Feb 28, 2025
81c19b3
fix: HtmlHelper getMeta signature
didoda Feb 28, 2025
d22d8a2
tests: fix namespace
didoda Feb 28, 2025
3a0584f
tests: fix static provider
didoda Feb 28, 2025
0be9981
tests: fix testAuthenticateLeeway
didoda Feb 28, 2025
db765f6
tests: fix BaseClient testBase
didoda Feb 28, 2025
27b180d
tests: fix BaseClient
didoda Feb 28, 2025
8f33123
fix: remove cake Folder reference
didoda Feb 28, 2025
637f350
tests: fix BaseClient testLogCall
didoda Feb 28, 2025
166aa25
tests: fix Plugin testConsole
didoda Feb 28, 2025
e81d550
tests: fix AssetStrategy loadAssets
didoda Feb 28, 2025
2f35802
tests: replace @coversDefaultClass with CoversClass
didoda Feb 28, 2025
b3641c2
chore fix: phpcs
didoda Feb 28, 2025
99c5f78
tests: use CoverMethod instead of @covers
didoda Feb 28, 2025
f5f2768
tests: refactor CoversMethod at the beginning of class
didoda Feb 28, 2025
f280cad
chore fix: phpcs
didoda Feb 28, 2025
0ab69e3
refactor: strategies classes
didoda Feb 28, 2025
974f909
tests: fix PluginTest
didoda Feb 28, 2025
31f73d7
tests: fix strategies and more
didoda Feb 28, 2025
bd8fb1c
chore fix: phpcs
didoda Feb 28, 2025
c3bb52b
tests: strategies
didoda Feb 28, 2025
041a4ac
tests: fix bootstrap consts
didoda Feb 28, 2025
d27d4e1
tests: fix bootstrap consts
didoda Feb 28, 2025
5953608
tests: fix bootstrap
didoda Feb 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ jobs:
cs:
uses: bedita/github-workflows/.github/workflows/php-cs.yml@v2
with:
php_versions: '["8.3"]'
php_versions: '["8.4"]'

stan:
uses: bedita/github-workflows/.github/workflows/php-stan.yml@v2
with:
php_versions: '["8.3"]'
php_versions: '["8.4"]'

unit-5:
uses: bedita/github-workflows/.github/workflows/php-unit.yml@v2
with:
php_versions: '["8.3"]'
php_versions: '["8.3","8.4"]'
bedita_version: '5'
coverage_min_percentage: 99
25 changes: 11 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,21 @@
"require": {
"php": ">=8.3",
"bedita/php-sdk": "^4.1.0",
"cakephp/cakephp": "^4.5",
"cakephp/cakephp": "^5.0",
"firebase/php-jwt": "^6.9",
"cakephp/twig-view": "^1.3.0"
"cakephp/twig-view": "^2"
},
"require-dev": {
"cakephp/authentication": "^2.9",
"cakephp/authorization": "^2.2",
"cakephp/cakephp-codesniffer": "^4.7",
"cakephp/authentication": "^3.0.3",
"cakephp/authorization": "^3.1.2",
"cakephp/cakephp-codesniffer": "^5.0",
"league/oauth2-client": "^2.6",
"josegonzalez/dotenv": "^3.2",
"phpstan/phpstan": "^1.10",
"phpstan/extension-installer": "^1.2",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^1.12",
"phpstan/phpstan-phpunit": "^1.4",
"phpstan/phpstan-deprecation-rules": "^1.2",
"phpunit/phpunit": "^9.6"
},
"suggest": {
"cakephp/authentication": "^2.9 To use \"ApiIdentifier\", \"Identity\", \"IdentityHelper\" and other authentication features",
"cakephp/authorization": "^2.2 To use \"RequestPolicy\" and other authorization features"
"phpunit/phpunit": "^11.1.3"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -67,8 +64,8 @@
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true,
"cakephp/plugin-installer": true
"cakephp/plugin-installer": true,
"phpstan/extension-installer": true
}
}
}
22 changes: 22 additions & 0 deletions config/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* BEdita, API-first content management framework
* Copyright 2018 ChannelWeb Srl, Chialab Srl
Expand All @@ -11,8 +12,29 @@
* See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details.
*/

/*
* Configure paths required to find CakePHP + general filepath constants
*/
require __DIR__ . DIRECTORY_SEPARATOR . 'paths.php';

/*
* Bootstrap CakePHP.
*
* Does the various bits of setup that CakePHP needs to do.
* This includes:
*
* - Registering the CakePHP autoloader.
* - Setting the default application paths.
*/
require CORE_PATH . 'config' . DS . 'bootstrap.php';

use Cake\Core\Configure;

/**
* Load global functions.
*/
require CAKE . 'functions.php';

/**
* Setup API config if missing
*/
Expand Down
66 changes: 66 additions & 0 deletions config/paths.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @since 3.0.0
* @license MIT License (https://opensource.org/licenses/mit-license.php)
*/

/*
* Use the DS to separate the directories in other defines
*/
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}

/*
* These defines should only be edited if you have cake installed in
* a directory layout other than the way it is distributed.
* When using custom settings be sure to use the DS and do not add a trailing DS.
*/

/*
* The full path to the directory which holds "src", WITHOUT a trailing DS.
*/
if (!defined('ROOT')) {
define('ROOT', dirname(__DIR__));
}

/*
* Path to the temporary files directory.
*/
if (!defined('TMP')) {
define('TMP', ROOT . DS . 'tmp' . DS);
}

/*
* Path to the cache files directory. It can be shared between hosts in a multi-server setup.
*/
if (!defined('CACHE')) {
define('CACHE', TMP . 'cache' . DS);
}

/*
* The absolute path to the "cake" directory, WITHOUT a trailing DS.
*
* CakePHP should always be installed with composer, so look there.
*/
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'vendor' . DS . 'cakephp' . DS . 'cakephp');
}

/*
* Path to the cake directory.
*/
if (!defined('CORE_PATH')) {
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
}
if (!defined('CAKE')) {
define('CAKE', CORE_PATH . 'src' . DS);
}
15 changes: 11 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" processIsolation="false" stopOnFailure="false" bootstrap="./tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="./tests/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<source>
<include>
<directory suffix=".php">./src/</directory>
</include>
</coverage>
</source>
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
Expand All @@ -16,6 +23,6 @@
</testsuite>
</testsuites>
<extensions>
<extension class="\Cake\TestSuite\Fixture\PHPUnitExtension"/>
<bootstrap class="\Cake\TestSuite\Fixture\Extension\PHPUnitExtension"/>
</extensions>
</phpunit>
4 changes: 2 additions & 2 deletions src/ApiClientProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class ApiClientProvider
/**
* BEdita API client
*
* @var \BEdita\SDK\BEditaClient
* @var \BEdita\SDK\BEditaClient|null
*/
private $apiClient = null;
private ?BEditaClient $apiClient = null;

/**
* Read singleton API client data.
Expand Down
7 changes: 4 additions & 3 deletions src/Authenticator/OAuth2Authenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Cake\Routing\Router;
use Cake\Utility\Hash;
use Firebase\JWT\JWT;
use League\OAuth2\Client\Provider\AbstractProvider;
use Psr\Http\Message\ServerRequestInterface;

/**
Expand All @@ -37,9 +38,9 @@ class OAuth2Authenticator extends AbstractAuthenticator
/**
* External Auth provider
*
* @var \League\OAuth2\Client\Provider\AbstractProvider
* @var \League\OAuth2\Client\Provider\AbstractProvider|null
*/
protected $provider = null;
protected ?AbstractProvider $provider = null;

/**
* Authentication URL key
Expand All @@ -59,7 +60,7 @@ class OAuth2Authenticator extends AbstractAuthenticator
*
* @var array
*/
protected $_defaultConfig = [
protected array $_defaultConfig = [
'sessionKey' => 'oauth2state',
'redirect' => ['_name' => 'login'],
'providers' => [],
Expand Down
4 changes: 1 addition & 3 deletions src/Command/CacheClearallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Cake\Command\CacheClearallCommand as BaseCommand;
use Cake\Console\Arguments;
use Cake\Console\ConsoleIo;
use Cake\Filesystem\Folder;

/**
* Extend `CacheClearallCommand` to remove Twig compiled files.
Expand All @@ -37,8 +36,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int

return parent::execute($args, $io);
}
$folder = new Folder($path); /* @phpstan-ignore-line */
$folder->delete();
unlink($path);
$io->out('<success>Cleared twig cache</success>');

return parent::execute($args, $io);
Expand Down
28 changes: 16 additions & 12 deletions src/Controller/ApiProxyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
*/
namespace BEdita\WebTools\Controller;

use BEdita\SDK\BEditaClient;
use BEdita\SDK\BEditaClientException;
use BEdita\WebTools\ApiClientProvider;
use Cake\Http\Exception\BadRequestException;
use Cake\Http\Exception\MethodNotAllowedException;
use Cake\Http\Response;
use Cake\Http\ServerRequest;
use Cake\Routing\Router;
use Cake\Utility\Hash;
use Cake\View\ViewVarsTrait;
use Throwable;

/**
* Use this Trait in a controller to directly proxy requests to BE4 API.
Expand All @@ -45,28 +49,28 @@ trait ApiProxyTrait
*
* @var \Cake\Http\ServerRequest
*/
protected $request;
protected ServerRequest $request;

/**
* An instance of a Response object that contains information about the impending response.
*
* @var \Cake\Http\Response
*/
protected $response;
protected Response $response;

/**
* BEdita API client
*
* @var \BEdita\SDK\BEditaClient
* @var \BEdita\SDK\BEditaClient|null
*/
protected $apiClient = null;
protected ?BEditaClient $apiClient = null;

/**
* Base URL used for mask links.
*
* @var string
*/
protected $baseUrl = '';
protected string $baseUrl = '';

/**
* @inheritDoc
Expand All @@ -88,7 +92,7 @@ public function initialize(): void
* @param string $path The path on which build base URL
* @return void
*/
protected function setBaseUrl($path): void
protected function setBaseUrl(string $path): void
{
$requestPath = $this->request->getPath();
$pos = strpos(rawurldecode($requestPath), $path);
Expand All @@ -106,7 +110,7 @@ protected function setBaseUrl($path): void
* @param string $path The path for API request
* @return void
*/
public function get($path = ''): void
public function get(string $path = ''): void
{
$this->apiRequest([
'method' => 'get',
Expand All @@ -121,7 +125,7 @@ public function get($path = ''): void
* @param string $path The path for API request
* @return void
*/
public function post($path = ''): void
public function post(string $path = ''): void
{
$this->apiRequest([
'method' => 'post',
Expand All @@ -136,7 +140,7 @@ public function post($path = ''): void
* @param string $path The path for API request
* @return void
*/
public function patch($path = ''): void
public function patch(string $path = ''): void
{
$this->apiRequest([
'method' => 'patch',
Expand All @@ -151,7 +155,7 @@ public function patch($path = ''): void
* @param string $path The path for API request
* @return void
*/
public function delete($path = ''): void
public function delete(string $path = ''): void
{
$this->apiRequest([
'method' => 'delete',
Expand Down Expand Up @@ -216,7 +220,7 @@ protected function apiRequest(array $options): void
$response = $this->maskResponseLinks($response);
$this->set($response);
$this->viewBuilder()->setOption('serialize', array_keys($response));
} catch (\Throwable $e) {
} catch (Throwable $e) {
$this->handleError($e);
}
}
Expand All @@ -228,7 +232,7 @@ protected function apiRequest(array $options): void
* @param \Throwable $error The error thrown.
* @return void
*/
protected function handleError(\Throwable $error): void
protected function handleError(Throwable $error): void
{
$status = $error->getCode();
if ($status < 100 || $status > 599) {
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Component/ApiCacheComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ApiCacheComponent extends Component
*
* @var array
*/
protected $_defaultConfig = [
protected array $_defaultConfig = [
'cache' => '_apicache_',
];

Expand All @@ -40,7 +40,7 @@ class ApiCacheComponent extends Component
*
* @var array
*/
protected $cacheIndex = [];
protected array $cacheIndex = [];

/**
* Use 'default' as fallback if no cache configuration is found.
Expand Down
Loading
Loading