Download the PHP package somnambulist/collection without Composer

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

Somnambulist Collection Library

GitHub Actions Build Status Issues License PHP Version Current Version

Somnambulist Collection provides a framework for making collections and pseudo sets of your own. It has been completely re-worked from the previous versions into a set of behaviours (traits) and some common interfaces grouped around function.

The basic "Collection" is an interface that extends ArrayAccess, IteratorAggregate and Countable; and adds Arrayable and Jsonable as common requirements. Then the basic methods are:

From this, additional functionality is added by interface and traits - or implement your own. The goal is to allow for a set of small, re-usable, well tested functions that can be combined to provide the functionality you need, instead of a single monolithic collection class that does everything and more.

Of course out of the box, several standard implementations are included.

This is heavily inspired by Doctrine ArrayCollection and of course Laravel Collection along with ideas from Lithium framework, ez Components, CakePHP and more.

If you see something missing or have suggestions for other methods, submit a PR or ticket! Adding functions is easy with the trait system and if you think that the groupings need work, suggest a better name!

Change History

Requirements

Installation

Install using composer, or checkout / pull the files from github.com.

Contributing

Contributions are more than welcome! Whether doc improvements, new methods or bug fixes. In all cases, fork the repository, make a branch then submit a PR - the usual GitHub flow.

Please consider the following:

Remember that the Collection could be a Set or Frozen, so often it is necessary to operate on the values and then create a new collection after processing. See the current implementations for examples.

Built-in Collections

There are several types of collection that all implement the Collection interface with varying levels of functionality:

There's no frozen set, but if you freeze a MutableSet; you have yourself a FrozenSet.

Usage

Instantiate with an array or other collection of items:

Freeze changes to a collection:

Use a custom Immutable collection class:

Dot Access

Dot access is available on:

For example: users.*.name would fetch the name from all elements in the users key space. Dot access can call into:

If the key name uses snake casing e.g.: user_address, this will be converted to UserAddress for method access checks.

A default can be supplied with get() that if the specified key does not exist, it will be used instead. The default can be a closure. Note: that this will be called for all elements e.g: users.*.age with a default that returned 0, would return 0 for all matching users without an age present.

Key walking is implemented in a standalone class allowing it to be re-used in other classes. This functionality is based on Laravel's data_get() and Arr::pluck(), modified to support getter methods and default handling when extracting from objects.

Proxy Helpers

New in v4 is an expansion of the run/map proxies used to make operations across the set. Now additional proxies can be bound to virtual properties that can be accessed at runtime. This allows for additional custom behaviour or the creation of mini Domain Specific Languages within the collection.

It is recommended when adding additional proxy options, that this is done in a child class of the collection so that the options can be documented using @property-read declarations in the class docblock. By default run and map are pre-bound in the built-in collections, however these can be overridden if necessary.

Proxies are lazy instantiated when accessed so should have a minimal impact on performance. For most cases the proxy is mapped by the full qualified class name to an alias, but for more complex construction a closure can be used.

The proxy can be called by:

For example: to run the method setDateTo() on a collection of objects that have this method:

Method Index

The collection behaviour docs are generated from the source code and are available in the docs folder.

Factory Methods

On the collection class

As helpers in the FactoryUtils

Methods by Group

Aggregates Assertable Comparable Exportable Filterable Mappable
average assert diff jsonSerialize filter collapse
max diffUsing toArray matching flatMap
median diffAssoc toJson notMatching flatten
min diffAssocUsing toQueryString reject map
modal diffKeys toString except mapInto
sum diffKeysUsing serialize has reduce
countBy intersect unserialize hasAllOf
intersectByKeys hasAnyOf
hasNoneOf
keys
keysMatching
only
with
without
matchingRule
Mutable Partitionable Queryable Runnable String Helpers
add groupBy all each capitalize
append partition contains pipe lower
concat slice doesNotContain pipeline trim
combine splice extract run upper
clear find
combine findLast
fill first
fillKeysWith get
flip last
merge has
pad random
pop removeEmpty
prepend removeNulls
push sort
remapKeys sortBy
remove value
replace values
replaceRecursively
reverse
set
shift
shuffle
union
unset
when

Magic Methods & PHP Interface Methods


All versions of collection with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
ext-json Version *
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 somnambulist/collection contains the following files

Loading the files please wait ....