Download the PHP package dreadlabs/media-type-encoding without Composer

On this page you can find all versions of the php package dreadlabs/media-type-encoding. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package media-type-encoding

dreadlabs/media-type-encoding

Description

This library provides a simple API for Media type designation.

It can be used to generate Media type strings from string literals such as PHP class names. This is useful for APIs or serialization processes which should denote a platform agnostic type literal.

This library leans on the RFC 6838 specification.

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

Installation

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

Usage

Example 1

From a fully-qualified, namespaced PHP class name, designate a Media type within the application/ top-level type. The subtype is located in the Personal tree. The UpperCamelCased naming convention of PHP classes should be designated to a hyphened form. The designated Media type comes with a version parameter and a +json suffix.

$mediaType = new Application(RegistrationTree::personal(new HyphenedFromUpperCamelCased(new Exploded('\\'))));
$withParameter = $mediaType->withParameter(new Parameter('version', '1.0'));
$withSuffix = $withParameter->withSuffix(new Json());

echo (string)$withSuffix->designated('Acme\\Example\\Class');

> 'application/prs.acme.example.class+json; version=1.0'

Example 2

This example enhances Example 1. Let's imagine you are structuring your PHP project in such a way, that the Domain namespace contains your business logic. The PHP library you are building is named after a Bounded context called SalesApi. There, you have a Domain Event called UserCreated. The Media type encoding should not carry too much information about the vendor namespace and the physical structures of the filesystem.

$imaginaryClassName = 'Acme\\SalesApi\\Domain\\Event\\UserCreated';
$namespace = 'Acme\\SalesApi\\Domain\\Event';
$mediaType = new Application(RegistrationTree::vendor(new HyphenedFromUpperCamelCased(new Exploded('\\'))));

$designatedMediaType = $mediaType->designated(str_replace($namespace, 'SalesApi', $imaginaryClassName));

self::assertEquals('application/vnd.sales-api.user-created', (string)$designatedMediaType);

The reason why I am showing you this is, because I thought about implementing a subtype Prefixed which allows replacing parts of the FQCN. But this would add unnecessary complexity where a simple str_replace is sufficent.

Development

Requirements

Please read the contribution guide and ensure you have a working Docker environment.

Setup

Fork and clone this repository as described in the contribution guide.

Open a terminal and run the setup script:

script/setup

Run tests

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

Links

License

MIT


All versions of media-type-encoding with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package dreadlabs/media-type-encoding contains the following files

Loading the files please wait ....