arkitect
arkitect copied to clipboard
Only depends on components
onlyDependOnComponents
Q | A |
---|---|
New Feature | yes |
RFC | no |
BC Break | no |
Summary
Some classes should ONLY depends on others components.
For example, i have this situation to validate...

Filters
Appliers : the filtering logic
StockModel
StockSku
Shared : all logic that allow filters work
StockModel & StockSku should only have 2 files that
- Has a suffix of Applier and DTO
- Depends ONLY to the Shared classes
Is it possible to do with the rules already written? If not, do you think is a possible new good feature?
Thank you so much!
Hi @alessandro-candon, thanks for this issue, it's very interesting what you want to achieve.
- At the moment we don't have the rule to specify if it's inside a class there is a specific number of files or more than one suffix
- for this rule I usually use
DependsOnlyOnTheseNamespaces
but I think that in your example we need more than that right?
I think that we need to implement something, we can try to write an example of a config file to achieve the rules that you want @alessandro-candon
After that, we can try to implement what is necessary.
@fain182 @micheleorselli @pfazzi any different suggestions?
I think, as you say, it's complex than I thought.
I try to write a rule that can explain what we need :
$try = Architecture::withComponents()
->component('FilterApplier')->definedBy('App\Filters\Appliers\**\**\*FilterApplier')
->component('FilterDto')->definedBy('App\Filters\Appliers\**\**\*FilterDto')
->component('FilterShared')->definedBy('App\Filters\Shared\*')
->where('FilterApplier')->onlyDependOnComponents('FilterDto', 'FilterShared')
->rules();
So, maybe what we need is
- support
definedBy
with regex - introduce
onlyDependOnComponents
to block every type of dependency with other classes...
An other possibility is to introduce AND
OR
operator in this way you define some rules that exists at the same time...
It could be a good idea...
Just to understand you better @alessandro-candon which is the problem that made you think "I need to check this DTO/Applier achitecture"? Did you find some Applier which depended on each other? Did you find an Applier without a DTO? Or some other bug?
First of all the naming convention for me is mandatory to be respected... we find a lot of "errors" on that (typo and superficiality)... And if it is possible is very interesting also to have a "dependency" validation, we find some DTOs that depends on service that is not allowed...
@alessandro-candon So if I understood well, we need:
-
onlyDependOnComponents
rule
definedBy
with regexp is already implemented as you can see into this test file: https://github.com/phparkitect/arkitect/blob/main/tests/Unit/Architecture/ArchitectureTest.php
Without using components there is the possibility already to say that a namespace depends only on a specific namespace and we have filters with regexp
@alessandro-candon in this PR #278 I am trying to add the shouldOnlyDependOnComponents
that can solve your problem maybe. What do you think?
@alessandro-candon we released version 0.2.28
with the new architectural filter.
Can you please give us feedback about your problem?
Then we can understand together what could be the next step
Hi @AlessandroMinoccheri, I'm really sorry about my response delay... I'll introduce the filter and try if it is enough! For the moment thank you so much for your grate work!
No problem for the delay @alessandro-candon! Let me know if we can do something for your project, at the moment I keep the issue open and I am waiting for your feedback :)