Akaunting/app/Utilities/Info.php

88 lines
2.2 KiB
PHP
Raw Normal View History

2017-09-14 19:21:00 +00:00
<?php
namespace App\Utilities;
2018-06-09 23:48:51 +00:00
use App\Models\Common\Company;
2022-09-21 21:57:54 +00:00
use App\Models\Common\Contact;
use App\Models\Document\Document;
2023-05-06 13:34:49 +00:00
use App\Traits\Cloud;
2021-12-24 15:44:10 +00:00
use Composer\InstalledVersions;
2022-09-21 21:57:54 +00:00
use Illuminate\Support\Facades\DB;
2017-09-14 19:21:00 +00:00
class Info
{
2019-12-18 12:29:59 +00:00
public static function all()
2017-09-14 19:21:00 +00:00
{
2023-05-05 21:24:18 +00:00
static $info = [];
2023-10-03 08:06:08 +00:00
if (! empty($info) || request()->isCloudHost()) {
2023-05-05 21:24:18 +00:00
return $info;
}
$info = array_merge(static::versions(), [
2019-12-18 12:29:59 +00:00
'api_key' => setting('apps.api_key'),
2022-09-21 21:57:54 +00:00
'ip' => static::ip(),
2020-03-03 13:09:05 +00:00
'companies' => Company::count(),
2023-10-03 08:06:08 +00:00
'users' => user_model_class()::count(),
'invoices' => Document::allCompanies()->invoice()->count(),
'customers' => Contact::allCompanies()->customer()->count(),
2020-05-19 12:48:24 +00:00
'php_extensions' => static::phpExtensions(),
2019-12-18 12:29:59 +00:00
]);
2023-05-05 21:24:18 +00:00
return $info;
2017-09-14 19:21:00 +00:00
}
2019-12-18 12:29:59 +00:00
public static function versions()
2017-09-14 19:21:00 +00:00
{
2023-05-05 21:24:18 +00:00
static $versions = [];
if (! empty($versions)) {
return $versions;
}
$versions = [
2019-12-18 12:29:59 +00:00
'akaunting' => version('short'),
2022-09-21 21:57:54 +00:00
'laravel' => InstalledVersions::getPrettyVersion('laravel/framework'),
2019-12-18 12:29:59 +00:00
'php' => static::phpVersion(),
'mysql' => static::mysqlVersion(),
2022-09-21 21:57:54 +00:00
'guzzle' => InstalledVersions::getPrettyVersion('guzzlehttp/guzzle'),
2021-12-24 15:44:10 +00:00
'livewire' => InstalledVersions::getPrettyVersion('livewire/livewire'),
2022-09-21 21:57:54 +00:00
'omnipay' => InstalledVersions::getPrettyVersion('league/omnipay'),
2019-12-18 12:29:59 +00:00
];
2023-05-05 21:24:18 +00:00
return $versions;
2017-09-14 19:21:00 +00:00
}
public static function phpVersion()
{
return phpversion();
}
2020-03-03 13:09:05 +00:00
2020-05-19 12:48:24 +00:00
public static function phpExtensions()
{
return get_loaded_extensions();
}
2017-09-14 19:21:00 +00:00
public static function mysqlVersion()
{
2020-05-19 12:48:24 +00:00
static $version;
if (empty($version) && (config('database.default') === 'mysql')) {
$version = DB::selectOne('select version() as mversion')->mversion;
}
if (isset($version)) {
return $version;
}
2017-09-14 19:21:00 +00:00
2019-12-18 12:29:59 +00:00
return 'N/A';
2017-09-14 19:21:00 +00:00
}
2022-09-21 21:57:54 +00:00
public static function ip()
{
return request()->header('CF_CONNECTING_IP')
? request()->header('CF_CONNECTING_IP')
: request()->ip();
}
2020-03-03 13:09:05 +00:00
}