From 3d5fc14d5e5a66effc9baad2c2a203f65f03c12c Mon Sep 17 00:00:00 2001 From: Yassine Doghri Date: Wed, 15 Nov 2023 16:17:43 +0000 Subject: [PATCH] build: upgrade CI4 + php and js dependencies to latest closes #396 --- .gitignore | 1 + app/Config/Boot/development.php | 2 + app/Config/Boot/production.php | 2 + app/Config/Boot/testing.php | 6 + app/Config/Filters.php | 9 +- app/Config/Migrations.php | 4 +- app/Config/Routes.php | 3 + app/Config/View.php | 10 +- app/Controllers/BaseController.php | 4 +- app/Controllers/EpisodeAudioController.php | 2 +- app/Controllers/PostController.php | 3 +- app/Database/Seeds/PlatformSeeder.php | 2 +- app/Helpers/rss_helper.php | 2 +- app/Libraries/ViewComponents/Component.php | 2 +- .../ViewComponents/ComponentRenderer.php | 2 +- app/Libraries/ViewThemes/Theme.php | 4 +- app/Libraries/Vite/Vite.php | 25 +- app/Models/EpisodeCommentModel.php | 15 +- app/Models/LikeModel.php | 11 +- app/Views/Components/Forms/Select.php | 2 +- app/Views/Components/IconButton.php | 2 +- app/Views/errors/html/error_exception.php | 7 +- composer.json | 18 +- composer.lock | 349 ++- modules/Admin/Controllers/BaseController.php | 2 +- modules/Auth/Config/AuthToken.php | 57 + package.json | 62 +- phpstan.neon | 3 + pnpm-lock.yaml | 2316 ++++++++++------- writable/debugbar/.gitkeep | 0 30 files changed, 1677 insertions(+), 1250 deletions(-) create mode 100644 modules/Auth/Config/AuthToken.php create mode 100644 writable/debugbar/.gitkeep diff --git a/.gitignore b/.gitignore index 75d7aa6e..b76b146f 100644 --- a/.gitignore +++ b/.gitignore @@ -67,6 +67,7 @@ writable/uploads/* !writable/uploads/index.html writable/debugbar/* +!writable/debugbar/.gitkeep php_errors.log diff --git a/app/Config/Boot/development.php b/app/Config/Boot/development.php index 8193a56a..3f6dd938 100644 --- a/app/Config/Boot/development.php +++ b/app/Config/Boot/development.php @@ -9,6 +9,8 @@ declare(strict_types=1); * In development, we want to show as many errors as possible to help * make sure they don't make it to production. And save us hours of * painful debugging. + * + * If you set 'display_errors' to '1', CI4's detailed error report will show. */ error_reporting(-1); ini_set('display_errors', '1'); diff --git a/app/Config/Boot/production.php b/app/Config/Boot/production.php index 4cf210d8..701bf31e 100644 --- a/app/Config/Boot/production.php +++ b/app/Config/Boot/production.php @@ -8,6 +8,8 @@ declare(strict_types=1); * -------------------------------------------------------------------------- * Don't show ANY in production environments. Instead, let the system catch * it and display a generic error message. + * + * If you set 'display_errors' to '1', CI4's detailed error report will show. */ ini_set('display_errors', '0'); error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); diff --git a/app/Config/Boot/testing.php b/app/Config/Boot/testing.php index 56c22a9c..ae8eb6b4 100644 --- a/app/Config/Boot/testing.php +++ b/app/Config/Boot/testing.php @@ -2,6 +2,12 @@ declare(strict_types=1); +/* + * The environment testing is reserved for PHPUnit testing. It has special + * conditions built into the framework at various places to assist with that. + * You can’t use it for your development. + */ + /** * -------------------------------------------------------------------------- * ERROR DISPLAY diff --git a/app/Config/Filters.php b/app/Config/Filters.php index d4bcb168..632aec72 100644 --- a/app/Config/Filters.php +++ b/app/Config/Filters.php @@ -11,8 +11,6 @@ use CodeIgniter\Filters\DebugToolbar; use CodeIgniter\Filters\Honeypot; use CodeIgniter\Filters\InvalidChars; use CodeIgniter\Filters\SecureHeaders; -use Modules\Admin\Config\Admin; -use Modules\Analytics\Config\Analytics; use Modules\Auth\Filters\PermissionFilter; class Filters extends BaseConfig @@ -20,8 +18,9 @@ class Filters extends BaseConfig /** * Configures aliases for Filter classes to make reading things nicer and simpler. * - * @var array - * @phpstan-var array + * @var array|string> [filter_name => classname] + * or [filter_name => [classname1, classname2, ...]] + * @phpstan-var array> */ public array $aliases = [ 'csrf' => CSRF::class, @@ -80,7 +79,7 @@ class Filters extends BaseConfig $this->filters = [ 'session' => [ - 'before' => [config(Admin::class)->gateway . '*', config(Analytics::class)->gateway . '*'], + 'before' => [config('Admin')->gateway . '*', config('Analytics')->gateway . '*'], ], 'podcast-unlock' => [ 'before' => ['*@*/episodes/*'], diff --git a/app/Config/Migrations.php b/app/Config/Migrations.php index d4e7731b..c30ad993 100644 --- a/app/Config/Migrations.php +++ b/app/Config/Migrations.php @@ -27,9 +27,7 @@ class Migrations extends BaseConfig * * This is the name of the table that will store the current migrations state. * When migrations runs it will store in a database table which migration - * level the system is at. It then compares the migration level in this - * table to the $config['migration_version'] if they are not the same it - * will migrate up. This must be set. + * files have already been run. */ public string $table = 'migrations'; diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 6339fad3..f9e06943 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -49,6 +49,9 @@ $routes->get('/', 'HomeController', [ $routes->get('.well-known/platforms', 'Platform'); +service('auth') + ->routes($routes); + // Podcast's Public routes $routes->group('@(:podcastHandle)', static function ($routes): void { // override default Fediverse Library's actor route diff --git a/app/Config/View.php b/app/Config/View.php index ae4d7475..e69d19b0 100644 --- a/app/Config/View.php +++ b/app/Config/View.php @@ -8,6 +8,10 @@ use CodeIgniter\Config\View as BaseView; use CodeIgniter\View\ViewDecoratorInterface; use ViewComponents\Decorator; +/** + * @phpstan-type ParserCallable (callable(mixed): mixed) + * @phpstan-type ParserCallableString (callable(mixed): mixed)&string + */ class View extends BaseView { /** @@ -28,7 +32,7 @@ class View extends BaseView * Examples: { title|esc(js) } { created_on|date(Y-m-d)|esc(attr) } * * @var array - * @phpstan-var array + * @phpstan-var array */ public $filters = []; @@ -36,8 +40,8 @@ class View extends BaseView * Parser Plugins provide a way to extend the functionality provided by the core Parser by creating aliases that * will be replaced with any callable. Can be single or tag pair. * - * @var array - * @phpstan-var array + * @var array|callable|string> + * @phpstan-var array|ParserCallableString|ParserCallable> */ public $plugins = []; diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php index 7bfc7c21..6c87b000 100644 --- a/app/Controllers/BaseController.php +++ b/app/Controllers/BaseController.php @@ -59,13 +59,13 @@ abstract class BaseController extends Controller ResponseInterface $response, LoggerInterface $logger ): void { - $this->helpers = array_merge($this->helpers, ['auth', 'svg', 'components', 'misc', 'seo', 'premium_podcasts']); + $this->helpers = [...$this->helpers, 'auth', 'svg', 'components', 'misc', 'seo', 'premium_podcasts']; // Do Not Edit This Line parent::initController($request, $response, $logger); Theme::setTheme('app'); - $this->helpers = array_merge($this->helpers, ['setting']); + $this->helpers = [...$this->helpers, 'setting']; } } diff --git a/app/Controllers/EpisodeAudioController.php b/app/Controllers/EpisodeAudioController.php index d65294ac..fbf66d76 100644 --- a/app/Controllers/EpisodeAudioController.php +++ b/app/Controllers/EpisodeAudioController.php @@ -64,7 +64,7 @@ class EpisodeAudioController extends Controller set_user_session_location(); set_user_session_player(); - $this->analyticsConfig = config(Analytics::class); + $this->analyticsConfig = config('Analytics'); } public function _remap(string $method, string ...$params): mixed diff --git a/app/Controllers/PostController.php b/app/Controllers/PostController.php index 23d68882..7e0ea87e 100644 --- a/app/Controllers/PostController.php +++ b/app/Controllers/PostController.php @@ -22,7 +22,6 @@ use CodeIgniter\HTTP\URI; use CodeIgniter\I18n\Time; use Modules\Analytics\AnalyticsTrait; use Modules\Fediverse\Controllers\PostController as FediversePostController; -use Modules\Fediverse\Models\FavouriteModel; class PostController extends FediversePostController { @@ -203,7 +202,7 @@ class PostController extends FediversePostController public function attemptFavourite(): RedirectResponse { - model(FavouriteModel::class)->toggleFavourite(interact_as_actor(), $this->post); + model('FavouriteModel')->toggleFavourite(interact_as_actor(), $this->post); return redirect()->back(); } diff --git a/app/Database/Seeds/PlatformSeeder.php b/app/Database/Seeds/PlatformSeeder.php index 0fb5ab0d..00b2b000 100644 --- a/app/Database/Seeds/PlatformSeeder.php +++ b/app/Database/Seeds/PlatformSeeder.php @@ -622,7 +622,7 @@ class PlatformSeeder extends Seeder ], ]; - $data = array_merge($podcastingData, $fundingData, $socialData); + $data = [...$podcastingData, ...$fundingData, ...$socialData]; $this->db ->table('platforms') ->ignore(true) diff --git a/app/Helpers/rss_helper.php b/app/Helpers/rss_helper.php index 4b0d187c..cde17a2d 100644 --- a/app/Helpers/rss_helper.php +++ b/app/Helpers/rss_helper.php @@ -52,7 +52,7 @@ if (! function_exists('get_rss_feed')) { $atomLink->addAttribute('type', 'application/rss+xml'); // websub: add links to hubs defined in config - $websubHubs = config(WebSub::class) + $websubHubs = config('WebSub') ->hubs; foreach ($websubHubs as $websubHub) { $atomLinkHub = $channel->addChild('link', null, $atomNamespace); diff --git a/app/Libraries/ViewComponents/Component.php b/app/Libraries/ViewComponents/Component.php index 47dc2625..b86e4a85 100644 --- a/app/Libraries/ViewComponents/Component.php +++ b/app/Libraries/ViewComponents/Component.php @@ -25,7 +25,7 @@ class Component implements ComponentInterface helper('viewcomponents'); // overwrite default attributes if set - $this->attributes = array_merge($this->attributes, $attributes); + $this->attributes = [...$this->attributes, ...$attributes]; if ($attributes !== []) { $this->hydrate($attributes); diff --git a/app/Libraries/ViewComponents/ComponentRenderer.php b/app/Libraries/ViewComponents/ComponentRenderer.php index 79e1987b..f9e916c0 100644 --- a/app/Libraries/ViewComponents/ComponentRenderer.php +++ b/app/Libraries/ViewComponents/ComponentRenderer.php @@ -16,7 +16,7 @@ class ComponentRenderer public function __construct() { - $this->config = config(ViewComponents::class); + $this->config = config('ViewComponents'); } public function render(string $output): string diff --git a/app/Libraries/ViewThemes/Theme.php b/app/Libraries/ViewThemes/Theme.php index f3d94796..30020dcb 100644 --- a/app/Libraries/ViewThemes/Theme.php +++ b/app/Libraries/ViewThemes/Theme.php @@ -32,7 +32,7 @@ class Theme public function __construct() { - $this->config = config(Themes::class); + $this->config = config('Themes'); } /** @@ -85,7 +85,7 @@ class Theme { $themes = []; - $config = config(Themes::class); + $config = config('Themes'); foreach ($config->themes as $name => $folder) { $themes[] = [ diff --git a/app/Libraries/Vite/Vite.php b/app/Libraries/Vite/Vite.php index b0dea4ec..4ff6fa6e 100644 --- a/app/Libraries/Vite/Vite.php +++ b/app/Libraries/Vite/Vite.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Vite; use ErrorException; -use Vite\Config\Vite as ViteConfig; class Vite { @@ -21,7 +20,7 @@ class Vite public function asset(string $path, string $type): string { - if (config(ViteConfig::class)->environment !== 'production') { + if (config('Vite')->environment !== 'production') { return $this->loadDev($path, $type); } @@ -30,10 +29,7 @@ class Vite private function loadDev(string $path, string $type): string { - return $this->getHtmlTag( - config(ViteConfig::class)->baseUrl . config(ViteConfig::class)->assetsRoot . "/{$path}", - $type - ); + return $this->getHtmlTag(config('Vite') ->baseUrl . config('Vite')->assetsRoot . "/{$path}", $type); } private function loadProd(string $path, string $type): string @@ -41,8 +37,8 @@ class Vite if ($this->manifestData === null) { $cacheName = 'vite-manifest'; if (! ($cachedManifest = cache($cacheName))) { - $manifestPath = config(ViteConfig::class) - ->assetsRoot . '/' . config(ViteConfig::class) + $manifestPath = config('Vite') + ->assetsRoot . '/' . config('Vite') ->manifestFile; try { if (($manifestContents = file_get_contents($manifestPath)) !== false) { @@ -66,7 +62,7 @@ class Vite // import css dependencies if any if (array_key_exists('css', $manifestElement)) { foreach ($manifestElement['css'] as $cssFile) { - $html .= $this->getHtmlTag('/' . config(ViteConfig::class)->assetsRoot . '/' . $cssFile, 'css'); + $html .= $this->getHtmlTag('/' . config('Vite')->assetsRoot . '/' . $cssFile, 'css'); } } @@ -78,26 +74,21 @@ class Vite if (array_key_exists('css', $this->manifestData[$importPath])) { foreach ($this->manifestData[$importPath]['css'] as $cssFile) { $html .= $this->getHtmlTag( - '/' . config(ViteConfig::class)->assetsRoot . '/' . $cssFile, + '/' . config('Vite')->assetsRoot . '/' . $cssFile, 'css' ); } } $html .= $this->getHtmlTag( - '/' . config( - ViteConfig::class - )->assetsRoot . '/' . $this->manifestData[$importPath]['file'], + '/' . config('Vite')->assetsRoot . '/' . $this->manifestData[$importPath]['file'], 'js' ); } } } - $html .= $this->getHtmlTag( - '/' . config(ViteConfig::class)->assetsRoot . '/' . $manifestElement['file'], - $type - ); + $html .= $this->getHtmlTag('/' . config('Vite')->assetsRoot . '/' . $manifestElement['file'], $type); } return $html; diff --git a/app/Models/EpisodeCommentModel.php b/app/Models/EpisodeCommentModel.php index bbceb48f..beefbd53 100644 --- a/app/Models/EpisodeCommentModel.php +++ b/app/Models/EpisodeCommentModel.php @@ -20,7 +20,6 @@ use CodeIgniter\I18n\Time; use Michalsn\Uuid\UuidModel; use Modules\Fediverse\Activities\CreateActivity; use Modules\Fediverse\Activities\DeleteActivity; -use Modules\Fediverse\Models\ActivityModel; use Modules\Fediverse\Objects\TombstoneObject; class EpisodeCommentModel extends UuidModel @@ -111,7 +110,7 @@ class EpisodeCommentModel extends UuidModel ->set('actor', $comment->actor->uri) ->set('object', new CommentObject($comment)); - $activityId = model(ActivityModel::class, false) + $activityId = model('ActivityModel', false) ->newActivity( 'Create', $comment->actor_id, @@ -124,7 +123,7 @@ class EpisodeCommentModel extends UuidModel $createActivity->set('id', url_to('activity', esc($comment->actor->username), $activityId)); - model(ActivityModel::class, false) + model('ActivityModel', false) ->update($activityId, [ 'payload' => $createActivity->toJSON(), ]); @@ -154,7 +153,7 @@ class EpisodeCommentModel extends UuidModel ->set('actor', $comment->actor->uri) ->set('object', $tombstoneObject); - $activityId = model(ActivityModel::class, false) + $activityId = model('ActivityModel', false) ->newActivity( 'Delete', $comment->actor_id, @@ -167,7 +166,7 @@ class EpisodeCommentModel extends UuidModel $deleteActivity->set('id', url_to('activity', esc($comment->actor->username), $activityId)); - model(ActivityModel::class, false) + model('ActivityModel', false) ->update($activityId, [ 'payload' => $deleteActivity->toJSON(), ]); @@ -177,7 +176,7 @@ class EpisodeCommentModel extends UuidModel ->delete($comment->id); if ($comment->in_reply_to_id === null) { - model(EpisodeModel::class, false)->builder() + model('EpisodeModel', false)->builder() ->where('id', $comment->episode_id) ->decrement('comments_count'); } else { @@ -294,9 +293,9 @@ class EpisodeCommentModel extends UuidModel $data['data']['id'] = $uuid4->toString(); if (! isset($data['data']['uri'])) { - $actor = model(ActorModel::class, false) + $actor = model('ActorModel', false) ->getActorById((int) $data['data']['actor_id']); - $episode = model(EpisodeModel::class, false) + $episode = model('EpisodeModel', false) ->find((int) $data['data']['episode_id']); if (! $episode instanceof Episode) { diff --git a/app/Models/LikeModel.php b/app/Models/LikeModel.php index b0b222ff..b7929684 100644 --- a/app/Models/LikeModel.php +++ b/app/Models/LikeModel.php @@ -17,7 +17,6 @@ use Modules\Fediverse\Activities\LikeActivity; use Modules\Fediverse\Activities\UndoActivity; use Modules\Fediverse\Entities\Activity; use Modules\Fediverse\Entities\Actor; -use Modules\Fediverse\Models\ActivityModel; class LikeModel extends UuidModel { @@ -66,7 +65,7 @@ class LikeModel extends UuidModel $likeActivity->set('actor', $actor->uri) ->set('object', $comment->uri); - $activityId = model(ActivityModel::class) + $activityId = model('ActivityModel') ->newActivity( 'Like', $actor->id, @@ -79,7 +78,7 @@ class LikeModel extends UuidModel $likeActivity->set('id', url_to('activity', esc($actor->username), $activityId)); - model(ActivityModel::class) + model('ActivityModel') ->update($activityId, [ 'payload' => $likeActivity->toJSON(), ]); @@ -107,7 +106,7 @@ class LikeModel extends UuidModel if ($registerActivity) { $undoActivity = new UndoActivity(); // FIXME: get like activity associated with the deleted like - $activity = model(ActivityModel::class) + $activity = model('ActivityModel') ->where([ 'type' => 'Like', 'actor_id' => $actor->id, @@ -129,7 +128,7 @@ class LikeModel extends UuidModel ->set('actor', $actor->uri) ->set('object', $likeActivity); - $activityId = model(ActivityModel::class) + $activityId = model('ActivityModel') ->newActivity( 'Undo', $actor->id, @@ -142,7 +141,7 @@ class LikeModel extends UuidModel $undoActivity->set('id', url_to('activity', esc($actor->username), $activityId)); - model(ActivityModel::class) + model('ActivityModel') ->update($activityId, [ 'payload' => $undoActivity->toJSON(), ]); diff --git a/app/Views/Components/Forms/Select.php b/app/Views/Components/Forms/Select.php index 0740beef..8f112c90 100644 --- a/app/Views/Components/Forms/Select.php +++ b/app/Views/Components/Forms/Select.php @@ -32,7 +32,7 @@ class Select extends FormComponent unset($this->attributes['name']); unset($this->attributes['options']); unset($this->attributes['selected']); - $extra = array_merge($this->attributes, $defaultAttributes); + $extra = [...$this->attributes, ...$defaultAttributes]; return form_dropdown($this->name, $this->options, old($this->name, $this->selected !== '' ? [$this->selected] : []), $extra); } diff --git a/app/Views/Components/IconButton.php b/app/Views/Components/IconButton.php index fc6bc318..57afa1a4 100644 --- a/app/Views/Components/IconButton.php +++ b/app/Views/Components/IconButton.php @@ -22,7 +22,7 @@ class IconButton extends Button 'large' => 'text-2xl', ]; - $allAttributes = array_merge($attributes, $iconButtonAttributes); + $allAttributes = [...$attributes, ...$iconButtonAttributes]; parent::__construct($allAttributes); diff --git a/app/Views/errors/html/error_exception.php b/app/Views/errors/html/error_exception.php index a50dfe81..6f9383a3 100644 --- a/app/Views/errors/html/error_exception.php +++ b/app/Views/errors/html/error_exception.php @@ -47,6 +47,7 @@ $errorId = uniqid('error', true); +
    @@ -69,7 +70,7 @@ $errorId = uniqid('error', true);
  • - + setStatusCode(http_response_code());

+