Skip to content

Commit db9c74b

Browse files
authored
Merge pull request #280 from phparkitect/readme-refresh
Improving README
2 parents 4da9330 + 3f574db commit db9c74b

File tree

1 file changed

+89
-73
lines changed

1 file changed

+89
-73
lines changed

README.md

Lines changed: 89 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
# PHPArkitect
1+
# 📐 PHPArkitect
22
[![Latest Stable Version](https://poser.pugx.org/phparkitect/phparkitect/v/stable)](https://packagist.org/packages/phparkitect/phparkitect) ![PHPArkitect](https://github.com/phparkitect/arkitect/workflows/Arkitect/badge.svg?branch=master)
33
[![Packagist](https://img.shields.io/packagist/dt/phparkitect/phparkitect.svg)](https://packagist.org/packages/phparkitect/phparkitect)
44
[![codecov](https://codecov.io/gh/phparkitect/arkitect/branch/main/graph/badge.svg)](https://codecov.io/gh/phparkitect/arkitect)
55

6+
7+
1. [Introduction](#introduction)
8+
1. [Installation](#installation)
9+
1. [Usage](#usage)
10+
1. [Available rules](#available-rules)
11+
1. [Rule Builders](#rule-builders)
12+
1. [Integrations](#integrations)
13+
14+
# Introduction
15+
616
PHPArkitect helps you to keep your PHP codebase coherent and solid, by permitting to add some architectural constraint check to your workflow.
717
You can express the constraint that you want to enforce, in simple and readable PHP code, for example:
818

@@ -12,8 +22,79 @@ Rule::allClasses()
1222
->should(new HaveNameMatching('*Controller'))
1323
->because("it's a symfony naming convention");
1424
```
25+
# Installation
26+
27+
## Using Composer
28+
29+
```bash
30+
composer require --dev phparkitect/phparkitect
31+
```
32+
33+
## Using a Phar
34+
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.
35+
36+
The Phar can be downloaded from GitHub:
37+
38+
```
39+
wget https://github.com/phparkitect/arkitect/releases/latest/download/phparkitect.phar
40+
chmod +x phparkitect.phar
41+
./phparkitect.phar check
42+
```
43+
44+
# Usage
45+
46+
To use this tool you need to launch a command via Bash:
47+
48+
```
49+
phparkitect check
50+
```
51+
52+
With this command `phparkitect` will search all rules in the root of your project the default config file called `phparkitect.php`.
53+
You can also specify your configuration file using `--config` option like this:
54+
55+
```
56+
phparkitect check --config=/project/yourConfigFile.php
57+
```
58+
59+
By default, a progress bar will show the status of the ongoing analysis.
60+
61+
## Configuration
62+
63+
Example of configuration file `phparkitect.php`
64+
65+
```php
66+
<?php
67+
declare(strict_types=1);
68+
69+
use Arkitect\ClassSet;
70+
use Arkitect\CLI\Config;
71+
use Arkitect\Expression\ForClasses\HaveNameMatching;
72+
use Arkitect\Expression\ForClasses\NotHaveDependencyOutsideNamespace;
73+
use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
74+
use Arkitect\Rules\Rule;
75+
76+
return static function (Config $config): void {
77+
$mvcClassSet = ClassSet::fromDir(__DIR__.'/mvc');
78+
79+
$rules = [];
80+
81+
$rules[] = Rule::allClasses()
82+
->that(new ResideInOneOfTheseNamespaces('App\Controller'))
83+
->should(new HaveNameMatching('*Controller'))
84+
->because('we want uniform naming');
85+
86+
$rules[] = Rule::allClasses()
87+
->that(new ResideInOneOfTheseNamespaces('App\Domain'))
88+
->should(new NotHaveDependencyOutsideNamespace('App\Domain'))
89+
->because('we want protect our domain');
90+
91+
$config
92+
->add($mvcClassSet, ...$rules);
93+
};
94+
```
1595

16-
## Available rules
96+
97+
# Available rules
1798

1899
Currently, you can check if a class:
19100

@@ -187,78 +268,8 @@ You can also define components and ensure that a component:
187268

188269
Check out [this demo project](https://github.com/phparkitect/arkitect-demo) to get an idea on how write rules.
189270

190-
# Installation
191-
192-
## Using Composer
193-
194-
```bash
195-
composer require --dev phparkitect/phparkitect
196-
```
197-
198-
## Using a Phar
199-
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.
200-
201-
The Phar can be downloaded from GitHub:
202-
203-
```
204-
wget https://github.com/phparkitect/arkitect/releases/latest/download/phparkitect.phar
205-
chmod +x phparkitect.phar
206-
./phparkitect.phar check
207-
```
208-
209-
# Usage
210-
211-
To use this tool you need to launch a command via Bash:
212-
213-
```
214-
phparkitect check
215-
```
216-
217-
With this command `phparkitect` will search all rules in the root of your project the default config file called `phparkitect.php`.
218-
You can also specify your configuration file using `--config` option like this:
219-
220-
```
221-
phparkitect check --config=/project/yourConfigFile.php
222-
```
223-
224-
By default, a progress bar will show the status of the ongoing analysis.
225-
226-
# Configuration
227-
228-
Example of configuration file `phparkitect.php`
229-
230-
```php
231-
<?php
232-
declare(strict_types=1);
233-
234-
use Arkitect\ClassSet;
235-
use Arkitect\CLI\Config;
236-
use Arkitect\Expression\ForClasses\HaveNameMatching;
237-
use Arkitect\Expression\ForClasses\NotHaveDependencyOutsideNamespace;
238-
use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
239-
use Arkitect\Rules\Rule;
240-
241-
return static function (Config $config): void {
242-
$mvcClassSet = ClassSet::fromDir(__DIR__.'/mvc');
243-
244-
$rules = [];
245-
246-
$rules[] = Rule::allClasses()
247-
->that(new ResideInOneOfTheseNamespaces('App\Controller'))
248-
->should(new HaveNameMatching('*Controller'))
249-
->because('we want uniform naming');
250-
251-
$rules[] = Rule::allClasses()
252-
->that(new ResideInOneOfTheseNamespaces('App\Domain'))
253-
->should(new NotHaveDependencyOutsideNamespace('App\Domain'))
254-
->because('we want protect our domain');
255271

256-
$config
257-
->add($mvcClassSet, ...$rules);
258-
};
259-
```
260-
261-
## Rule Builders
272+
# Rule Builders
262273

263274
PHPArkitect offers some builders that enable you to implement more readable rules for specific contexts.
264275

@@ -325,3 +336,8 @@ phparkitect check --config=/project/yourConfigFile.php
325336
* `--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.
326337
Supported PHP versions are: 7.1, 7.2, 7.3, 7.4, 8.0, 8.1
327338
* `--stop-on-failure`: With this option the process will end immediately after the first violation.
339+
340+
# Integrations
341+
342+
## Laravel
343+
If you plan to use Arkitect with Laravel, [smortexa](https://github.com/smortexa) wrote a nice wrapper with some predefined rules for laravel: https://github.com/smortexa/laravel-arkitect

0 commit comments

Comments
 (0)