composer require germania-kg/fabricsapi-client "^4.0"
The FabricsApiClient requures a Guzzle client with configured API base URL at hand:
<?php
use Germania\FabricsApiClient\FabricsApiClient;
$guzzle = new \GuzzleHttp\Client([
// Note the trailing slash!
'base_uri' => "https://path/to/api/"
]);
$reader = new FabricsApiClient($guzzle);
For better performance, a PSR-6 CacheItemPool may be used to cache the results. The CacheFabricsApiClient wraps the above FabricsApiClient:
<?php
use Germania\FabricsApiClient\CacheFabricsApiClient;
$api_reader = new FabricsApiClient($guzzle);
$psr6 = ...;
$lifetime = 86400;
$reader = new CacheFabricsApiClient($api_reader, $psr6, $lifetime);
// iterable
$all_fabrics = $reader->collection("anyCollection");
// Sort by pattern
$all_fabrics = $reader->collection("anyCollection", null, "pattern");
// iterable
$matching_fabrics = $reader->collection("anyCollection", "seaflower");
// Sort by pattern
$matching_fabrics = $reader->collection("anyCollection", "seaflower", "pattern");
// Germania\Fabrics\FabricInterface
$single = reader->fabric("anyCollection", "1-2345");
Copy phpunit.xml.dist
to phpunit.xml
and adapt to your needs. Obtain Germania's Fabrics API URL and the collection slug, otherwise the Unit Tests will fail and ask a wrong API…
<php>
<env name="FABRICS_API" value="https://api.test.com/" />
<env name="FABRICS_SLUG" value="duette" />
<env name="FABRIC_NUMBER" value="1-2345" />
</php>
Run PhpUnit test or composer scripts like this:
$ composer test
# or
$ vendor/bin/phpunit