Download the PHP package phparkitect/phparkitect without Composer
On this page you can find all versions of the php package phparkitect/phparkitect. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phparkitect/phparkitect
More information about phparkitect/phparkitect
Files in phparkitect/phparkitect
Package phparkitect
Short Description Enforce architectural constraints in your PHP applications
License MIT
Informations about the package phparkitect
📐 PHPArkitect
- Introduction
- Installation
- Usage
- Available rules
- Rule Builders
- Integrations
Introduction
PHPArkitect helps you to keep your PHP codebase coherent and solid, by permitting to add some architectural constraint check to your workflow. You can express the constraint that you want to enforce, in simple and readable PHP code, for example:
Installation
Using Composer
Using a Phar
Sometimes your project can conflict with one or more of PHPArkitect's dependencies. In that case you may find the Phar (a self-contained PHP executable) useful.
The Phar can be downloaded from GitHub:
Usage
To use this tool you need to launch a command via Bash:
With this command phparkitect
will search all rules in the root of your project the default config file called phparkitect.php
.
You can also specify your configuration file using --config
option like this:
By default, a progress bar will show the status of the ongoing analysis.
Using a baseline file
If there are a lot of violations in your codebase and you can't fix them now, you can use the baseline feature to instruct the tool to ignore past violations.
To create a baseline file, run the check
command with the generate-baseline
parameter as follows:
This will create a phparkitect-baseline.json
, if you want a different file name you can do it with:
It will produce a json file with the current list of violations.
If is present a baseline file with the default name will be used automatically.
To use a different baseline file, run the check
command with the use-baseline
parameter as follows:
To avoid using the default baseline file, you can use the skip-baseline
option:
Line numbers in baseline
By default, the baseline check also looks at line numbers of known violations. When a line before the offending line changes, the line numbers change and the check fails despite the baseline.
With the optional flag ignore-baseline-linenumbers
, you can ignore the line numbers of violations:
Warning: When ignoring line numbers, phparkitect can no longer discover if a rule is violated additional times in the same file.
Configuration
Example of configuration file phparkitect.php
PHPArkitect can detect violations also on DocBlocks custom annotations (like @Assert\NotBlank
or @Serializer\Expose
).
If you want to disable this feature you can add this simple configuration:
Available rules
Hint: If you want to test how a Rule work, you can use the command like phparkitect debug:expression <RuleName> <arguments>
to check which class satisfy the rule in your current folder.
For example: phparkitect debug:expression ResideInOneOfTheseNamespaces App
Currently, you can check if a class:
Depends on a namespace
Doc block contains a string
Doc block not contains a string
Extend another class
Has an attribute (requires PHP >= 8.0)
Have a name matching a pattern
Implements an interface
Not implements an interface
Is abstract
Is trait
Is final
Is readonly
Is interface
Is enum
Is not abstract
Is not trait
Is not final
Is not readonly
Is not interface
Is not enum
Not depends on a namespace
Not extend another class
Don't have dependency outside a namespace
Not have a name matching a pattern
Reside in a namespace
Not reside in a namespace
You can also define components and ensure that a component:
- should not depend on any component
- may depend on specific components
- may depend on any component
Check out this demo project to get an idea on how write rules.
Rule Builders
PHPArkitect offers some builders that enable you to implement more readable rules for specific contexts.
Component Architecture Rule Builder
Thanks to this builder you can define components and enforce dependency constraints between them in a more readable fashion.
Excluding classes when parser run
If you want to exclude some classes from the parser you can use the except
function inside your config file like this:
You can use wildcards or the exact name of a class.
Optional parameters and options
You can add parameters when you launch the tool. At the moment you can add these parameters and options:
-v
: with this option you launch Arkitect with the verbose mode to see every parsed file-
--config
: with this parameter, you can specify your config file instead of the default. like this: --target-php-version
: With this parameter, you can specify which PHP version should use the parser. This can be useful to debug problems and to understand if there are problems with a different PHP version. Supported PHP versions are: 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2--stop-on-failure
: With this option the process will end immediately after the first violation.
Run only a specific rule
For some reasons, you might want to run only a specific rule, you can do it using runOnlyThis
like this:
Integrations
Laravel
If you plan to use Arkitect with Laravel, smortexa wrote a nice wrapper with some predefined rules for laravel: https://github.com/smortexa/laravel-arkitect
All versions of phparkitect with dependencies
symfony/finder Version ^3.0|^4.0|^5.0|^6.0|^7.0
symfony/event-dispatcher Version ^3.0|^4.0|^5.0|^6.0|^7.0
symfony/console Version ^3.0|^4.0|^5.0|^6.0|^7.0
symfony/polyfill-php80 Version ^1.20
nikic/php-parser Version ~4
webmozart/assert Version ^1.9
ext-json Version *
phpstan/phpdoc-parser Version ^1.2
ondram/ci-detector Version ^4.1