定制 sweetchuck/cdd 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sweetchuck/cdd

最新稳定版本:v2.0.0

Composer 安装命令:

composer require sweetchuck/cdd

包简介

Circular dependency detector

README 文档

README

CircleCI codecov

A lightweight PHP library for detecting circular dependencies in complex systems. This library provides a simple and efficient API to identify loops and cycles within dependency chains, making it an essential tool for maintaining clean architecture and preventing infinite loops in your applications.

When to Use

This library is ideal for projects that need to:

  • Validate dependency graphs - Ensure there are no circular references in your dependency structures
  • Build system management - Detect cycles in build task dependencies to prevent infinite loops
  • Module/package validation - Verify that plugin systems or modular architectures don't have circular imports
  • Code analysis tools - Power dependency analysis features in linters and static analysis tools
  • Architecture enforcement - Maintain strict layered architecture by preventing unwanted circular dependencies
  • Plugin systems - Validate plugin dependencies before loading them

Features

  • Zero runtime dependencies - lightweight and dependency-free
  • Detects complex cycles - identifies loops of any depth
  • Returns cycle paths - shows exactly which items form the cycle

Usage

<?php

declare(strict_types = 1);

use Sweetchuck\cdd\CircularDependencyDetector;

$detector = new CircularDependencyDetector();

$items = [
    // Item "a" has no any dependencies.
    'a' => [],

    // Item "b" depends on "c" and "d".
    'b' => ['c', 'd'],

    // Item "c" has no any dependencies.
    'c' => [],

    // Item "d" has no any dependencies.
    'd' => [],
];

$loops = $detector->detect($items);

/**
 * $loops = [];
 */
var_dump($loops);

$items = [
    // Item "a" depends on "b".
    'a' => ['b'],

    // Item "b" depends on "a".
    'b' => ['a'],
];

$loops = $detector->detect($items);

/**
 * $loops = [
 *   'a|b' => ['b', 'a', 'b'],
 * ];
 */
var_dump($loops);

$items = [
    // Item "a" depends on "b".
    'a' => ['b'],

    // Item "b" depends on "c".
    'b' => ['c'],

    // Item "c" depends on "a".
    'c' => ['a'],
];

$loops = $detector->detect($items);

/**
 * $loops = [
 *   'a|b|c' => ['c', 'a', 'b', 'c'],
 * ];
 */
var_dump($loops);

统计信息

  • 总下载量: 275.43k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2018-11-30