From 762afbcc9a8fc1fa1f9d8ab4233063507998df6e Mon Sep 17 00:00:00 2001 From: Liam Hammett Date: Sat, 15 Mar 2025 17:23:26 +0000 Subject: [PATCH 1/3] Autoload new bootstrap/helpers.php file and add user() helper function --- bootstrap/helpers.php | 22 ++++++++++++++++++++++ composer.json | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 bootstrap/helpers.php diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php new file mode 100644 index 00000000000..11340bba4e0 --- /dev/null +++ b/bootstrap/helpers.php @@ -0,0 +1,22 @@ +user(); + + if ($currentUser === null) { + throw new Exception('The current user is not authenticated.'); + } + + if (!$currentUser instanceof User) { + throw new Exception('The currently authenticated user is not an instance of ' . User::class); + } + + return $currentUser; +} diff --git a/composer.json b/composer.json index 9c446ae87e7..a00d96fdfab 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ "App\\": "app/", "Database\\Factories\\": "database/factories/", "Database\\Seeders\\": "database/seeders/" - } + }, + "files": ["bootstrap/helpers.php"] }, "autoload-dev": { "psr-4": { From a0a93a98d6419d43549aa41cae4d5fc4f99141ab Mon Sep 17 00:00:00 2001 From: Liam Hammett Date: Sat, 15 Mar 2025 23:30:59 +0000 Subject: [PATCH 2/3] Style fixes --- bootstrap/helpers.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php index 11340bba4e0..a1a903c8c76 100644 --- a/bootstrap/helpers.php +++ b/bootstrap/helpers.php @@ -14,8 +14,8 @@ function user(): User throw new Exception('The current user is not authenticated.'); } - if (!$currentUser instanceof User) { - throw new Exception('The currently authenticated user is not an instance of ' . User::class); + if (! $currentUser instanceof User) { + throw new Exception('The currently authenticated user is not an instance of '.User::class); } return $currentUser; From 87c9a90e86d3c78546fc4a5f46db21d7f6848af4 Mon Sep 17 00:00:00 2001 From: Liam Hammett Date: Tue, 18 Mar 2025 10:11:46 +0000 Subject: [PATCH 3/3] Remove unused namespace --- bootstrap/helpers.php | 1 - 1 file changed, 1 deletion(-) diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php index a1a903c8c76..ffdc56f9b53 100644 --- a/bootstrap/helpers.php +++ b/bootstrap/helpers.php @@ -1,7 +1,6 @@