A free open source IT asset/license management system
Map app singletons to new FileStorage
snipe0024330d41fd
diff --git a/app/Providers/SettingsServiceProvider.php b/app/Providers/SettingsServiceProvider.phpindex a0e79490e5..0e4707b90f 100644--- a/app/Providers/SettingsServiceProvider.php+++ b/app/Providers/SettingsServiceProvider.php@@ -2,206 +2,101 @@namespace App\Providers;+use App\Enums\FileStorage;use App\Models\Setting;use Illuminate\Support\ServiceProvider;/**- * This service provider handles sharing the snipeSettings variable, and sets- * some common upload path and image urls.+ * This service provider shares `$snipeSettings` with every view and+ * registers legacy `{resource}_upload_path` / `{resource}_upload_url`+ * singletons that Blade templates and a handful of callers resolve via+ * `app('users_upload_path')` and similar.*- * PHP version 5.5.9- *- * @version v3.0+ * The directory values are now sourced from `FileStorage` so there+ * is one authoritative map, and the previous duplicate binding of+ * `accessories_upload_path` (defined twice with conflicting values+ * before the migration) is naturally gone.*/class SettingsServiceProvider extends ServiceProvider{- /**- * Custom email array validation- *- * @author [A. Gianotto] [<[email protected]>]- *- * @since [v3.0]- *- * @return void- */public function boot(){-// Share common setting variables with all views.view()->composer('*', function ($view) {$view->with('snipeSettings', Setting::getSettings());$view->with('settings', Setting::getSettings());});- /**- * Set some common variables so that they're globally available.- * The paths should always be public (versus private uploads)- */-- // Model paths and URLs-- app()->singleton('eula_pdf_path', function () {- return 'eula_pdf_path/';- });-- app()->singleton('assets_upload_path', function () {- return 'assets/';- });-- app()->singleton('maintenances_path', function () {- return 'maintenances/';- });-- app()->singleton('audits_upload_path', function () {- return 'audits/';- });-- app()->singleton('accessories_upload_path', function () {- return 'public/uploads/accessories/';- });-- app()->singleton('models_upload_path', function () {- return 'models/';- });-- app()->singleton('models_upload_url', function () {- return 'models/';- });-- app()->singleton('assets_upload_url', function () {- return 'assets/';- });-- app()->singleton('licenses_upload_url', function () {- return 'licenses/';- });-- // Categories- app()->singleton('categories_upload_path', function () {- return 'categories/';- });-- app()->singleton('categories_upload_url', function () {- return 'categories/';- });-- // Locations- app()->singleton('locations_upload_path', function () {- return 'locations/';- });-- app()->singleton('locations_upload_url', function () {- return 'locations/';- });-- // Companies- app()->singleton('companies_upload_path', function () {- return 'companies/';- });-- app()->singleton('companies_upload_url', function () {- return 'companies/';- });-- // Departments- app()->singleton('departments_upload_path', function () {- return 'departments/';- });-- app()->singleton('departments_upload_url', function () {- return 'departments/';- });-- // Users- app()->singleton('users_upload_path', function () {- return 'avatars/';- });-- app()->singleton('users_upload_url', function () {- return 'users/';- });-- // Manufacturers- app()->singleton('manufacturers_upload_path', function () {- return 'manufacturers/';- });-- app()->singleton('manufacturers_upload_url', function () {- return 'manufacturers/';- });-- // Suppliers- app()->singleton('suppliers_upload_path', function () {- return 'suppliers/';- });-- app()->singleton('suppliers_upload_url', function () {- return 'suppliers/';- });-- // Departments- app()->singleton('departments_upload_path', function () {- return 'departments/';- });-- app()->singleton('departments_upload_url', function () {- return 'departments/';- });-- // Company paths and URLs- app()->singleton('companies_upload_path', function () {- return 'companies/';- });-- app()->singleton('companies_upload_url', function () {- return 'companies/';- });-- // Accessories paths and URLs- app()->singleton('accessories_upload_path', function () {- return 'accessories/';- });-- app()->singleton('accessories_upload_url', function () {- return 'accessories/';- });-- // Consumables paths and URLs- app()->singleton('consumables_upload_path', function () {- return 'consumables/';- });-- app()->singleton('consumables_upload_url', function () {- return 'consumables/';- });-- // Components paths and URLs- app()->singleton('components_upload_path', function () {- return 'components/';- });-- app()->singleton('components_upload_url', function () {- return 'components/';- });-- app()->singleton('maintenances_upload_url', function () {- return 'maintenances/';- });-- app()->singleton('maintenances_upload_path', function () {- return 'maintenances/';- });+ // Legacy upload-path singletons, now derived from FileStorage.+ // Keep the `{resource}_upload_path` singleton name shape because+ // call sites across Blade and a few controllers resolve them by+ // string key. New callers should reach for `FileStorage` cases+ // directly rather than adding more legacy keys here.+ $publicPathMap = [+ 'accessories_upload_path' => FileStorage::Accessories,+ 'assets_upload_path' => FileStorage::Assets,+ 'audits_upload_path' => FileStorage::Audits,+ 'categories_upload_path' => FileStorage::Categories,+ 'companies_upload_path' => FileStorage::Companies,+ 'components_upload_path' => FileStorage::Components,+ 'consumables_upload_path' => FileStorage::Consumables,+ 'departments_upload_path' => FileStorage::Departments,+ 'locations_upload_path' => FileStorage::Locations,+ 'maintenances_upload_path' => FileStorage::Maintenances,+ 'manufacturers_upload_path' => FileStorage::Manufacturers,+ 'models_upload_path' => FileStorage::Models,+ 'suppliers_upload_path' => FileStorage::Suppliers,+ // The user's own avatar directory is historically named+ // `avatars/`, not `users/`, so this singleton points at the+ // Avatars case rather than Users. `users_upload_url` (below)+ // keeps the legacy `users/` value for the handful of Blade+ // call sites that pre-date the enum.+ 'users_upload_path' => FileStorage::Avatars,+ ];+ foreach ($publicPathMap as $key => $case) {+ app()->singleton($key, fn () => $case->publicPath());+ }++ // Legacy `_upload_url` singletons. These historically used the+ // same subdir name as the path for everything except users,+ // which pointed at the URL segment `users/` rather than the+ // storage dir `avatars/`. Audits does not appear in the url+ // map because audits is a private-only resource (eula-pdfs is+ // the companion exclusion). Everything else mirrors publicPath.+ $publicUrlMap = [+ 'accessories_upload_url' => FileStorage::Accessories,+ 'assets_upload_url' => FileStorage::Assets,+ 'categories_upload_url' => FileStorage::Categories,+ 'companies_upload_url' => FileStorage::Companies,+ 'components_upload_url' => FileStorage::Components,+ 'consumables_upload_url' => FileStorage::Consumables,+ 'departments_upload_url' => FileStorage::Departments,+ 'licenses_upload_url' => FileStorage::Licenses,+ 'locations_upload_url' => FileStorage::Locations,+ 'maintenances_upload_url' => FileStorage::Maintenances,+ 'manufacturers_upload_url' => FileStorage::Manufacturers,+ 'models_upload_url' => FileStorage::Models,+ 'suppliers_upload_url' => FileStorage::Suppliers,+ ];+ foreach ($publicUrlMap as $key => $case) {+ app()->singleton($key, fn () => $case->value.'/');+ }++ // Users URL is the one historical outlier - it's the URL+ // segment `users/`, not the storage path `avatars/`.+ app()->singleton('users_upload_url', fn () => 'users/');++ // Legacy standalone singletons that don't fit the resource map.+ app()->singleton('eula_pdf_path', fn () => 'eula_pdf_path/');++ // Legacy short-form alias. `resources/views/maintenances/edit.blade.php`+ // resolves this instead of the `maintenances_upload_path` long form.+ app()->singleton('maintenances_path', fn () => FileStorage::Maintenances->publicPath());// Set the monetary locale to the configured locale to make helper::parseFloat work.setlocale(LC_MONETARY, config('app.locale'));setlocale(LC_NUMERIC, config('app.locale'));-}- /**- * Register any application services.- *- * @return void- */public function register() {}}