Download the PHP package jtl/php-generic-collection without Composer

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

Generic Collection

Build status

An implementation of generic collections in PHP using iterators. Brings type safety to your arrays without hacks or ugly code.

Usage

The primary way of using this library is to create your own collection class which extends the GenericCollection and sets its type in the constructor like so:

You can now add new items to your collection in bulk, using $collection[] = ... or by using the static from function.

Alternative you can just use the generic ObjectCollection without creating a new collection class for every object type.

Trying to add a new item that's not of the specified type will throw an InvalidArgumentException.

Advanced type checking

The default type checking function only checks if the item to be added is an instance of the given type or, if you set the type to 'string', if it is a string.
If you desire more advanced type checking you can implement your own algorithm easily.
Your custom collection class simply needs to override the checkType method and return true if the type matches or false if it doesn't.

Here's an example of a collection that only accepts even numbers.

Iterator methods

In addition to ensuring type safety the GenericCollection also implements a few methods to make working with iterators more pleasant.
Note: Some of these methods mutate the state of the collection. If this behavior is not desired you may wish to clone the collection before modifying it.

The following methods are currently implemented:

Method Explanation
each(Closure) Performs a closure on each item in the collection
map(Closure) Replaces every element in the collection with the result of the closure
filter(Closure) Modifies the collection to leave only items in the collection for which the closure returns true
clone() Clones the collection
chain(GenericCollection) Appends another collection to the end of the current collection
zip(GenericCollection) Zips another collection with the current collection
partition(Closure) Creates two collections, one for which the closure returns true and one for which the closure returns false
reduce(Closure) Reduces the collection to a final value based on a closure
all(Closure) Returns true if the closure returns true for each element, otherwise false
any(Closure) Returns true if the closure returns true for at least one element, otherwise false
find(Closure) Returns the first element for which the closure returns true
from(...$items) Create a new collection from existing items

What does zipping do?

Zipping joins two collections together so that each element of the new collection is a tuple of one element from the first, or left, collection and one element from the second, or right, collection. To keep the code readable you access the elements of the tuple using getLeft() and getRight().

Example:

Important! You can zip two collections of different types!

Unzipping

A zipped collection can be unzipped into the two original collections using the unzip() method on a zipped collection.

Building upon the previous example:

At this point $itemList1 and $unzippedItemList1 will be identical. The same is true for $itemList2 and $unzippedItemList2.

The zipped collection stores the original collection types internally so unzipping is even possible if you zip two different collection types.

License

The code is released under the MIT License.


All versions of php-generic-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 jtl/php-generic-collection contains the following files

Loading the files please wait ....