Git Product home page Git Product logo

Comments (4)

patrickkusebauch avatar patrickkusebauch commented on June 9, 2024 1

Hi,
I see what you are trying to do here, as I personally also structure my projects into modules as you are describing here.

I can share my experience, and how I solve this problem with the current capabilities of deptrac. To me, what are you trying to achieve is too complex for a mark-up language like YAML. Luckily, deptrac also provides a way to specify configuration via PHP. And I think for your use case, it is a natural fit.

    $finder = \Nette\Utils\Finder::findDirectories('*')->from('src'); //to get all your modules
    foreach($finder as $module) {
        //specify layers that are present for each module
        //specify rulesets that are present between modules and within modules
        //(optionally) specify formatter groups for Graphviz to have nicer graphs
    }

I take it a step further and have a deptrac.php file for each module like this:

//top project level config
    $finder = \Nette\Utils\Finder::findFiles('*/deptrac.php')->from('src');

    foreach ($finder as $file) {
        require_once $file->getPathname();
        $namespace = str_replace('src/', '\\My\\Namespace\\', $file->getPath());
        $layers = $namespace . '\\layers';
        $config->layers(...$layers());
        $rulesets = $namespace . '\\rulesets';
        $config->rulesets(...$rulesets());
        $graphvizFormat = $namespace . '\\graphvizFormat';
        $graphvizFormat($formatter);
    }

// deptrac.php in each module
/**
 * @return list<Layer>
 */
function layers(): array
{
    return [
        Layer::withName('Branding')
            ->collectors(
                DirectoryConfig::create('src/Branding/.*'),
                ClassLikeConfig::create('^Nette\\Routing\\.*'),
                ComposerConfig::create()
                    ->addPackage('contributte/menu-control')
                    ->addPackage('nette/routing')
            ),
    ];
}

/**
 * @return list<Ruleset>
 */
function rulesets(): array
{
    return [
        Ruleset::forLayer(Layer::withName('Branding'))
            ->accesses(
                Layer::withName('Generic Domain'),
                Layer::withName('Nette'),
                Layer::withName('Logging'),
                //and more
            ),
    ];
}

function graphvizFormat(GraphvizConfig $graphvizConfig): void
{
    $graphvizConfig->hiddenLayers(Layer::withName('Branding'));
}

from deptrac.

plumthedev avatar plumthedev commented on June 9, 2024

Looks great, however I see that $config and $formatter are not defined at top level config.

CLI

sail@f7adfa5bd9b5:/var/www/html$ ./vendor/bin/deptrac --config-file=deptrac.php 
PHP Warning:  Undefined variable $config in /var/www/html/deptrac.php on line 21
PHP Warning:  Undefined variable $formatter in /var/www/html/deptrac.php on line 2

/var/www/html/deptrac.php

<?php

declare(strict_types = 1);

$finder = \Nette\Utils\Finder::findFiles('*/deptrac.php')->from('app');

foreach ($finder as $file) {
    require_once $file->getPathname();
    $namespace = str_replace('src/', '\\My\\Namespace\\', $file->getPath());

    $layers = $namespace . '\\layers';
    $config->layers(...$layers());

    $rulesets = $namespace . '\\rulesets';
    $config->rulesets(...$rulesets());

    $graphvizFormat = $namespace . '\\graphvizFormat';
    $graphvizFormat($formatter);
}

dd($config, $formatter);

Am I doing something wrong? Do you have any examples in docs?

from deptrac.

patrickkusebauch avatar patrickkusebauch commented on June 9, 2024

You can reference https://github.com/qossmic/deptrac/blob/2.0.x/docs/blog/2023-05-11_PHP_configuration.md or https://github.com/qossmic/deptrac-src/blob/2.0.x/deptrac.config.php.

From there, you should be able to get the $config. For formatter - $formatter = GraphvizConfig::create().

from deptrac.

plumthedev avatar plumthedev commented on June 9, 2024

Thanks @patrickkusebauch
It looks definitely like something what fulfill my needs and will be enough here.
I will present my solution when it will be built and ready, for now we can close this thread!

from deptrac.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.