mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Partial migration to singletons for static resources
This commit is contained in:
parent
fc091659ed
commit
23b7c6667e
@ -378,15 +378,16 @@ class Client extends BaseModel implements HasLocalePreference
|
|||||||
|
|
||||||
public function language()
|
public function language()
|
||||||
{
|
{
|
||||||
$languages = Cache::get('languages');
|
$languages = app('languages');
|
||||||
|
// $languages = Cache::get('languages');
|
||||||
|
|
||||||
if (! $languages) {
|
// if (! $languages) {
|
||||||
$this->buildCache(true);
|
// $this->buildCache(true);
|
||||||
}
|
// }
|
||||||
|
|
||||||
return $languages->filter(function ($item) {
|
return $languages->first(function ($item) {
|
||||||
return $item->id == $this->getSetting('language_id');
|
return $item->id == $this->getSetting('language_id');
|
||||||
})->first();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function industry(): BelongsTo
|
public function industry(): BelongsTo
|
||||||
@ -410,28 +411,30 @@ class Client extends BaseModel implements HasLocalePreference
|
|||||||
|
|
||||||
public function date_format()
|
public function date_format()
|
||||||
{
|
{
|
||||||
$date_formats = Cache::get('date_formats');
|
$date_formats = app('date_formts');
|
||||||
|
// $date_formats = Cache::get('date_formats');
|
||||||
|
|
||||||
if (! $date_formats) {
|
// if (! $date_formats) {
|
||||||
$this->buildCache(true);
|
// $this->buildCache(true);
|
||||||
}
|
// }
|
||||||
|
|
||||||
return $date_formats->filter(function ($item) {
|
return $date_formats->first(function ($item) {
|
||||||
return $item->id == $this->getSetting('date_format_id');
|
return $item->id == $this->getSetting('date_format_id');
|
||||||
})->first()->format;
|
})->format;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function currency()
|
public function currency()
|
||||||
{
|
{
|
||||||
$currencies = Cache::get('currencies');
|
$currencies = app('currencies');
|
||||||
|
// $currencies = Cache::get('currencies');
|
||||||
|
|
||||||
if (! $currencies) {
|
// if (! $currencies) {
|
||||||
$this->buildCache(true);
|
// $this->buildCache(true);
|
||||||
}
|
// }
|
||||||
|
|
||||||
return $currencies->filter(function ($item) {
|
return $currencies->first(function ($item) {
|
||||||
return $item->id == $this->getSetting('currency_id');
|
return $item->id == $this->getSetting('currency_id');
|
||||||
})->first();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function service(): ClientService
|
public function service(): ClientService
|
||||||
@ -739,15 +742,17 @@ class Client extends BaseModel implements HasLocalePreference
|
|||||||
|
|
||||||
public function preferredLocale()
|
public function preferredLocale()
|
||||||
{
|
{
|
||||||
$languages = Cache::get('languages');
|
$this->language()->locale ?? 'en';
|
||||||
|
// $languages = app('languages');
|
||||||
|
// $languages = Cache::get('languages');
|
||||||
|
|
||||||
if (! $languages) {
|
// if (! $languages) {
|
||||||
$this->buildCache(true);
|
// $this->buildCache(true);
|
||||||
}
|
// }
|
||||||
|
|
||||||
return $languages->filter(function ($item) {
|
// return $languages->first(function ($item) {
|
||||||
return $item->id == $this->getSetting('language_id');
|
// return $item->id == $this->getSetting('language_id');
|
||||||
})->first()->locale;
|
// })->locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function backup_path(): string
|
public function backup_path(): string
|
||||||
|
@ -12,10 +12,14 @@
|
|||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use App\Models\Bank;
|
use App\Models\Bank;
|
||||||
|
use App\Models\Size;
|
||||||
use App\Models\Country;
|
use App\Models\Country;
|
||||||
|
use App\Models\Gateway;
|
||||||
use App\Models\Currency;
|
use App\Models\Currency;
|
||||||
use App\Models\Industry;
|
use App\Models\Industry;
|
||||||
use App\Models\Language;
|
use App\Models\Language;
|
||||||
|
use App\Models\Timezone;
|
||||||
|
use App\Models\DateFormat;
|
||||||
use App\Models\PaymentTerm;
|
use App\Models\PaymentTerm;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use App\DataMapper\EmailTemplateDefaults;
|
use App\DataMapper\EmailTemplateDefaults;
|
||||||
@ -30,6 +34,7 @@ class StaticServiceProvider extends ServiceProvider
|
|||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
app()->singleton('currencies', function ($app) {
|
app()->singleton('currencies', function ($app) {
|
||||||
return Currency::query()->orderBy('name')->get();
|
return Currency::query()->orderBy('name')->get();
|
||||||
});
|
});
|
||||||
@ -54,6 +59,31 @@ class StaticServiceProvider extends ServiceProvider
|
|||||||
return Bank::query()->orderBy('name')->get();
|
return Bank::query()->orderBy('name')->get();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app()->singleton('date_formats', function ($app) {
|
||||||
|
return DateFormat::query()->orderBy('id')->get();
|
||||||
|
});
|
||||||
|
|
||||||
|
app()->singleton('timezones', function ($app) {
|
||||||
|
return Timezone::query()->orderBy('id')->get();
|
||||||
|
});
|
||||||
|
|
||||||
|
app()->singleton('gateways', function ($app) {
|
||||||
|
return Gateway::query()->orderBy('id')->get();
|
||||||
|
});
|
||||||
|
|
||||||
|
app()->singleton('industries', function ($app) {
|
||||||
|
return Industry::query()->orderBy('id')->get();
|
||||||
|
});
|
||||||
|
|
||||||
|
app()->singleton('sizes', function ($app) {
|
||||||
|
return Size::query()->orderBy('id')->get();
|
||||||
|
});
|
||||||
|
|
||||||
|
/** @deprecated */
|
||||||
|
app()->singleton('banks', function ($app) {
|
||||||
|
return Bank::query()->orderBy('id')->get();
|
||||||
|
});
|
||||||
|
|
||||||
app()->singleton('templates', function ($app) {
|
app()->singleton('templates', function ($app) {
|
||||||
return [
|
return [
|
||||||
'invoice' => [
|
'invoice' => [
|
||||||
@ -91,6 +121,7 @@ class StaticServiceProvider extends ServiceProvider
|
|||||||
];
|
];
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function boot()
|
public function boot()
|
||||||
|
@ -201,7 +201,7 @@ return [
|
|||||||
App\Providers\MultiDBProvider::class,
|
App\Providers\MultiDBProvider::class,
|
||||||
App\Providers\ClientPortalServiceProvider::class,
|
App\Providers\ClientPortalServiceProvider::class,
|
||||||
App\Providers\NinjaTranslationServiceProvider::class,
|
App\Providers\NinjaTranslationServiceProvider::class,
|
||||||
// App\Providers\StaticServiceProvider::class,
|
App\Providers\StaticServiceProvider::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -216,8 +216,8 @@ return [
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
'aliases' => Facade::defaultAliases()->merge([
|
'aliases' => Facade::defaultAliases()->merge([
|
||||||
'Collector' => Turbo124\Collector\CollectorFacade::class,
|
'Collector' => Turbo124\Beacon\CollectorFacade::class,
|
||||||
'Countries' => 'Webpatser\Countries\CountriesFacade',
|
// 'Countries' => 'Webpatser\Countries\CountriesFacade',
|
||||||
'CustomMessage' => App\Utils\ClientPortal\CustomMessage\CustomMessageFacade::class,
|
'CustomMessage' => App\Utils\ClientPortal\CustomMessage\CustomMessageFacade::class,
|
||||||
'Redis' => Illuminate\Support\Facades\Redis::class,
|
'Redis' => Illuminate\Support\Facades\Redis::class,
|
||||||
])->toArray(),
|
])->toArray(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user