PwaManifest - viames/pair GitHub Wiki

Pair framework: PwaManifest

Pair\Helpers\PwaManifest generates and writes Web App Manifest JSON.

Main methods

toArray(array $options = []): array

Builds normalized manifest payload with defaults.

build(array $options = []): string

Returns manifest JSON string.

write(string $path, array $options = []): bool

Writes manifest JSON to file path.

Important normalized fields

  • id
  • name
  • short_name
  • description
  • lang
  • orientation
  • start_url
  • scope
  • display
  • background_color
  • theme_color
  • icons
  • shortcuts (optional)

If icons are omitted, Pair provides default icon definitions.

Example

use Pair\Helpers\PwaManifest;

PwaManifest::write(APPLICATION_PATH . '/public/manifest.webmanifest', [
    'name' => 'My Pair App',
    'short_name' => 'PairApp',
    'start_url' => '/',
    'scope' => '/',
    'display' => 'standalone',
    'theme_color' => '#1b6ec2',
    'background_color' => '#ffffff',
    'icons' => [
        ['src' => '/icons/icon-192.png', 'sizes' => '192x192', 'type' => 'image/png'],
        ['src' => '/icons/icon-512.png', 'sizes' => '512x512', 'type' => 'image/png', 'purpose' => 'any maskable']
    ]
]);

Validation/normalization notes

  • relative paths are normalized with leading /
  • invalid color fallback is #ffffff
  • display/orientation values are constrained to allowed sets

See also: PwaConfig, PWA, Application.