Comments (4)
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.
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.
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.
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)
- Add ability to disable "Parsing File" output HOT 2
- Allow usage of debug:unassigned in CI or add `--fail-on-unassigned`
- Ability to disable `@internal` feature HOT 4
- `@template-covariant` type always appears in Uncovered HOT 9
- Ability to add custom `PhpParser\NodeVisitor` to alter AST attributes HOT 8
- Vendor folder as a layer question HOT 1
- How to install deptrac via composer HOT 7
- Version 2.0.0-alpha ignores @internal and just works with @deptrac-internal HOT 2
- Vendor directory combined with an empty composer file. HOT 1
- Uncaught Error: Typed property Qossmic\Deptrac\Core\Ast\AstMap\DependencyToken::$context must not be accessed before initialization HOT 3
- Does `functionName` only support functions with namespaces?
- Cannot configure skipViolations with DeptracConfig HOT 1
- Problem with duplicate functions and classes HOT 1
- PHP Fatal error on v2.0 (EventHelper::__construct(): Argument #1 ($skippedViolations) must be of type array, null given) HOT 3
- Unable to use custom `EventSubscriberInterface` in depfile since 2.0 as those are prefixed in the phar HOT 7
- PHP Warning: Undefined array key "internal_tag" HOT 5
- Unable to customize DIC services since 2.0
- composer doesn't allow to check exclusion from one of the packages HOT 2
- Option --version does not show correct version - ^2.0 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deptrac.