Download the PHP package crell/ordered-collection without Composer

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

Ordered Collection

Latest Version on Packagist Total Downloads

Ordered Collection is what it says on the tin; it's a flexible tool for ordering arbitrary items based on either priority values or topological sorting (before/after). It contains two implementations, OrderedCollection and MultiOrderedCollection. The former is a bit faster, while the latter is considerably more powerful.

For more on Priority and Topological sorting, see this benchmark blog post comparing the results.

OrderedCollection

OrderedCollection supports ordering items by integer priorities, or a single before/after value. Internally, it converts the before/after information into priority values, and then sorts the whole list by priority. This is often faster than sorting topologically, but does not handle more than a single before/after entry per item, and cannot detect cyclic dependencies in the before/after ordering.

To use it first, create a new collection:

Now, arbitrary items may be added to the collection with addItem(), addItemBefore(), and addItemAfter(). Each item may be an arbitrary value, and they do not need to be of the same type.

When adding an item, you may provide an $id. If you do not, one will be created on the fly. The ID that was used will be returned by the addItem*() method. The ID is necessary for before/after ordering. If the ID is already in use, a numeric suffix will be added automatically to ensure uniqueness.

Once the items are added, they will be sorted automatically the first time the collection is iterated. OrderedCollection implements \IteratorAggregate, so you can use either foreach() or iterator_to_array() to get values back out.

In this case, would give the following output:

MultiOrderedCollection

This second, more robust option is very similar to OrderedCollection, and both implement the same OrderableCollection interface. However, MultiOrderedCollection has an additional method, add(), that can handle priority, before, and after ordering, and supports multiple before/after entries on the same item. For that reason, using add() with MultiOrderedCollection is recommended, though the common interface will still work on both.

MultiOrderedCollection converts all priorities into "before" entries, and then sorts the collection topologically. This can be a little bit slower, but it supports multiple before/after directives on a single item and will also detect circular dependencies, which triggers a CycleFound exception.

The add() method's signature is like so:

The return value is the ID that was assigned to the value, which may then be used in before/after ordering. Of note, the $before and $after parameters take an array, not a single ID. Also, because there are so many options, using named arguments is strongly recommended.

The example above, on MultiOrderedCollection, would look like this:

In this case, the output would be the same as before.

Guarantees

OrderedCollection and MultiOrderedCollection provide the following guarantees about the resulting list of values returned:

They do not provide the following guarantees, so while they may happen you should not count on them.

Types

The items being sorted are not used at all during the process. While the example above shows strings, you can use arrays, objects, strings, numbers, or whatever else you'd like. They may be of the same type, or different types. The collection objects don't care.

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

Contributing

Please see CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please use the GitHub security reporting form rather than the issue queue.

Credits

License

The Lesser GPL version 3 or later. Please see License File for more information.


All versions of ordered-collection with dependencies

PHP Build Version
Package Version
Requires php Version ~8.1
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 crell/ordered-collection contains the following files

Loading the files please wait ....