Download the PHP package collab-corp/formatter without Composer

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

Input Formatter

Tests

StyleCI

A php package for formatting data/values using a laravel validation like syntax, powered by Illuminate\Support components.

Installation

composer require collab-corp/formatter

Use

The most basic use is simple, just pass your value and array of callables that your value should be called against:

Passing Arguments To Callables

You can specify arguments using a : followed by a comma delimited list e.g callable:arg1,arg2:

Note: Notice that we only specified the suffix parameter. The ValueFormatter class automatically passes your value as the first parameter to every function with the exception of delegation to objects/instances (See Using Instances section below).

What if value isnt the first parameter to my function?

No problem, you can specify what order you want your value passed by using the :value: placeholder:

For example, preg_replace accepts a value to format as the third parameter:

Whitelisting Allowed Callables

By default, all callables are allowed to be called, but if you are dynamically calling callables or want to add a protection layer, it may be worth specifying what callable functions should be allowed:

Using Instances/Object Values & Method Chaining

It is possible to pass an object/instance to the formatter and utilize any methods on that instance. Using a .<methodName> convention you can specify method chaining on that instance. For example take a Carbon instance:

Closures/Formattable Classes

You can use closures for formatting your value as well:

Or you can also implement the CollabCorp\Formatter\Support\Contracts\Formattable contract and use instances:

Optional Formatting/Blank Input

Sometimes you may only want to format a value if the value isnt null or "blank": You can specify ? anywhere in the chain of callables to specify if the formatter should break out of processing callables, often this should be defined in front of all your callables:

Note: This packages uses Laravel's blank helper to determine blank/empty values. If you have more complicated logic to break out of rules, use a closure or a Formattable class and call the 2nd argument exit callback:

Formatting multiple values

So far all the examples have been using a single value, but often times we are working with much more data from client requests. This is where the DataFormatter class is preferred:

Array Input

You may also format array data using dot notation:

Wildcard Formatting

Callables can contain wildcards as well:

This includes array input:

Concerns

If you prefer using a trait to easily create formatter instances, we provide the CollabCorp\Formatter\Support\Concerns\FormatsData trait for easy access:

Contribute

Contributions are always welcome in the following manner:

License

The project is licensed under the MIT license.


All versions of formatter with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/support Version ~7.0|^8.0|^9.0
illuminate/validation Version ~7.0|^8.0|^9.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 collab-corp/formatter contains the following files

Loading the files please wait ....