style updates
This commit is contained in:
@@ -1,22 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Marketplace\Services;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
final class PackageManifest
|
||||
{
|
||||
public function parse(array|string $manifest): array
|
||||
{
|
||||
if (is_string($manifest)) {
|
||||
$decoded=json_decode($manifest,true);
|
||||
if (!is_array($decoded)) throw ValidationException::withMessages(['manifest'=>'The package manifest is not valid JSON.']);
|
||||
$manifest=$decoded;
|
||||
$decoded = json_decode($manifest, true);
|
||||
if (! is_array($decoded)) {
|
||||
throw ValidationException::withMessages(['manifest' => 'The package manifest is not valid JSON.']);
|
||||
}
|
||||
$manifest = $decoded;
|
||||
}
|
||||
foreach (['name','type','version'] as $field) if (!filled(Arr::get($manifest,$field))) throw ValidationException::withMessages(['manifest'=>"Manifest field [$field] is required."]);
|
||||
if (!in_array($manifest['type'],config('marketplace.supported_types',[]),true)) throw ValidationException::withMessages(['manifest'=>'Unsupported marketplace package type.']);
|
||||
$manifest['requires']=$manifest['requires'] ?? [];
|
||||
$manifest['content_manager']=$manifest['content_manager'] ?? '*';
|
||||
$manifest['laravel']=$manifest['laravel'] ?? '*';
|
||||
foreach (['name', 'type', 'version'] as $field) {
|
||||
if (! filled(Arr::get($manifest, $field))) {
|
||||
throw ValidationException::withMessages(['manifest' => "Manifest field [$field] is required."]);
|
||||
}
|
||||
}
|
||||
if (! in_array($manifest['type'], config('marketplace.supported_types', []), true)) {
|
||||
throw ValidationException::withMessages(['manifest' => 'Unsupported marketplace package type.']);
|
||||
}
|
||||
$manifest['requires'] = $manifest['requires'] ?? [];
|
||||
$manifest['content_manager'] = $manifest['content_manager'] ?? '*';
|
||||
$manifest['laravel'] = $manifest['laravel'] ?? '*';
|
||||
|
||||
return $manifest;
|
||||
}
|
||||
public function fromFile(string $path): array { return $this->parse((string) file_get_contents($path)); }
|
||||
|
||||
public function fromFile(string $path): array
|
||||
{
|
||||
return $this->parse((string) file_get_contents($path));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user