Download the PHP package konsulting/laravel-transformer without Composer

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

Transformer

Build Status Scrutinizer Code Quality

A simple way to transform data, with helpers for transforming data in Laravel applications.

Installation

Transformer in a Laravel application

If you are using Laravel 5.5, they will auto-register. However, if you have chosen not to auto-register, or are using an earlier version, add the following to config/app.php

Transformer outside a Laravel application

Usage

Transformer uses RulePacks to provide transformation functionality. RulePacks can be added to the Transformer during construction, or after with the addRulePack or addRulePacks methods.

A set of rules can be passed in during construction (useful when applying the same rules to different sets of data) or rules can be passed in at the point when performing transformation.

To transform data, the transform method is used. It accepts an array (or collection) of data to transform, and optionally rules to apply.

Transform helper

There is also a helper class Transform, which facilitates the easy transformation of a single value by one or more rules. Transform receives an instance of Transformer via its constructor, which provides the transformation logic and determines which rules are available. Using the instance of Transformer built up previously:

Rules may be called as methods on the Transform object, with the value to be transformed passed in as the first argument and any rule parameters as subsequent arguments.

Alternatively, rules may be passed via the withRule() and withRules() methods (for singular and multiple rules respectively). Rule parameters are passed either as separate arguments, or as an array.

Fluent API

Rules may also be called fluently: the input value is set with the input() method, and the result is obtained with get(). Any number of rule methods may be chained between these.

When the fluent API is used, the value is not passed as an argument to the rule methods (as it has already been set via input()). As such, all arguments passed to rule methods are treated as rule parameters.

withRule() and withRules() may be used to fluently declare rules with or without parameters:

Available Rules

We provide a couple of rule packs for use, it is easy to extend the rules available by creating your own Rule Pack. Rule Packs are loaded in the declared order, methods in later packs will override packs loaded earlier.

Parameter names are denoted by <param> and optional parameters by [<param>].

Core Rule Pack

Cleaning up
Casting
String manipulation
Regex and string replace

Carbon Rule Pack

Related Fields Rule Pack

Number Rule Pack

Note: key is a dot notation key for another field in the dataset

Laravel Helpers

We use Laravel frequently, so have a couple of extras added here.

Facade

Use the facade to gain easy access to the Transformer wherever you are.

Request Macro transform

The Service Provider adds the transform Macro to the Illuminate\Http\Request class. This makes it simple to invoke the transformation on a request at any point. The method passes the request object back to allow chaining.

TransformingRequest Trait

This trait makes the form request transform the data before validation occurs (which is upon it being resolved by the container).

Rules for transformation are provided in the transformRules method.

Using the TransformingRequest Trait

Middleware

The TransformRequest middleware applies transformations to requests according to configured rules. These rules are specified in the middleware_rules key of the config file as detailed in Usage.

To register the middleware for use in your project, add the following line to your project's App/Http/Kernel.php:

The default middleware rules state that every field should be trimmed of whitespace and nulled if empty:

Rules need not be applied to all fields; specific fields may be targeted within the middleware if required:

With the above configuration, the postcode and email fields of every request sent through the middleware will be affected, but all other fields will be left unchanged.

Multiple transformer middlewares may be useful in a project: to achieve this, copy laravel-transformer/src/Middleware/TransformRequest.php to your project's App/Http/Middleware directory, and rename/edit as necessary. Each new middleware will have to be registered in the kernel.

Contributing

Contributions are welcome and will be fully credited. We will accept contributions by Pull Request.

Please:

Testing

We use PHPUnit and the excellent orchestral/testbench.

Run tests using PHPUnit: vendor/bin/phpunit


All versions of laravel-transformer with dependencies

PHP Build Version
Package Version
Requires php Version ^7.0||^8.0
konsulting/laravel-extend-collections Version ^0.1
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 konsulting/laravel-transformer contains the following files

Loading the files please wait ....