chore: remove pragmarx/countries-laravel dependency (#6237)

This commit is contained in:
Alexis Saettler
2022-07-31 10:37:15 +02:00
committed by GitHub
parent 84d0232095
commit a5ff8fc247
43 changed files with 1389 additions and 1862 deletions
+6 -6
View File
@@ -61,18 +61,18 @@ class ImportCSV extends Command
$user = User::where('email', $this->argument('user'))->first();
}
if (! file_exists($file)) {
$this->error('You need to provide a valid file path.');
return -1;
}
if (! $user) {
$this->error('You need to provide a valid User ID or email address!');
return -1;
}
if (! file_exists($file)) {
$this->error('You need to provide a valid file path.');
return -2;
}
if (is_string($file)) {
$this->info("Importing CSV file {$file} to user {$user->id}");
}
+2 -2
View File
@@ -50,7 +50,7 @@ class ImportVCards extends Command
// show an error and exist if the user does not exist
$this->error('No user with that email.');
return;
return -1;
}
$path = $this->option('path');
@@ -63,7 +63,7 @@ class ImportVCards extends Command
if (! $filesystem->exists($path) || ! $this->acceptedExtensions($filesystem, $path)) {
$this->error('The provided vcard file was not found or is not valid!');
return;
return -2;
}
$importJob = $this->import($path, $user);
+7 -5
View File
@@ -29,26 +29,28 @@ class SendTestEmail extends Command
*/
public function handle()
{
// retrieve the email from the option
/** retrieve the email from the option.
* @var string $email
*/
$email = $this->option('email');
// if no email was passed to the option, prompt the user to enter the email
if (! $email) {
$email = $this->ask('What email address should I send the test email to?');
$email = (string) $this->ask('What email address should I send the test email to?');
}
// Validate user provided email address
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
$this->error('Invalid email address: "'.$email.'".');
$this->error("Invalid email address: \"$email\".");
return -1;
}
$this->info('Preparing and sending email to "'.$email.'"');
$this->info("Preparing and sending email to \"$email\"");
// immediately deliver the test email (bypassing the queue)
Mail::raw(
'Hi '.$email.', you requested a test email from Monica.',
"Hi $email, you requested a test email from Monica.",
function ($message) use ($email) {
$message->to($email)
->subject('Monica email delivery test');
+23 -26
View File
@@ -2,11 +2,10 @@
namespace App\Helpers;
use Illuminate\Support\Arr;
use Rinvex\Country\Country;
use Rinvex\Country\CountryLoader;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\App;
use PragmaRX\CountriesLaravel\Package\Facade as Countries;
use PragmaRX\Countries\Package\Support\Collection as Country;
class CountriesHelper
{
@@ -17,10 +16,10 @@ class CountriesHelper
*/
public static function getAll(): Collection
{
$x = Countries::all();
$countries = $x->map(function ($item) {
$x = collect(countries(true, true));
$countries = $x->map(function (Country $item) {
return [
'id' => $item->cca2,
'id' => $item->getIsoAlpha2(),
'country' => static::getCommonNameLocale($item),
];
});
@@ -48,61 +47,59 @@ class CountriesHelper
* Find a country by the (english) name of the country.
*
* @param string $name Common name of a country
* @return string cca2 code of the country
* @return string iso_3166_1_alpha2 code of the country
*/
public static function find($name): string
{
$country = Countries::where('name.common', $name)->first();
$country = collect(CountryLoader::where('name.common', $name));
if ($country->count() === 0) {
$country = Countries::where('cca2', mb_strtoupper($name))->first();
$country = collect(CountryLoader::where('iso_3166_1_alpha2', mb_strtoupper($name)));
}
if ($country->count() === 0) {
return '';
}
return $country->cca2;
return (new Country($country->first()))->getIsoAlpha2();
}
/**
* Get the common name of country, in locale version.
*
* @param \ArrayAccess $country
* @param \Rinvex\Country\Country $country
* @return string
*/
private static function getCommonNameLocale($country): string
private static function getCommonNameLocale(Country $country): string
{
$locale = App::getLocale();
$lang = LocaleHelper::getLocaleAlpha($locale);
return Arr::get($country, 'translations.'.$lang.'.common',
Arr::get($country, 'name.common', '')
);
return $country->getTranslation($lang)['common'];
}
/**
* Get country for a specific iso code.
*
* @param string $iso
* @return Country|null the Country element
* @return \Rinvex\Country\Country|null the Country element
*/
public static function getCountry($iso): ?Country
{
$country = Countries::where('cca2', mb_strtoupper($iso))->first();
$country = collect(CountryLoader::where('iso_3166_1_alpha2', mb_strtoupper($iso)));
if ($country->count() === 0) {
$country = Countries::where('alt_spellings', mb_strtoupper($iso))->first();
$country = collect(CountryLoader::where('alt_spellings', mb_strtoupper($iso)));
}
if ($country->count() === 0) {
return null;
}
return $country;
return new Country($country->first());
}
/**
* Get country for a specific language.
*
* @param string $locale language code (iso)
* @return Country|null the Country element
* @return \Rinvex\Country\Country|null the Country element
*/
public static function getCountryFromLocale($locale): ?Country
{
@@ -113,22 +110,22 @@ class CountriesHelper
if (is_null($countryCode)) {
$lang = LocaleHelper::getLocaleAlpha($locale);
$country = Countries::whereISO639_3($lang);
$country = collect(CountryLoader::where("languages.$lang", '>', '0'));
if ($country->count() === 0) {
return null;
}
} else {
$country = Countries::where('cca2', $countryCode);
$country = collect(CountryLoader::where('iso_3166_1_alpha2', mb_strtoupper($countryCode)));
}
return $country->first();
return new Country($country->first());
}
/**
* Get default country for a language.
*
* @param string $locale language code (iso)
* @return string|null cca2 code
* @return string|null iso_3166_1_alpha2 code
*/
private static function getDefaultCountryFromLocale($locale): ?string
{
@@ -174,7 +171,7 @@ class CountriesHelper
{
// https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
// https://en.wikipedia.org/wiki/List_of_time_zones_by_country
switch ($country->cca3) {
switch ($country->getIsoAlpha3()) {
case 'AUS':
$timezone = 'Australia/Melbourne';
break;
@@ -197,7 +194,7 @@ class CountriesHelper
$timezone = 'America/Chicago';
break;
default:
$timezone = $country->hydrate('timezones')->timezones->first()->zone_name;
$timezone = collect($country->getTimezones())->first();
break;
}
+1 -1
View File
@@ -61,7 +61,7 @@ class LocaleHelper
if (is_null($countryCode)) {
$country = CountriesHelper::getCountryFromLocale($locale);
$countryCode = $country->cca2;
$countryCode = $country->getIsoAlpha2();
}
return mb_strtoupper($countryCode);
+1 -1
View File
@@ -14,7 +14,7 @@ class RequestHelper
/**
* Get client ip.
*
* @return array|string
* @return array|string|null
*/
public static function ip()
{
-3
View File
@@ -18,9 +18,6 @@ class Country extends JsonResource
if (is_array($this->resource)) {
$id = $this->resource['id'];
$name = $this->resource['country'];
} elseif ($this->resource instanceof \PragmaRX\Countries\Package\Support\Collection) {
$id = $this->resource->id;
$name = $this->resource->country;
} else {
$id = $this->resource;
$name = CountriesHelper::get($this->resource);
+1 -1
View File
@@ -5,6 +5,7 @@ namespace App\Models\Contact;
use DateTime;
use App\Traits\HasUuid;
use App\Traits\Searchable;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use App\Helpers\LocaleHelper;
use App\Models\Account\Photo;
@@ -22,7 +23,6 @@ use App\Models\Account\AddressBook;
use App\Models\Instance\SpecialDate;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
use IlluminateAgnostic\Arr\Support\Arr;
use App\Models\Account\ActivityStatistic;
use App\Models\Relationship\Relationship;
use Illuminate\Database\Eloquent\Builder;
@@ -15,12 +15,5 @@ class BroadcastServiceProvider extends ServiceProvider
public function boot()
{
Broadcast::routes();
/*
* Authenticate the user's personal channel...
*/
Broadcast::channel('App.User.*', function ($user, $userId) {
return (int) $user->id === (int) $userId;
});
}
}
@@ -3,9 +3,9 @@
namespace App\Services\DavClient\Utils;
use App\Jobs\Dav\PushVCard;
use Illuminate\Support\Arr;
use App\Jobs\Dav\DeleteVCard;
use Illuminate\Support\Collection;
use IlluminateAgnostic\Collection\Support\Arr;
use App\Services\DavClient\Utils\Model\SyncDto;
use App\Services\DavClient\Utils\Model\ContactDto;
use App\Services\DavClient\Utils\Traits\WithSyncDto;
@@ -3,9 +3,9 @@
namespace App\Services\DavClient\Utils;
use App\Jobs\Dav\PushVCard;
use Illuminate\Support\Arr;
use App\Models\Contact\Contact;
use Illuminate\Support\Collection;
use IlluminateAgnostic\Collection\Support\Arr;
use App\Services\DavClient\Utils\Model\SyncDto;
use App\Services\DavClient\Utils\Model\ContactDto;
use App\Services\DavClient\Utils\Traits\WithSyncDto;
+6 -6
View File
@@ -104,11 +104,11 @@ class CreateUser extends BaseService
}
// Currency
if (! is_null($currencyCode)) {
$this->associateCurrency($user, $currencyCode);
} elseif (! is_null($country)) {
foreach ($country->currencies as $currency) {
if ($this->associateCurrency($user, $currency)) {
if ((! is_null($currencyCode)
&& ! $this->associateCurrency($user, $currencyCode))
|| ! is_null($country)) {
foreach ($country->getCurrencies() as $currency) {
if ($this->associateCurrency($user, $currency['iso_4217_code'])) {
break;
}
}
@@ -116,7 +116,7 @@ class CreateUser extends BaseService
// Temperature scale
if (! is_null($country)) {
switch ($country->cca2) {
switch ($country->getIsoAlpha2()) {
case 'US':
case 'BZ':
case 'KY':