2017 © Pedro Peláez
 

library media-type-decoding

Simple API for Media type inference.

image

dreadlabs/media-type-decoding

Simple API for Media type inference.

  • Monday, July 16, 2018
  • by dreadwarrior
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

dreadlabs/media-type-decoding

Description

This library provides a simple API for Media type decoding., (*1)

It can be used to infer PHP class names from Media type strings literals such as application/prs.acme.user-created+json; version=1.0., (*2)

This library leans on the RFC 6838 specification., (*3)

It is a companion to DreadLabs/media-type-encoding, providing decoding of a Media type string literal., (*4)

Installation

composer install dreadlabs/media-type-decoding:~1.0

Usage

Example 1, (*5)

From a Media type string literal within the Application top-level type and the Vendor subtype tree, I want to resolve a fully-qualified PHP class name. The Media type string literal also carries a version parameter and no Suffix is defined., (*6)

$mediaType = new Application(RegistrationTree::vendor(new UpperCamelCasedFromHyphened(new Imploded('\\'))));
$withParameter = $mediaType->withParameter(new Parameter('version'));
$withSuffix = $withParameter->withSuffix(Suffix::none());

echo (string)$withSuffix->inferred('application/vnd.acme.customer-api.domain.event.item-added-to-cart; version=1.0');

> 'Acme\\CustomerApi\\Domain\\Event\\ItemAddedToCart'

Example 2, (*7)

This example enhances Example 1. The Media type string literal does not carry all necessary data to get the fully-qualified PHP class name. So we make usage of the Prefixed subtype inference., (*8)

$prefix = ['acme', 'customer-api', 'domain'];
$subtype = new Prefixed(new UpperCamelCasedFromHyphened(new Imploded('\\')), $prefix);
$mediaType = new Application(RegistrationTree::personal($subtype));

echo (string)$mediaType->inferred('application/prs.event.item-removed-from-cart')

> 'Acme\\CustomerApi\\Domain\\Event\\ItemRemovedFromCart'

Development

Requirements

Please read the contribution guide and ensure you have a working Docker environment., (*9)

Setup

Fork and clone this repository as described in the contribution guide., (*10)

Open a terminal and run the setup script:, (*11)

script/setup

Run tests

script/console run composer test:unit
script/console run composer test:integration
script/console run composer test:acceptance:fail-fast

License

MIT, (*12)

The Versions

16/07 2018

dev-master

9999999-dev

Simple API for Media type inference.

  Sources   Download

MIT

The Development Requires

16/07 2018