Download the PHP package deefour/transformer without Composer

On this page you can find all versions of the php package deefour/transformer. 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 transformer

Transformer

Build Status Total Downloads Latest Stable Version License

Transform raw input data into consistent, immutable data transfer objects.

Getting Started

Run the following to add Transfromer to your project's composer.json. See Packagist for specific versions.

>=PHP5.5.0 is required.

Overview

Example

Let's say the following input data is submitted via a POST request to create a new Book.

Let's also say that we want to be sure the title of the book has been properly titleized, the price is a float value, and the publication date is a Carbon\Carbon datetime object. The attributes of this raw $input can be formatted in a specific, consistent format using a transformer.

The methods are optional, each having public visibility and being named after a camel-cased version of an attribute. These methods will be called whenever those attributes are requested from the transformer.

Casts

A protected $casts property can be added to a transformer, composed of attribute names as its keys and the scalar type the attribute should be cast into by the transformer as its values. This mapping will be checked as attributes are returned from a transformer, casting them to the desired type.

Note: Casts to type 'object' and 'array' will be converted to JSON using json_encode.

Hiding Raw Input

A protected $hidden property can be added to a transformer, listing attributes that will be omitted from bulk requests for information like toArray(), all(), and jsonSerialize().

Fallbacks (Default Values)

A protected $fallbacks property can be added to a transformer, composed of attribute names as its keys and default values as its values. This mapping will be checked as attributes are requested from a transformer but cannot be found on the source data or whose value is NULL.

Accepting NULL Values

If an attributes on the source with a NULL value should generally be accepted in favor of a default value in the $fallbacks mapping, this can be enabled for the lifecycle of a request on all transformers by running the following:

To illustrate the difference:

Method Attributes

Public methods marked with @attribute in their docblock are be treated as attributes on the transformer's $attributes source.

The isOld method is marked with an @attribute annotation in the docblock, causing the transformer to behave as though an is_old attribute exists on the source data. internalSlug() can be called directly, but it will not be treated as some internal_slug attribute because it has not been marked properly with a docblock annotation.

Accessing Data

Individual transformed attributes can be retrieved with get().

A magic __get() implementation provides property access to the transformed attributes

A magic __call() implementation provides method access

The existince of a property can be checked through __isset() or the api

Transformers also implement ArrayAccess (attempting to set or unset throws an exception).

All transformed attributes can be retrieved at once.

and a specific set of keys can be plucked all at once.

The JsonSerializable interface is also implemented.

Individual raw attributes or the entire raw source can be retrieved.

A default value can be provided to get() as a second parameter. If the default is a callable, it will be evaluated before returning.

Mutable Transformers

In the base transformer, __set(), offsetSet, and offsetUnset are all null methods. This (lack of) behavior keeps the underlying source data immutable.

A MutableTransformer class exists which does implement these methods, allowing additional properties to be added to, or existing properties to be modified on the transformer instance.

The __call() method can also be used to set/modify attributes on the transformer.

Instantiation and data access are otherwise identical to the base transformer.

Tracking Changes

When an attribute is modified on a mutable transformer, it's original value is maintained. The transformer can be queried to determine if an attribute has been modified after construction or to retrieve a list of changes.

Contribute

Changelog

1.7.0 - March 2, 2017

1.6.0 - February 14, 2017

1.5.0 - October 20, 2016

1.4.0 - October 20, 2016

1.3.0 - October 16, 2016

1.0.1 - October 29, 2015

1.0.0 - October 7, 2015

0.4.0 - September 7, 2015

0.3.0 - September 4, 2015

0.2.6 - June 5, 2015

0.2.5 - June 3, 2015

0.2.4 - June 2, 2015

0.2.2 - May 30, 2015

0.2.1 - May 25, 2015

0.2.0 - May 5, 2015

0.1.0 - April 22, 2015

License

Copyright (c) 2016 Jason Daly (deefour). Released under the MIT License.


All versions of transformer with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5.0
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 deefour/transformer contains the following files

Loading the files please wait ....