Download the PHP package yoshi2889/collections without Composer

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

Collections

Build Status Scrutinizer Code Quality Scrutinizer Code Coverage Latest Stable Version Latest Unstable Version Total Downloads

Simple Collection class allowing storage of specific data, based on PHP's ArrayObject.

Installation

You can install this class via composer:

Usage

To use a Collection, create a new instance:

Note that the closure passed as the first parameter to the Collection constructur MUST return a boolean value. This function is used to validate any added data types. A returned value of true means the given value may be added to the collection.

The second parameter can contain any initial values which should be in the collection. These items will also be validated.

Validating

Data is validated using a Closure instance, or a callback. The given closure must support exactly 1 untyped(!) parameter and return a boolean value. Values for which the closure returns false will be denied with an \InvalidArgumentException.

Please note that only the values are validated, while keys are not.

Validation can be manually performed on values using the ->validateType($value) and ->validateArray(array $array) methods, which check a single value and an array of values respectively.

->validateType($value) will return boolean true if the value passes validation, and false if it does not.

->validateArray(array $array) will return boolean true if all the values pass validation, and false if one or more do not.

Manipulation

A Collection instance may be treated like a generic array. This means you can manipulate it like the following example:

Please note that any data entered this way will still be validated and may still throw an \InvalidArgumentException.

Furthermore, to remove data from the Collection you may use the ->offsetUnset($index) and ->removeAll($value) methods.

->offsetUnset($index) will remove the value located at key $index, which works similarly to using unset($collection['key']).

->removeAll($value) will remove every value which is equal to $value from the collection. Because values may exist multiple times in the same Collection, it is not possible to reliably remove only a single value from the collection using a value; consider removing by key instead. If you wish to preserve the original values while creating a new instance without certain values, please refer to Filtering below.

Filtering

A Collection can be filtered using the ->filter(\Closure $condition) method. The given closure MUST return a boolean value.

The condition closure is called for every element in the collection. Any elements for which the closure returns true will be kept and put in a new Collection instance, which will be returned. For example, to filter out all elements which are NOT foo:

Events

A Collection will emit a changed event if data gets added to or removed from it. No arguments are passed. This functionality is borrowed from Événement by igorw.

You can subscribe to the event using the ->on($event, callable $listener) method, like so:

Validation Closures

You can find a lot of closures and utilities which can be used by a Collection in the separate validation-closures project.

License

This code is released under the MIT License. Please see LICENSE to read it.


All versions of collections with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2.0
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 yoshi2889/collections contains the following files

Loading the files please wait ....