Download the PHP package cocur/chain without Composer

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

Chain

Chain provides you with a consistent and chainable way to work with arrays in PHP.

Build Status Windows Build status Scrutinizer Code Quality Code Coverage

Made by Florian Eckerstorfer in Vienna, Europe.

Motivation

Let us be honest. Working with arrays in PHP is a mess. First of all, you have to prefix most (but not all) functions with array_, the parameter ordering is not consistent. For example, array_map() expects the callback as first parameter and the array as the second, but array_filter() expects the array as first and the callback as second. You also have to wrap the function calls around the array, the resulting code is not nice to look at, not readable and hard to understand.

Chain wraps the array in an object and gives you a chainable interface.

Take a look at the following code. How long do you need to understand it?

What about this?

Hint: It takes the diff of two arrays, intersects it with a filtered array and sums it up.

Installation

You can install Chain using Composer:

Usage

Chain allows you to create, manipulate and access arrays.

Array Creation

You can create a Chain by passing an array to the constructor.

Or with a convenient static method:

In addition a Chain can also be created by the static fill() method, which is a wrapper for the array_fill() function.

There is also a method, ::createFromString(), that creates the Chain from a string. In addition to the string you need to provide a delimiter, which is used to split the string. If the option regexp is passed in the delimiter must be a regular expression.

Array Manipulation

Chains manipulation methods manipulate the underlying array and return the object, that is, they can be chained. Most of the methods are simple wrappers around the corresponding array_ function.

In the following example ->map() is used to multiply each element by 3 and then filter the array to only contain odd elements.

When a method accepts an array (->diff() or ->intersect()) you can also pass in another instance of Chain instead of the array.

List of Array Manipulation Methods

All of these methods manipulate the array, but not all of them return an instance of Cocur\Chain\Chain. For example, ->shift() removes the first element from the array and returns it.

Array Access

Most importantly you can access the underlying array using the public array property.

Chain implements the Traversable interface.

It also implements the ArrayAccess interface allowing to access elements just like in any normal array.

Additionally Chain contains a number of methods to access properties of the array. In contrast to the manipulation methods these methods return a value instead of a reference to the Chain object. That is, array access methods are not chainable.

List of Array Access Methods

Author

Chain has been developed by Florian Eckerstorfer (Twitter) in Vienna, Europe.

Chain is a project of Cocur. You can contact us on Twitter: @cocurco

Support

If you need support you can ask on Twitter (well, only if your question is short) or you can join our chat on Gitter.

Gitter

In case you want to support the development of Chain you can send me an Euro or two.

Change Log

Version 0.9.0 (19 July 2020)

Version 0.8.0 (12 September 2019)

Version 0.7.0 (11 November 2018)

Version 0.6.0 (5 April 2018)

Version 0.5.0 (4 December 2017)

Version 0.4.1 (4 December 2017)

Version 0.4.0 (22 September 2017)

Version 0.3.0 (7 September 2017)

Version 0.2.0 (6 November 2015)

Version 0.1.0 (6 November 2015)

License

The MIT license applies to Chain. For the full copyright and license information, please view the LICENSE file distributed with this source code.


All versions of chain with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
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 cocur/chain contains the following files

Loading the files please wait ....