Download the PHP package fusion-php/collection without Composer

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

Fusion.Collection

Scrutinizer Code Quality Code Coverage Build Status

This package provides a small collection library useful for aggregating data values in an object. Stored values can be accessed via methods, loops, or as an array.

Requirements

PHP 7.4 or greater.

Installation

This package is installed via Composer.

Usage

The library provides two different types of a collection. A basic object, simply Collection, and a Dictionary. There are two variants of these called TypedCollection and TypedDictionary which are meant for storing instances of specific object types.

Instantiation

Creating any of the collection objects this library provides can be done via constructor or with the CollectionFactory class. The remainder of this section will assume the usage of the CollectionFactory class to create collection objects. For information about instantiation via constructor please see the Manual Instantiation section below.

The Collection Class

The Collection object will hold any value that a PHP array can hold, with the exception of null values.

A Collection can be instantiated empty or with an array of starting elements. In the latter scenario existing keys in the array are ignored.

As seen above, the count() method returns an integer with the number of items in the collection. The collection utilizes the Countable interface allowing you to obtain the collection size via the PHP count() method as an alternative means.

To add items to the collection use the add() method passing in the value you wish to store.

Use the find() method with an existing index to retrieve a value from the collection.

The collection can have values replaced by calling the replace() method and providing the index of the value to be replaced and the replacement value.

To remove items from the collection use the remove() method passing in the value to remove.

With the remove() method all values identical to the argument given are removed. This means that any duplicates of literal values or objects of the same instance are also removed. To remove a specific value use the removeAt() method passing in the numerical index of the value's location.

Both the remove() and removeAt() methods will cause the numerical index of the collection to update closing any gaps in the index sequence.

To empty out a collection simply call the clear() method.

Iteration and Direct Access

The Collection instances can make use of ArrayAccess and Iterator. This means that you can use a collection as the subject of a for or foreach.

You can also access items and replace items directly via their index if they already exist.

Feel free to remove items in this way via an unset() call with a value's index number.

The Dictionary Class

A Dictionary is very similar to a Collection with the main difference being that a Dictionary only accepts index values (called keys from here on) as strings. A Dictionary will hold any value that a PHP array can hold, with the exception of null values.

A Dictionary can be instantiated empty or with an array of starting elements. In the latter scenario existing keys in the array are not ignored, but they must be strings.

As seen above the count() method can be used to gather the number of items in the dictionary and, as with the Collection class, this can also be obtained using the PHP count() method.

Items can be added to the dictionary with the add() method specifying the key to store them under.

Items can be replaced at a given key as well.

The find(), remove(), removeAt(), and clear() methods in the Dictionary class work exactly the same as they do under the Collection class, with the find() and removeAt() methods requiring their parameters to be strings instead of integers.

Iteration and Direct Access

The Dictionary class also leverages the ArrayAccess and Iterator interfaces allowing looping.

The values in a Dictionary can also be accessed directly via their key offset.

Removing an item directly can be done with unset().

Values can also be replaced directly at their offset and in addition new items can be added directly at their offset.

The TypedCollection and TypedDictionary Classes

In certain cases it may be desired to have a collection or dictionary that stores only object references of a specific type. In these cases a TypedCollection or TypedDictionary may be used.

Both classes are children of the Collection and Dictionary classes, respectively, and can be constructed with an optional set of starter items. However, the only required parameter during instantiation is the fully qualified name of the class or interface that is acceptable.

The TypedDictionary variant is similar, however string keys are required.

As with the standard Collection and Dictionary classes, null values are not allowed.

Exception Cases

The library defines the exception CollectionException, which is thrown in the following cases:

Collection

TypedCollection

Dictionary

TypedDictionary

Manual Instantiation

Each of the collection objects in this library can be instantiated manually using their constructor versus the CollectionFactory class. The constructor signatures are similar to those found in the factory versions with the exception of an added parameter, an instance of the CollectionValidationInterface, which takes care of integrity checks for collection operations.

Each of the constructor signatures are as follows:

The library provides an implementation of the CollectionValidationInterface in the form of the CollectionValidator class. Below is the alternative method of creating collection objects:

The above pattern holds true for the remaining collection objects. Simply create an instance of the CollectionValidationInterface and pass it as the first parameter to the constructor.


All versions of collection with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
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 fusion-php/collection contains the following files

Loading the files please wait ....