Laravel 9 Update (#1413)

Update to Laravel 9 and PHP 8+

Co-authored-by: B.Fatih KOZ <fatih.koz@gmail.com>
This commit is contained in:
Nabeel S
2022-03-14 11:45:18 -04:00
committed by GitHub
parent 00bf18c225
commit 12848091a2
340 changed files with 6130 additions and 4502 deletions

View File

@@ -26,9 +26,10 @@ class Database
*
* @return array
*/
public static function seed_from_yaml_file($yaml_file, $ignore_errors = false): array
public static function seed_from_yaml_file($yaml_file, bool $ignore_errors = false): array
{
$yml = file_get_contents($yaml_file);
return static::seed_from_yaml($yml, $ignore_errors);
}
@@ -40,7 +41,7 @@ class Database
*
* @return array
*/
public static function seed_from_yaml($yml, $ignore_errors = false): array
public static function seed_from_yaml($yml, bool $ignore_errors = false): array
{
$imported = [];
$yml = Yaml::parse($yml);
@@ -95,11 +96,11 @@ class Database
* @return mixed
*/
public static function insert_row(
$table,
$row,
$id_col = 'id',
$ignore_on_updates = [],
$ignore_errors = true
string $table,
array $row = [],
string $id_col = 'id',
array $ignore_on_updates = [],
bool $ignore_errors = true
) {
// encrypt any password fields
if (array_key_exists('password', $row)) {
@@ -112,7 +113,7 @@ class Database
// if any time fields are == to "now", then insert the right time
foreach ($row as $column => $value) {
if (strtolower($value) === 'now') {
if (!empty($value) && strtolower($value) === 'now') {
$row[$column] = static::time();
}
}

View File

@@ -61,11 +61,11 @@ class Dates
/**
* Return the start/end dates for a given month/year
*
* @param $month YYYY-MM
* @param string $month In "YYYY-MM" format
*
* @return array
*/
public static function getMonthBoundary($month): array
public static function getMonthBoundary(string $month): array
{
[$year, $month] = explode('-', $month);
$days = static::getDaysInMonth($month, $year);

View File

@@ -1,35 +0,0 @@
<?php
namespace App\Support;
use Illuminate\Support\Facades\Log;
class Discord
{
/**
* Get a user's private channel ID from Discord
*
* @param string $discord_id
*/
public static function getPrivateChannelId(string $discord_id)
{
/** @var HttpClient $httpClient */
$httpClient = app(HttpClient::class);
try {
$response = $httpClient->post(
'https://discord.com/api/users/@me/channels',
[
'recipient_id' => $discord_id,
]
);
dd($response);
return $response->id;
} catch (\Exception $ex) {
dd($ex);
Log::error('Could not get private channel id for '.$discord_id.';'.$ex->getMessage());
return '';
}
}
}

View File

@@ -10,7 +10,7 @@ use GuzzleHttp\RequestOptions;
*/
class HttpClient
{
private $httpClient;
private GuzzleClient $httpClient;
public function __construct(GuzzleClient $httpClient)
{
@@ -50,9 +50,11 @@ class HttpClient
* @param $body
* @param array $opts
*
* @throws \GuzzleHttp\Exception\GuzzleException
*
* @return mixed
*/
public function post($uri, $body, array $opts = [])
public function post($uri, $body, array $opts = []): mixed
{
$opts = array_merge([
'connect_timeout' => 2,
@@ -61,11 +63,40 @@ class HttpClient
$response = $this->httpClient->post($uri, $opts);
$content_type = $response->getHeaderLine('content-type');
if (strpos($content_type, 'application/json') !== false) {
$body = \GuzzleHttp\json_decode($body, true);
$content = $response->getBody()->getContents();
if (str_contains($content_type, 'application/json') !== false) {
$content = \GuzzleHttp\json_decode($content, true);
}
return $body;
return $content;
}
/**
* @param $uri
* @param $body
* @param array $opts
*
* @throws \GuzzleHttp\Exception\GuzzleException
*
* @return mixed
*/
public function form_post($uri, $body, array $opts = []): mixed
{
$opts = array_merge([
'connect_timeout' => 2,
'form_params' => $body,
], $opts);
$response = $this->httpClient->request('POST', $uri, $opts);
$content_type = $response->getHeaderLine('content-type');
$content = $response->getBody()->getContents();
if (str_contains($content_type, 'application/json') !== false) {
$content = \GuzzleHttp\json_decode($content, true);
}
return $content;
}
/**

View File

@@ -8,7 +8,6 @@ use App\Support\Units\Pressure;
use App\Support\Units\Temperature;
use App\Support\Units\Velocity;
use function count;
use Illuminate\Support\Facades\Log;
use PhpUnitsOfMeasure\Exception\NonNumericValue;
use PhpUnitsOfMeasure\Exception\NonStringUnitName;
@@ -403,14 +402,11 @@ class Metar implements \ArrayAccess
* @param int|float $value
* @param string $unit "feet" or "meters"
*
* @throws NonStringUnitName
* @throws NonNumericValue
*
* @return Altitude
*/
protected function createAltitude($value, $unit)
{
return new Altitude((float) $value, $unit);
return Altitude::make((float) $value, $unit);
}
/**
@@ -419,14 +415,11 @@ class Metar implements \ArrayAccess
* @param int|float $value
* @param string $unit "m" (meters) or "mi" (miles)
*
* @throws NonNumericValue
* @throws NonStringUnitName
*
* @return Distance
*/
protected function createDistance($value, $unit)
{
return new Distance((float) $value, $unit);
return Distance::make((float) $value, $unit);
}
/**
@@ -442,7 +435,7 @@ class Metar implements \ArrayAccess
*/
protected function createPressure($value, $unit)
{
return new Pressure((float) $value, $unit);
return Pressure::make((float) $value, $unit);
}
/**
@@ -458,7 +451,7 @@ class Metar implements \ArrayAccess
*/
protected function createTemperature($value, $unit)
{
return new Temperature((float) $value, $unit);
return Temperature::make((float) $value, $unit);
}
/**
@@ -474,7 +467,7 @@ class Metar implements \ArrayAccess
*/
protected function createVelocity($value, $unit)
{
return new Velocity((float) $value, $unit);
return Velocity::make((float) $value, $unit);
}
/**

View File

@@ -10,7 +10,7 @@ use Akaunting\Money\Money as MoneyBase;
*/
class Money
{
public $money;
public MoneyBase $money;
public $subunit_amount;
public static $iso_currencies;
public static $subunit_multiplier;

View File

@@ -19,7 +19,7 @@ class CustomPaginatedResourceResponse extends PaginatedResourceResponse
protected function meta($paginated)
{
return Arr::except($paginated, [
$arr = Arr::except($paginated, [
'data',
'first_page_url',
'last_page_url',
@@ -27,5 +27,10 @@ class CustomPaginatedResourceResponse extends PaginatedResourceResponse
'next_page_url',
'links',
]);
$arr['prev_page'] = $paginated['prev_page_url'];
$arr['next_page'] = $paginated['next_page_url'];
return $arr;
}
}

View File

@@ -18,12 +18,13 @@ class ThemeViewFinder extends \Igaster\LaravelTheme\themeViewFinder
* Override findNamespacedView() to add "Theme/vendor/..." paths
*
* @param string $name
*
* @return string
*/
protected function findNamespacedView($name)
protected function findNamespacedView($name): string
{
// Extract the $view and the $namespace parts
list($namespace, $view) = $this->parseNamespaceSegments($name);
[$namespace, $view] = $this->parseNamespaceSegments($name);
$paths = $this->addThemeNamespacePaths($namespace);
@@ -84,6 +85,7 @@ class ThemeViewFinder extends \Igaster\LaravelTheme\themeViewFinder
$paths = Arr::prepend($paths, $path);
}
}
return $paths;
}
}

View File

@@ -7,7 +7,7 @@ use PhpUnitsOfMeasure\PhysicalQuantity\Length;
class Altitude extends Unit
{
public $responseUnits = [
public array $responseUnits = [
'ft',
'km',
'm',
@@ -26,7 +26,14 @@ class Altitude extends Unit
$value = 0;
}
$this->unit = setting('units.altitude');
$this->instance = new Length($value, $unit);
$this->localUnit = setting('units.altitude');
$this->internalUnit = config('phpvms.internal_units.altitude');
if ($value instanceof self) {
$value->toUnit($unit);
$this->instance = $value->instance;
} else {
$this->instance = new Length($value, $unit);
}
}
}

View File

@@ -7,7 +7,7 @@ use PhpUnitsOfMeasure\PhysicalQuantity\Length;
class Distance extends Unit
{
public $responseUnits = [
public array $responseUnits = [
'm',
'km',
'mi',
@@ -17,19 +17,26 @@ class Distance extends Unit
/**
* Distance constructor.
*
* @param float $value
* @param string $unit
* @param Distance|float $value
* @param string $unit The unit of $value
*
* @throws \PhpUnitsOfMeasure\Exception\NonNumericValue
* @throws \PhpUnitsOfMeasure\Exception\NonStringUnitName
*/
public function __construct($value, string $unit)
public function __construct(mixed $value, string $unit)
{
if (empty($value)) {
$value = 0;
}
$this->unit = setting('units.distance');
$this->instance = new Length($value, $unit);
$this->localUnit = setting('units.distance');
$this->internalUnit = config('phpvms.internal_units.distance');
if ($value instanceof self) {
$value->toUnit($unit);
$this->instance = $value->instance;
} else {
$this->instance = new Length($value, $unit);
}
}
}

View File

@@ -7,7 +7,7 @@ use PhpUnitsOfMeasure\PhysicalQuantity\Mass;
class Fuel extends Unit
{
public $responseUnits = [
public array $responseUnits = [
'kg',
'lbs',
];
@@ -25,7 +25,14 @@ class Fuel extends Unit
$value = 0;
}
$this->unit = setting('units.fuel');
$this->instance = new Mass($value, $unit);
$this->localUnit = setting('units.fuel');
$this->internalUnit = config('phpvms.internal_units.fuel');
if ($value instanceof self) {
$value->toUnit($unit);
$this->instance = $value->instance;
} else {
$this->instance = new Mass($value, $unit);
}
}
}

View File

@@ -7,7 +7,7 @@ use PhpUnitsOfMeasure\PhysicalQuantity\Mass as MassUnit;
class Mass extends Unit
{
public $responseUnits = [
public array $responseUnits = [
'kg',
'lbs',
];
@@ -25,7 +25,14 @@ class Mass extends Unit
$value = 0;
}
$this->unit = setting('units.weight');
$this->instance = new MassUnit($value, $unit);
$this->localUnit = setting('units.weight');
$this->internalUnit = config('phpvms.internal_units.mass');
if ($value instanceof self) {
$value->toUnit($unit);
$this->instance = $value->instance;
} else {
$this->instance = new MassUnit($value, $unit);
}
}
}

View File

@@ -10,7 +10,7 @@ use PhpUnitsOfMeasure\PhysicalQuantity\Pressure as PressureUnit;
*/
class Pressure extends Unit
{
public $responseUnits = [
public array $responseUnits = [
'atm',
'hPa',
];
@@ -28,7 +28,14 @@ class Pressure extends Unit
$value = 0;
}
$this->unit = setting('units.temperature');
$this->instance = new PressureUnit($value, $unit);
$this->localUnit = setting('units.temperature');
$this->internalUnit = config('phpvms.internal_units.temperature');
if ($value instanceof self) {
$value->toUnit($unit);
$this->instance = $value->instance;
} else {
$this->instance = new PressureUnit($value, $unit);
}
}
}

View File

@@ -10,7 +10,7 @@ use PhpUnitsOfMeasure\PhysicalQuantity\Temperature as TemperatureUnit;
*/
class Temperature extends Unit
{
public $responseUnits = [
public array $responseUnits = [
'C',
'F',
];
@@ -28,7 +28,14 @@ class Temperature extends Unit
$value = 0;
}
$this->unit = setting('units.temperature');
$this->instance = new TemperatureUnit($value, $unit);
$this->localUnit = setting('units.temperature');
$this->internalUnit = config('phpvms.internal_units.temperature');
if ($value instanceof self) {
$value->toUnit($unit);
$this->instance = $value->instance;
} else {
$this->instance = new TemperatureUnit($value, $unit);
}
}
}

View File

@@ -10,7 +10,7 @@ use PhpUnitsOfMeasure\PhysicalQuantity\Velocity as VelocityUnit;
*/
class Velocity extends Unit
{
public $responseUnits = [
public array $responseUnits = [
'km/h',
'knots',
];
@@ -28,7 +28,14 @@ class Velocity extends Unit
$value = 0;
}
$this->unit = setting('units.speed');
$this->instance = new VelocityUnit($value, $unit);
$this->localUnit = setting('units.speed');
$this->internalUnit = config('phpvms.internal_units.velocity');
if ($value instanceof self) {
$value->toUnit($unit);
$this->instance = $value->instance;
} else {
$this->instance = new VelocityUnit($value, $unit);
}
}
}

View File

@@ -10,7 +10,7 @@ use PhpUnitsOfMeasure\PhysicalQuantity\Volume as VolumeUnit;
*/
class Volume extends Unit
{
public $responseUnits = [
public array $responseUnits = [
'gal',
'liters',
];
@@ -28,7 +28,14 @@ class Volume extends Unit
$value = 0;
}
$this->unit = setting('units.volume');
$this->instance = new VolumeUnit($value, $unit);
$this->localUnit = setting('units.volume');
$this->internalUnit = config('phpvms.internal_units.volume');
if ($value instanceof self) {
$value->toUnit($unit);
$this->instance = $value->instance;
} else {
$this->instance = new VolumeUnit($value, $unit);
}
}
}

View File

@@ -20,7 +20,7 @@ class Utils
*
* @return string
*/
public static function generateNewId(int $length = null)
public static function generateNewId(int $length = null): string
{
if (!$length) {
$length = Model::ID_MAX_LENGTH;
@@ -38,8 +38,7 @@ class Utils
*/
public static function generateApiKey(): string
{
$key = substr(sha1(time().mt_rand()), 0, 20);
return $key;
return substr(sha1(time().mt_rand()), 0, 20);
}
/**

View File

@@ -1,130 +0,0 @@
<?php
namespace App\Support;
use App\Services\VersionService;
use Codedge\Updater\Contracts\GithubRepositoryTypeContract;
use Codedge\Updater\SourceRepositoryTypes\GithubRepositoryType;
use Codedge\Updater\Traits\SupportPrivateAccessToken;
use Codedge\Updater\Traits\UseVersionFile;
use Exception;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use InvalidArgumentException;
use Psr\Http\Message\ResponseInterface;
/**
* Use SourceRepositoryTypes/GithubRepositoryTypes/GithubTagType.php as a reference
* Just replace the new update checks, etc, with the VersionService stubs. They're
* essentially the same except for the current version checks and all that. Adds some
* additional logging too, but the base update method is from GithubRepositoryType
*/
final class VmsRepositoryType extends GithubRepositoryType implements GithubRepositoryTypeContract
{
use UseVersionFile;
use SupportPrivateAccessToken;
/**
* @var Client
*/
protected $client;
/**
* @var VersionService
*/
protected $versionSvc;
/**
* @var string
*/
private $storagePath;
public function __construct(array $config, Client $client)
{
$this->config = $config;
$this->client = $client;
$this->storagePath = Str::finish($this->config['download_path'], DIRECTORY_SEPARATOR);
$this->versionSvc = app(VersionService::class);
}
/**
* Check repository if a newer version than the installed one is available.
*
* @param string $currentVersion
*
* @throws InvalidArgumentException
* @throws Exception
*
* @return bool
*/
public function isNewVersionAvailable(string $currentVersion = ''): bool
{
return $this->versionSvc->isNewVersionAvailable($currentVersion);
}
/**
* Get the latest version that has been published in a certain repository.
* Example: 2.6.5 or v2.6.5.
*
* @param string $prepend Prepend a string to the latest version
* @param string $append Append a string to the latest version
*
* @throws Exception
*
* @return string
*/
public function getVersionAvailable(string $prepend = '', string $append = ''): string
{
return $this->versionSvc->getLatestVersion();
}
/**
* Fetches the latest version. If you do not want the latest version, specify one and pass it.
*
* @param string $version
*
* @throws Exception
*
* @return void
*/
public function fetch($version = ''): void
{
$response = $this->getRepositoryReleases();
$releaseCollection = collect(\GuzzleHttp\json_decode($response->getBody()->getContents()));
if ($releaseCollection->isEmpty()) {
throw new Exception('Cannot find a release to update. Please check the repository you\'re pulling from');
}
if (!File::exists($this->storagePath)) {
File::makeDirectory($this->storagePath, 493, true, true);
}
if (!empty($version)) {
$release = $releaseCollection->where('name', $version)->first();
} else {
$release = $releaseCollection->first();
}
Log::info('Found release='.$release->name.', path='.$release->zipball_url);
$storageFolder = $this->storagePath.$release->name.'-'.now()->timestamp;
$storageFilename = $storageFolder.'.zip';
if (!$this->isSourceAlreadyFetched($release->name)) {
$this->downloadRelease($this->client, $release->zipball_url, $storageFilename);
$this->unzipArchive($storageFilename, $storageFolder);
$this->createReleaseFolder($storageFolder, $release->name);
}
}
protected function getRepositoryReleases(): ResponseInterface
{
$url = self::GITHUB_API_URL
.'/repos/'.$this->config['repository_vendor']
.'/'.$this->config['repository_name']
.'/tags';
$headers = [];
return $this->client->request('GET', $url, ['headers' => $headers]);
}
}