Download the PHP package quibble/transformer without Composer

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

Quibble/Transformer

Transformers for query result( sets)

Easily cast and transform a single result set or a collection of results from a database query.

Installation

Usage

Instantiate a transformer and either call the collection or resource method. The first parameter is the query result, the second a callable used to determine how to transform the result(s):

Internally, collection is simply a convenient front to array_map(Transformer::resource). In all other respects they work identically. The rest of this README will therefore only use resource.

The default behaviour is to remove all numeric keys from resources as if one had fetched it using PDO::FETCH_ASSOC. To override this you may instantiate the transformer with a false parameter.

You can only transform results returned as an array. The assumption is that if you fetch "into" objects (models) these would do their own massaging. You will however see later on how we can transform into objects as well.

Defining a transformation

The key to specifying the transformation is to type hint the named parameters you want to have transformed. By default PDO returns most things as strings. We can simply specify a few fields we want to be cast:

We can also type hint any object. The assumption is that such an object will be instantiated with the original value as its first and only argument. E.g.:

Any fields not specifically transformed are passed verbatim, and any fields mentioned in the transformed not present in the result are simply ignored. The idea is that you specify transformers with all transformable fields for a table, but your query doesn't necessarily do "SELECT *". This way you can easily reuse transformers.

Modifying the return type

PHP7+ allows us to type-hint a return type. If a transformer does this, an object of that type (or an array of them, in the case of collection) is returned instead:

Specifying multiple transformers

More than one transformer may be given; just add additional arguments. They are applied in order and if more than one specifies a return type, only the last is used. This allows you to quickly specify overrides for certain query results. If a field would be transformed twice using this method, it is first cast back to a string before being passed to the next transformer. If you instead would like to pass the transformed value (because your decorator uses type hinting in its constructor itself) specify it with a default null value.

Centralizing your code (DRY)

Instead of manually passing lambdas around, a much cleaner pattern would be to specify your transformers as class methods. You might do this on a model, or in a central interface. Remember, we're not actually calling these methods, we just want to inspect them!

FAQ

Do I need any other Quibble module to use this?

Nope. You don't even need PDO as long as you're dealing with arrays.


All versions of transformer with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3
monomelodies/reflex Version ^0.3
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 quibble/transformer contains the following files

Loading the files please wait ....