Download the PHP package benconda/collection without Composer

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

Collection

Collection library, powered by generators, with generics, easily extendable and immutable. Lazy by design and memory friendly. Accept anything as iterable 🔥 (Generator, array, Iterator, ...)

Requirement

To use this library you need at least php 8.2

Usage

You first need to create the collection from an iterable, it can be an array, or anything that is iterable (generators, objects iterators, etc)

Now you can apply one or multiple Modifier to it :

Each time you call a modifier method it returns a new instance of the collection, nothing is override.

The collection is invokable, so you can add modifiers like this too :

Because each modifier rely on generators, nothing is done until you start to iterate on the collection.

You can get the first value like this :

Note that it won't go through the whole array to return the first value, behind the scene it only iterate through 1,2,3,4,5 => The number is 5 and stop.

This is possible thanks to generators, most other Collection libraries will need to loop through the whole array to filter it, then Map every filtered value before you can get the first value.

We can iterate on all value using a foreach directly on the collection $object :

And you can translate the whole Collection into an array like this :

Be careful, by design we accept anything as a key, array restrict keys to int|string type, if the key type mismatch, it will fallback to int incremented key.

Modifiers

Collection iteration can be altered using modifiers, which allow you to shape and transform data in a memory friendly way.

Some modifiers require some memory buffering, and are split in another namespace called BufferedModifier. This is the case for example with BenConda\Collection\BufferedModifier\Reverse, in order to reverse, the whole collection need to be loaded in memory.

So keep in mind, BufferedModifier namespace = will consume memory depending on the size of the iterable.

You will find the modifiers list in this documentation

Note : documentation is in progress

Extend

Add custom modifier

Simply create a class that implement BenConda\Collection\Modifier\ModifierInterface

For example, for the reindex modifier :

If you need some configuration, simply add a constructor to the class.

Using your own collection class

Sometimes you need to create your own, strict typed Collection class.

To do so, you can extend the CoreCollection class, and implement only the needed modifier method.

Sometimes you may need to have mutable custom Collection, for this use case you can extend MutableCoreCollection. You will find an example in this test

Note that even with mutable Collection, you still rely on Generators behind so each time you modify your collection, nothing is really done until you loop through it.


All versions of collection with dependencies

PHP Build Version
Package Version
Requires php Version ^8.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 benconda/collection contains the following files

Loading the files please wait ....