2017 © Pedro Peláez
 

library manifest

A PHP library for building web application manifests

image

lukaswhite/manifest

A PHP library for building web application manifests

  • Tuesday, April 10, 2018
  • by lukaswhite
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 250 % Grown

The README.md

Manifest

A simple PHP library for programmatically generating Web App Manifests., (*1)

Simple Example

$manifest = new Manifest( );
$manifest->name( 'My Awesome App' )
    ->shortName( 'AwesomeApp' )
    ->description( 'Just testing' );

print $manifest->toJson( );
// or
$manifest->save( 'public/manifest.json' );    

In Laravel

Route::get( 'manifest.json', function( ) {
    $manifest = new Manifest( );
    $manifest->name( Config::get( 'app.name' ) )
        ->description( trans( 'site.meta.description' ) );

    return response( )->json( $manifest );
} );

A Longer Example

Here's an example taken from the Mozilla documentation on web app manifests:, (*2)

{
  "name": "HackerWeb",
  "short_name": "HackerWeb",
  "start_url": ".",
  "display": "standalone",
  "background_color": "#fff",
  "description": "A simply readable Hacker News app.",
  "icons": [{
    "src": "images/touch/homescreen48.png",
    "sizes": "48x48",
    "type": "image/png"
  }, {
    "src": "images/touch/homescreen72.png",
    "sizes": "72x72",
    "type": "image/png"
  }, {
    "src": "images/touch/homescreen96.png",
    "sizes": "96x96",
    "type": "image/png"
  }, {
    "src": "images/touch/homescreen144.png",
    "sizes": "144x144",
    "type": "image/png"
  }, {
    "src": "images/touch/homescreen168.png",
    "sizes": "168x168",
    "type": "image/png"
  }, {
    "src": "images/touch/homescreen192.png",
    "sizes": "192x192",
    "type": "image/png"
  }],
  "related_applications": [{
    "platform": "play",
    "url": "https://play.google.com/store/apps/details?id=cheeaun.hackerweb"
  }]
}

And here is how to build that using this library:, (*3)

$manifest = new Manifest( );
$manifest
    ->name( 'HackerWeb' )
    ->shortName( 'HackerWeb' )
    ->description( 'A simply readable Hacker News app.' )
    ->startUrl( '.' )
    ->standalone( )
    ->backgroundColor( '#fff' )
    ->icons(
        [
            new Icon( 'images/touch/homescreen48.png', 48, 'image/png' ),
            new Icon( 'images/touch/homescreen72.png', 72, 'image/png' ),
            new Icon( 'images/touch/homescreen96.png', 96, 'image/png' ),
            new Icon( 'images/touch/homescreen144.png', 144, 'image/png' ),
            new Icon( 'images/touch/homescreen168.png', 168, 'image/png' ),
            new Icon( 'images/touch/homescreen192.png', 192, 'image/png' ),
        ]
    )
    ->addRelatedApplication(
        new RelatedApplication(
            'play', 
            'https://play.google.com/store/apps/details?id=cheeaun.hackerweb'
        )
    );

But...why?

I created this because I was a developing an application designed to be deployed multiple times with different configurations; things like the application name would be different across multiple installations, so it made sense to be able to control the contents of the manifest from the codebase., (*4)

Suppose you're building a CMS-driven application; chances are anything from the metadata (the name and description as it appears when adding an app to a homescreen) to the colour-scheme are probably database-driven; this allows you to do just that., (*5)

There are a number of other reasons you might want to use this approach:, (*6)

  • Personal preference; maybe you prefer writing out JSON files by hand, perhaps you prefer the programmatic approach
  • It helps remove duplication; suppose information such as a your application name are in config or a database — this allows you to avoid duplicating that information
  • Some properties really belong in config; suppose you need to set a sender ID for Google Clound Messaging. It makes sense to keep that in config, and then you can simply inject it into your manifest as required.
  • i18n; want to translate your app description into multiple languages? You can using this approach.
  • You can integrate it into your deployment process; if you're automating, say, your application icon generation (who wants to do that resizing by hand?), this approach makes that easier to automate.

More documentation to follow, (*7)

The Versions

10/04 2018

dev-master

9999999-dev

A PHP library for building web application manifests

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Lukas White