vendor and env first commit

This commit is contained in:
2025-03-28 08:52:46 +01:00
parent f8388bc81b
commit 8f26283832
10976 changed files with 1349952 additions and 2 deletions
@@ -0,0 +1,131 @@
<?php
namespace Webpatser\Countries;
use Illuminate\Database\Eloquent\Model;
/**
* CountryList
*
*/
class Countries extends Model {
/**
* @var string
* Path to the directory containing countries data.
*/
protected $countries;
/**
* @var string
* The table for the countries in the database, is "countries" by default.
*/
protected $table;
/**
* Constructor.
*
* @return void
*/
public function __construct()
{
$this->table = \Config::get('countries.table_name');
}
/**
* Get the countries from the JSON file, if it hasn't already been loaded.
*
* @return array
*/
protected function getCountries()
{
//Get the countries from the JSON file
if (! $this->countries){
$this->countries = json_decode(file_get_contents(__DIR__ . '/Models/countries.json'), true);
}
//Return the countries
return $this->countries;
}
/**
* Returns one country
*
* @param string $id The country id
*
* @return array
*/
public function getOne($id)
{
$countries = $this->getCountries();
return $countries[$id];
}
/**
* Returns a list of countries
*
* @param string sort
*
* @return array
*/
public function getList($sort = null)
{
//Get the countries list
$countries = $this->getCountries();
//Sorting
$validSorts = [
'capital',
'citizenship',
'country-code',
'currency',
'currency_code',
'currency_sub_unit',
'full_name',
'iso_3166_2',
'iso_3166_3',
'name',
'region-code',
'sub-region-code',
'eea',
'calling_code',
'currency_symbol',
'flag',
];
if (!is_null($sort) && in_array($sort, $validSorts)){
uasort($countries, function($a, $b) use ($sort) {
if (!isset($a[$sort]) && !isset($b[$sort])){
return 0;
} elseif (!isset($a[$sort])){
return -1;
} elseif (!isset($b[$sort])){
return 1;
} else {
return strcasecmp($a[$sort], $b[$sort]);
}
});
}
//Return the countries
return $countries;
}
/**
* Returns a list of countries suitable to use with a select element in Laravelcollective\html
* Will show the value and sort by the column specified in the display attribute
*
* @param string display
*
* @return array
*/
public function getListForSelect($display = 'name')
{
foreach ($this->getList($display) as $key => $value) {
$countries[$key] = $value[$display];
}
//return the array
return $countries;
}
}
@@ -0,0 +1,19 @@
<?php
namespace Webpatser\Countries;
use Illuminate\Support\Facades\Facade;
/**
* CountriesFacade
*
*/
class CountriesFacade extends Facade {
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor() { return 'countries'; }
}
@@ -0,0 +1,84 @@
<?php
namespace Webpatser\Countries;
use Illuminate\Support\ServiceProvider;
/**
* CountryListServiceProvider
*/
class CountriesServiceProvider extends ServiceProvider {
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* Bootstrap the application.
*
* @return void
*/
public function boot()
{
// The publication files to publish
$this->publishes([__DIR__ . '/../../config/config.php' => config_path('countries.php')]);
// Append the country settings
$this->mergeConfigFrom(
__DIR__ . '/../../config/config.php', 'countries'
);
}
/**
* Register everything.
*
* @return void
*/
public function register()
{
$this->registerCountries();
$this->registerCommands();
}
/**
* Register the service provider.
*
* @return void
*/
public function registerCountries()
{
$this->app->bind('countries', function($app)
{
return new Countries();
});
}
/**
* Register the artisan commands.
*
* @return void
*/
protected function registerCommands()
{
$this->app->singleton('command.countries.migration', function ($app) {
return new MigrationCommand($app);
});
$this->commands('command.countries.migration');
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return ['countries'];
}
}
File diff suppressed because it is too large Load Diff