diff --git a/README.md b/README.md index cd9d840..7a878f3 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,80 @@ composer require S1SYPHOS/php-thx For yarn v2 support, the `php-yaml` package is required! -# Usage +## Usage + +First, determine the paths to your files (datafile & lockfile, see below): + +```php + '/path/to/cache']; # Optional: Cache settings, see below +``` + +**Note:** +For available cache drivers & settings, see [here](https://github.com/terrylinooo/simple-cache)! + +Passing these options to `Thx::giveBack()` creates an instance: + +```php +$obj = Thx::giveBack($pkgFile, $lockFile, $cacheDriver, $cacheSettings); +``` + +.. which you may configure to your liking by using: + +- `setTimeout(int $seconds)` +- `setCacheDuration(int $days)` +- `setUserAgent(string $userAgent)` +- `setBlockList(array $blockList)` + +```php +# For example: + +$obj->setCacheDuration(7); # Cache results for one week +$obj->setBlockList(['php', 'some/library']); # Block from being processed +``` + +After setting everything up, `spreadLove()` makes some API calls: + +- Composer packages @ https://repo.packagist.org +- Node packages @ https://api.npms.io + +```php +$obj->spreadLove(); +``` + +Currently there are three methods you can use: + +- `data()` returns raw data from lockfile for all used packages +- `pkgs()` returns processed data for all used packages +- `packages()` returns the names of all used packages + +```php +# Alternative 1: +# Process data +$obj->spreadLove(); + +# Work with it +$raw = $obj->data(); +$processed = $obj->pkgs(); + +# Alternative 2: +# Since `spreadLove` allows chaining, you could also do it like this: +$obj->spreadLove()->data(); + +# The second call provides cached data, no performance penalty there +$obj->spreadLove()->pkgs(); +``` + + +## Example This example should get you started: @@ -48,11 +121,11 @@ try { ## Roadmap -- [ ] Add (more sophisticated) tests +- [x] ~~Add (more sophisticated) tests~~ for now, they get the job done +- [x] Parse yarn v1 lockfiles - [x] Gather information using public APIs -- [ ] Custom `Exception`s +- [x] Custom `Exception`s - [ ] Provide more methods -- [x] Parse yarn v1 lockfiles ## Credits diff --git a/composer.json b/composer.json index 932eb49..ba17306 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Acknowledge the people behind your frontend dependencies - and give thanks!", "type": "library", "license": "MIT", - "version": "0.3.0", + "version": "1.0.0", "keywords": ["gratitude", "appreciation", "gratefulness", "thankfulness"], "homepage": "https://github.com/S1SYPHOS", "scripts": { diff --git a/lib/Driver.php b/lib/Driver.php index 315a1db..7feaf74 100644 --- a/lib/Driver.php +++ b/lib/Driver.php @@ -58,8 +58,8 @@ abstract class Driver /** * Constructor * - * @param string $dataFile Path to data file - * @param string $lockFile Lockfile stream + * @param string $pkgData Content of datafile as array + * @param string $lockFile Content of lockfile as string * @param string $cacheDriver Cache driver * @param array $cacheSettings Cache settings * @return void diff --git a/lib/Exceptions/NoJuiceException.php b/lib/Exceptions/NoJuiceException.php new file mode 100644 index 0000000..cbd9d2e --- /dev/null +++ b/lib/Exceptions/NoJuiceException.php @@ -0,0 +1,5 @@ +cacheDrivers) === false) { - throw new \Exception(sprintf('Cache driver "%s" cannot be initiated', $cacheDriver)); + throw new NoJuiceException(sprintf('Cache driver "%s" cannot be initiated', $cacheDriver)); } # (2) Merge caching options with defaults @@ -134,7 +137,7 @@ protected function createDir(string $dir, bool $recursive = true): bool } if (is_writable($parent) === false) { - throw new \Exception(sprintf('The directory "%s" cannot be created', $dir)); + throw new NoMannersException(sprintf('The directory "%s" cannot be created', $dir)); } return mkdir($dir);