Download the PHP package markhj/collection without Composer

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

This Collection library is best thought of as an "upgraded object-oriented array".

This package provides features to write more beautiful and readable code.

Install

You can install this package to your PHP project with:

You will need Composer 2.

Example

Methods

There are examples of some of the methods further down.

Associative collection

Associative collections provide all the same functionality as the non-associative, but uses key/value pairing similar to PHP's associative arrays.

``

Language features

Typecasting

When you typecast the collection to string, it will return the JSON structure of the collection.

Iteration

You can use the ` operator on the collection instance.

Example use of other methods

map

The ` method iterates over every element of the collection, and assigns the returned value of the handler to the element in the collection. ``

forEach

The ` method is in many ways similar to the map method, but it will not assign the returned value to the element in the collection. Instead you can carry out actions which aren't directly related to the collection itself. ``

sort

The ` method sorts the collection elements by a defined handler (callable) ``

filter

The ` method removes unwanted elements from the collection. ``

retrieve

The ` method creates a new (cloned) collection based on requested elements. This allows you to extract a filtered subset of elements, without affecting the original collection itself. ``

has

The method returns true if the target item is found in the collection. `` The method can also compare objects.

hasAnyOf

``

hasAllOf

``

merge

With the ` method you can merge another collection into the current. ``

You can use the ` to protect the values of the existing collection. ``

These methods are closely related to and.

Inheritance

You can use the "out of the box" collection objects provied in the package, but in many instances it makes sense to write custom collections which inherit the Collection. This allows you to expand with relevant methods.

Validate

When you create new collections you might want to restrict it to certain data types. For this, you can override the method

By default this method always returns true - meaning it accepts any type.

You can for example limit to strings:

Or to certain class names:

If a wrong data type is passed the ` is thrown.

Examples

For example, you can create a collection of date/time objects, where you add methods to retrieve the earliest and latest instances.

Another example would be a collection of payment methods, where you add methods relevant to your business logic. It could be a boolean method to check for expired credit cards, a method to get all credit cards, or a method to retrieve default payment method.

Options

Graceful handling of missing keys

When you're working on a class inheriting the Collection object, you can set the property to true, to enable graceful handling of trying to access a collection element that doesn't exist. In normal circumstances, trying to access an element that doesn't exist will throw. If graceful handling is enabled and you try access a non-existent key ` will be returned.


All versions of collection with dependencies

PHP Build Version
Package Version
No informations.
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 markhj/collection contains the following files

Loading the files please wait ....