Download the PHP package pwm/deepend without Composer
On this page you can find all versions of the php package pwm/deepend. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package deepend
Short Description A simple library for scheduling dependent task execution
License MIT
Homepage https://github.com/pwm/deepend
Informations about the package deepend
DeepEnd
A library for scheduling dependent task execution.
The goal is to be able to build a network of dependent entities, eg. task ids, which can then be sorted into a correct execution order. This means that if task B depends on task A then task A comes before task B in the sorted order.
Table of Contents
- Requirements
- Installation
- Usage
- How it works
- Tests
- Changelog
- Licence
Requirements
PHP 7.1+
Installation
$ composer require pwm/deepend
Usage
Below is a simple example of creating dependencies between 4 tasks:
You can also add data (including functions and objects) to your tasks for later use. For this case use the sortToMap()
method, which returns a map with ids as keys and the added data as values. Using the above example of 4 tasks we could do the following:
How it works
When adding entries via the add()
method and arrows via the draw()
method you are actually building a graph, more specifically a directed acyclic graph (DAG), where nodes are added via add()
and edges/arrows via draw()
.
Every time you want to draw a new arrow from node A to node B DeepEnd checks whether it would create a cycle and if the answer is yes then it will tell you in the form of an exception. The way this is done is that, before drawing the arrow, DeepEnd checks whether A is already reachable from B, ie. whether there's a path from B to A. If there is, then an arrow from A to B would lead to a cycle as you can already get from B to A and then, via the new arrow, back to B.
Once you have your graph built the sort()
method can be used to do what is called a topological sort on your DAG. This is done using depth first search where DeepEnd incrementally indexes nodes as it leaves them after visiting. This is known as postordering. Once finished it will sort the nodes in reverse order, starting with nodes with the highest post order index. This results in an order where nodes that depend on other nodes come after their dependencies, which is the order we are after.
Tests
$ vendor/bin/phpunit
$ composer phpcs
$ composer phpstan
Changelog
Click here
Licence
MIT