{"id":27078938,"url":"https://github.com/netlogix/task-graph-solver","last_synced_at":"2025-04-06T01:20:06.443Z","repository":{"id":205737166,"uuid":"710163642","full_name":"netlogix/task-graph-solver","owner":"netlogix","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-27T13:41:32.000Z","size":719,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"develop","last_synced_at":"2025-03-27T23:47:25.162Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/netlogix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-26T06:35:42.000Z","updated_at":"2025-02-27T13:36:12.000Z","dependencies_parsed_at":"2025-02-25T16:25:28.138Z","dependency_job_id":"55925a1c-601f-4ae9-b93b-3914a0588eef","html_url":"https://github.com/netlogix/task-graph-solver","commit_stats":null,"previous_names":["netlogix/task-graph-solver"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netlogix%2Ftask-graph-solver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netlogix%2Ftask-graph-solver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netlogix%2Ftask-graph-solver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netlogix%2Ftask-graph-solver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/netlogix","download_url":"https://codeload.github.com/netlogix/task-graph-solver/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247421043,"owners_count":20936217,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-06T01:20:05.901Z","updated_at":"2025-04-06T01:20:06.404Z","avatar_url":"https://github.com/netlogix.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Task Graph Solver\nThe Task Graph Solver Package is a PHP library that provides a mechanism for resolving dependencies between tasks represented as a directed acyclic graph (DAG).\n\nIt helps you manage and execute tasks that are dependent on each other and ensures that the tasks are executed in the correct order to resolve their dependencies.\n\n## Installation\nYou can install this package using Composer:\n\n```bash\ncomposer require netlogix/task-graph-solver\n```\n\n## Components\n\n### Task\nYou can use the simple [`Task`](src/Task.php) implementation or create your own task based on the [`TaskInterface`](src/TaskInterface.php).\n\nIf you want to execute a task multiple times, you can implement the [`ResettableTaskInterface`](src/ResettableTaskInterface.php) and reset the task to its initial state using the `reset()` method.\n\n### TaskPool\nTasks are managed by a TaskPool, you can use the bas [`TaskPool`](src/TaskPool.php) implementation or create your own TaskPool based on the [`TaskPoolInterface`](src/TaskPoolInterface.php).\nThe TaskPool is responsible for storing and providing access to your defined tasks.\n\n### TaskGraph\nThe TaskGraph class is used to resolve the task dependencies. It takes a TaskPool as input and can be iterated to get the tasks in the correct resolution order, considering their dependencies. It also checks for cyclic dependencies and prevents infinite loops.\n\n\n## Usage\n\n```php\nuse Netlogix\\DependencyResolver\\TaskGraph;\n\n$taskGraph = new TaskGraph($taskPool);\n\nforeach ($taskGraph as $resolutionBatch) {\n        foreach ($resolutionBatch as $task) {\n        // Execute the task or do any necessary operations.\n        $task-\u003eresolve();\n    }\n}\n```\n\n### Resetting Tasks\nIf your TaskPool implements the ResettableTaskPoolInterface, you can reset all tasks to their initial state for re-execution using the resetPool() method of the TaskGraph:\n\n```php\n$taskGraph-\u003eresetPool();\n```\n\n## Example\n\nHere is a simple example that shows how to use the TaskGraph to resolve the dependencies between tasks and generate a [mermaid](https://mermaid.js.org/) state diagram.\n\n```php\n\u003c?php\n\nrequire_once __DIR__ . '/vendor/autoload.php';\n\nuse Netlogix\\DependencyResolver\\Task;\nuse Netlogix\\DependencyResolver\\TaskPool;\nuse Netlogix\\DependencyResolver\\TaskGraph;\n\n$graph = new TaskGraph(\n    new TaskPool([\n        new Task('TaskA'),\n        new Task('TaskB', ['TaskA']),\n        new Task('TaskC', ['TaskA']),\n        new Task('TaskD', ['TaskB', 'TaskC']),\n        new Task('TaskE'),\n    ])\n);\n\n$first=true;\n$lines = ['stateDiagram'];\n$lastTasks = [];\nforeach ($graph-\u003egetIterator() as $tasks) {\n    foreach ($tasks as $name =\u003e $task) {\n        $lastTasks = array_filter($lastTasks, fn($t) =\u003e !in_array($t, $task-\u003egetDependencies()));\n        array_push($lines, ...$first ? [\"  [*] --\u003e $name\"]\n            : array_map(fn($t) =\u003e \"  $t --\u003e $name\", $task-\u003egetDependencies()));\n        $lastTasks[$name] = $name;\n        $task-\u003eresolve();\n    }\n    $first=false;\n}\nforeach ($lastTasks as $lastTask) {\n    $lines[] = \"  $lastTask --\u003e [*]\";\n}\n\necho implode(\"\\n\", $lines) . \"\\n\";\n```\n\n**Result:**\n\n```mermaid\nstateDiagram\n    [*] --\u003e TaskA\n    [*] --\u003e TaskE\n    TaskA --\u003e TaskB\n    TaskA --\u003e TaskC\n    TaskB --\u003e TaskD\n    TaskC --\u003e TaskD\n    TaskE --\u003e [*]\n    TaskD --\u003e [*]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetlogix%2Ftask-graph-solver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnetlogix%2Ftask-graph-solver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetlogix%2Ftask-graph-solver/lists"}