Download the PHP package cooper/hyperf-collection-macros without Composer

On this page you can find all versions of the php package cooper/hyperf-collection-macros. 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 hyperf-collection-macros

A set of useful Hyperf collection macros

Tests

Latest Stable Version

Total Downloads

This repository contains some useful collection macros.

Installation

You can pull in the package via composer:

The package will automatically register itself.

Macros

after

Get the next item from the collection.

You can also pass a second parameter to be used as a fallback.

at

Retrieve an item at an index.

second

Retrieve item at the second index.

third

Retrieve item at the third index.

fourth

Retrieve item at the fourth index.

fifth

Retrieve item at the fifth index.

sixth

Retrieve item at the sixth index.

seventh

Retrieve item at the seventh index.

eighth

Retrieve item at the eighth index.

ninth

Retrieve item at the ninth index.

tenth

Retrieve item at the tenth index.

getNth

Retrieve item at the nth item.

before

Get the previous item from the collection.

You can also pass a second parameter to be used as a fallback.

catch

See Try

chunkBy

Chunks the values from a collection into groups as long the given callback is true. If the optional parameter $preserveKeys as true is passed, it will preserve the original keys.

collectBy

Get an item at a given key, and collect it.

You can also pass a second parameter to be used as a fallback.

containsAny

Will return true if one or more of the given values exist in the collection.

containsAll

Will return true if all given values exist in the collection.

eachCons

Get the following consecutive neighbours in a collection from a given chunk size. If the optional parameter $preserveKeys as true is passed, it will preserve the original keys.

extract

Extract keys from a collection. This is very similar to only, with two key differences:

extract is useful when using PHP 7.1 short list() syntax.

filterMap

Map a collection and remove falsy values in one go.

firstOrFail

Get the first item. Throws Spatie\CollectionMacros\Exceptions\CollectionItemNotFound if the item was not found.

firstOrPush

Retrieve the first item using the callable given as the first parameter. If no value exists, push the value of the second parameter into the collection. You can pass a callable as the second parameter.

This method is really useful when dealing with cached class properties, where you want to store a value retrieved from an API or computationally expensive function in a collection to be used multiple times.

Occasionally, you'll want to specify the target collection to be pushed to. You may pass this as a third parameter.

fromPairs

Transform a collection into an associative array form collection item.

glob

Returns a collection of a glob() result.

groupByModel

Similar to groupBy, but groups the collection by an Eloquent model. Since the key is an object instead of an integer or string, the results are divided into separate arrays.

Full signature: groupByModel($callback, $preserveKeys, $modelKey, $itemsKey)

head

Retrieves first item from the collection.

if

The if macro can help branch collection chains. This is the signature of this macro:

$if, $then and $else can be any type. If a closure is passed to any of these parameters, then that closure will be executed and the macro will use its results.

When $if returns a truthy value, then $then will be returned, otherwise $else will be returned.

Here are some examples:

When a closure is passed to $if, $then or $else, the entire collection will be passed as an argument to that closure.

ifAny

Executes the passed callable if the collection isn't empty. The entire collection will be returned.

ifEmpty

Executes the passed callable if the collection is empty. The entire collection will be returned.

insertAfter

Inserts an item after the first occurrence of a given item and returns the updated Collection instance. Optionally a key can be given.

insertAfterKey

Inserts an item after a given key and returns the updated Collection instance. Optionally a key for the new item can be given.

insertAt

Inserts an item at a given index and returns the updated Collection instance. Optionally a key can be given.

insertBefore

Inserts an item before the first occurrence of a given item and returns the updated Collection instance. Optionally a key can be given.

insertBeforeKey

Inserts an item before a given key and returns the updated Collection instance. Optionally a key for the new item can be given.

none

Checks whether a collection doesn't contain any occurrences of a given item, key-value pair, or passing truth test. The function accepts the same parameters as the contains collection method.

path

Returns an item from the collection with multidimensional data using "dot" notation. Works the same way as native Collection's pull method, but without removing an item from the collection.

pluckMany

Returns a collection with only the specified keys.

pluckToArray

Returns array of values of a given key.

prioritize

Move elements to the start of the collection.

recursive

Convert an array and its children to collection using recursion.

rotate

Rotate the items in the collection with given offset

sectionBy

Splits a collection into sections grouped by a given key. Similar to groupBy but respects the order of the items in the collection and reuses existing keys.

Full signature: sectionBy($callback, $preserveKeys, $sectionKey, $itemsKey)

sliceBefore

Slice the values out from a collection before the given callback is true. If the optional parameter $preserveKeys as true is passed, it will preserve the original keys.

tail

Extract the tail from a collection. So everything except the first element. It's a shorthand for slice(1)->values(), but nevertheless very handy. If the optional parameter $preserveKeys as true is passed, it will preserve the keys and fallback to slice(1).

toPairs

Transform a collection into an array with pairs.

transpose

The goal of transpose is to rotate a multidimensional array, turning the rows into columns and the columns into rows.

weightedRandom

Returns a random item by a weight. In this example, the item with a has the most chance to get picked, and the item with c the least.

Alternatively, you can pass a callable to get the weight.

withSize

Create a new collection with the specified amount of items.

License

The MIT License (MIT). Please see License File for more information.


All versions of hyperf-collection-macros with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
hyperf/utils Version ~2.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 cooper/hyperf-collection-macros contains the following files

Loading the files please wait ....