@@ -7,76 +7,112 @@ Package for your app – it allows your App to check himself has consistent vend
77For small teams can be difficult to cooperate and keep ` /vendor ` directory synchronized with requirements
88in ` composer.json ` . Your colleagues can be a junior or can be not accustomed to right use the Composer.
99
10- You can force refresh Composer via git-hooks, or push all ` /vendor ` into your repo, but it's very dirty way.
11- Don't do it!
10+ You can force refresh Composer via git-hooks, but it requires careful preparation on each developer station.
11+ You can push all ` /vendor ` into your repo, but it's very very dirty way. Don't do it!
1212
1313Or… just add this package to you project. It checks if you ` /vendor ` is consistent with project and can
1414notify you and your colleagues to forgotten refresh.
1515
1616## Usage
1717Add this package to project as dev-dependency:
18- ``` bash
19- composer require --dev jakubboucek/composer-vendor -checker
18+ ``` shell
19+ composer require --dev jakubboucek/composer-consistency -checker
2020```
2121
22- In your app just call ` validateReqs ()` method:
22+ In your app just call ` validate ()` method:
2323``` php
2424<?php
25- use JakubBoucek\ComposerConsistency\Checker ;
25+ use JakubBoucek\ComposerConsistency\ComposerConsistency ;
2626
27- Checker::validateReqs (__DIR__);
27+ ComposerConsistency::rootDir (__DIR__)->validate( );
2828```
2929
3030When ` /vendor ` is not consistent with ` composer.json ` , checker throws an Exception.
3131
3232![ Exception from Checker] ( https://cdn.jakub-boucek.cz/screenshot/190703-jptvw.png )
3333
34- ## Modes
34+ ## Usage
35+
36+ ``` php
37+ use JakubBoucek\ComposerConsistency\ComposerConsistency;
38+
39+ \JakubBoucek\ComposerConsistency\ComposerConsistency::rootDir(__DIR__)
40+ ->validate();
41+ ```
42+
43+ ### Directories
44+ - ** Root dir** - directory which contains ` composer.json ` , rspt. ` composer.lock ` file,
45+ usually root directory od project.
46+ - ** Vendor dir** - directory which contains Composer's ` autoload.php ` file.
47+
48+ By default checker is assumes Verdor dir at ` vendor/ ` from root dir, you can change by method ` vendorDir() ` .
3549
36- ### Strict/Lax mode
37- Nehlásí chybu, pokud nenajde soubory
50+ ``` php
51+ \JakubBoucek\ComposerConsistency\ComposerConsistency::rootDir(__DIR__)
52+ ->vendorDir(__DIR__ . '/../vendor')
53+ ->validate();
54+ ```
3855
39- POPZOR? výchozéí stan není striktní - vysvětlit v readme
56+ ### Error severity
57+ When checker detects incosistence, it throws ` ComposerInconsitencyException ` .
4058
41- ### Silent mode
42- Vyhodí pouze chybu E_USER_ERROR, ne vyjímku
59+ You can change exception throwing to emit user error by method ` errorMode($severity) ` where ` $severity ` is Severity of
60+ emitted error, default is ` E_USER_ERROR ` , you can change it to any of ` E_USER ` family severity
61+ ([ read more] ( https://www.php.net/manual/en/function.trigger-error.php#refsect1-function.trigger-error-parameters ) ).
4362
4463``` php
45- Composer::validateConsistency($rootDir, $vendorDir, true, false);
46- (new Composer($rootDir))->strict(false)->validate($debugMode, E_USER_ERROR);
64+ \JakubBoucek\ComposerConsistency\ComposerConsistency::rootDir(__DIR__)
65+ ->errorMode(E_USER_WARNING)
66+ ->validate();
4767```
4868
49- ### Warning
50- Because you install Checker as dev-dependency, you should be very careful to hard-linking dependency
51- insinde your App. Is highly recommended to call validation only on development stage, not on production:
69+ Also you can disable checking by ` errorMode(false) ` – that's cause to completelly disable checking.
5270
5371``` php
54- if(Debugger::$productionMode === false) {
55- Checker::validateReqs(__DIR__);
56- }
72+ \JakubBoucek\ComposerConsistency\ComposerConsistency::rootDir(__DIR__)
73+ ->errorMode(false)
74+ ->validate();
5775```
5876
59- Or check if dependency exists:
77+ ### Strict mode
78+ In strict mode Checker throws Exception when is unable to read Composer's files used to
79+ compute vendor consistency. Default value: ` off ` .
80+
81+ Turn on Strict mode:
6082``` php
61- if(class_exists(Checker::class)) {
62- Checker::validateReqs(__DIR__);
63- }
83+ \JakubBoucek\ComposerConsistency\ComposerConsistency::rootDir(__DIR__)
84+ ->strict()
85+ ->validate();
6486```
6587
66- ## Reference
88+ Scrict mode is by default disabled, because:
89+ - it can break production if you ignore some files (like ` composer.lock ` ) during deploy -
90+ that's false positive,
91+ - is not important to guard these files, for example when is missing whole ` vendor/ ` directory,
92+ is unable to load this package too,
93+ - main purpose of package is watching to subtle nuances in packages consistency, not fatals
94+ in Composer's file system.
6795
68- ### Class ` Checker `
96+ ### Cache
97+ Checking vendor consistency on every request consume unnecessarily huge CPU power. Ceche is store last success check
98+ only check is composer files stay without change. It does not check consincy of packages until these files keep same
99+ content. Default value: off.
69100
70- #### ` __constructor($rootDir, ?string $vendorDir = null) `
71- Contructor creates Checker instance.\
72- Only required argument is absolute path to root directory (directory where checker search the ` composer.lock ` file).\
73- Optional argument is absolute path do ` vendor ` directory. Default is ` {$rootDir}/vendor ` .
101+ ``` php
102+ \JakubBoucek\ComposerConsistency\ComposerConsistency::rootDir(__DIR__)
103+ ->cache(__DIR__ . '/temp')
104+ ->validate();
105+ ```
74106
75- #### ` validate(): void `
76- Check if ` /vendor ` is consitent with app requirements and throw an Exception if is not.
107+ ### Froze mode
108+ Checking vendor consistency on every request consume unnecessarily huge CPU power. Froze mode is usable when you
109+ guarantee the deploy process to production is always purge the temp directory. Default value: off.
77110
78- #### ` isReqsValid(): bool `
79- Check if ` /vendor ` is consitent with app requirements and return boolean of consistency status.
111+ ``` php
112+ \JakubBoucek\ComposerConsistency\ComposerConsistency::rootDir(__DIR__)
113+ ->froze(__DIR__ . '/temp')
114+ ->validate();
115+ ```
80116
81- #### ` validateReqs(string $rootDir, ?string $vendorDir = null): void `
82- Shortcut to call ` validate() ` without creating Checker instance before .
117+ In Froze mode is vendor consistenty checked only once, then is state saved to temp directory and
118+ no more checks are performed until is temp directory purged .
0 commit comments