germania-kg/fabrics

处理布料的类和接口

5.2.9 2023-01-30 07:39 UTC

This package is auto-updated.

Last update: 2024-08-29 06:01:56 UTC


README

Germania KG · Fabrics

Packagist PHP version PHP Composer

安装

$ composer require germania-kg/fabrics "^5.0"

接口和类

基础

  • FabricInterface
  • FabricAbstract
  • Fabric

FabricsClientInterface

有关使用PDO数据库实现的示例,请参阅PdoFabricsClient

<?php
namespace Germania\Fabrics;

interface FabricsClientInterface
{

    /**
     * Retrieve all fabrics belonging to the given collection.
     *
     * @param  string        $collection   URL slug of a Germania Fabrics Collection
     * @param  string|null   $search       Optional: search term
     * @param  string|null   $sort         Optional: sort by field(s), string or CSV string
     * @return iterable|FabricInterface[]  Iterable with FabricInterface instances
     */
    public function collection( string $collection, string $search = null, string $sort = null) : iterable;


    /**
     * Retrieves all fabric transparencies belonging to the given collection.
     *
     * @param  string        $collection   URL slug of a Germania Fabrics Collection
     * @return iterable|FabricInterface[]  Iterable with FabricInterface instances
     */
    public function collectionTransparencies( string $collection) : iterable;


    /**
     * Retrieves all color groups belonging to the given collection.
     *
     * @param  string        $collection   URL slug of a Germania Fabrics Collection
     * @return iterable|FabricInterface[]  Iterable with FabricInterface instances
     */
    public function collectionColors( string $collection) : iterable;


    /**
     * Retrieves a single fabric from a given collection.
     *
     * @param  string $collection     URL slug of a Germania Fabrics Collection
     * @param  string $fabric_number  Fabric number
     * @return FabricInterface
     */
    public function fabric( string $collection, string $fabric_number ) : FabricInterface;
}

工厂

<?php
use Germania\Fabrics\FabricFactory;

$factory = new FabricFactory;

$fabric = $factory( [
	'fabric_number' => "1234",
  'collection_slug' => "someCollection"
]);

默认情况下,工厂创建Germania\Fabrics\Fabric的实例。您可以使用构造函数参数覆盖该类

use MyApp\SepcialFabric;
$factory = new FabricFactory( SepcialFabric::class );

装饰器

任何从FabricDecoratorAbstract扩展的具象装饰器类实现FabricInterface,并在构造函数中接受任何FabricInterface实例

<?php
use Germania\Fabrics\Fabric;
use Germania\Fabrics\FabricDecoratorAbstract;

class MyDecorator extends FabricDecoratorAbstract
{
  // ...
}

$fabric = new Fabric;
$my_fabric = new MyDecorator( $fabric );

过滤器迭代器

过滤来自PdoCollectionFabricsPdoCollectionFabricFuzzySearcher的数组迭代器

<?php
use Germania\Fabrics\PhotoNotEmptyFilterIterator;
use Germania\Fabrics\SameValueFilterIterator,
use Germania\Fabrics\LieferbarFabricsFilterIterator;
use Germania\Fabrics\EnabledFabricsFilterIterator;

PdoFabricsClient

PdoFabricsClient实现了FabricsClientInterface。其构造函数接受一个可选的PSR-3 Logger。

<?php
use Germania\Fabrics\PdoFabricsClient;

$pdo = ... // Your PDO handler
$fabrics_table = "germania_fabrics";
$colors_table = "germania_color_groups";
$fabrics_colors_table = "germania_fabrics_colors";
$logger = // optional

$client = new PdoFabricsClient(
  $pdo, 
  $fabrics_table, 
  $colors_table, 
  $fabrics_colors_table, 
  $logger);

自版本v4.5起,该类提供了一个collections方法

$collections = $client->collections();
print_r($collections);

//ArrayIterator Object
//(
//    [storage:ArrayIterator:private] => Array
//        (
//            [duette2014] => Array
//                (
//                    [collection_slug] => duette2014
//                    [collection_name] => DU-2014
//                    [fabrics_count] => 33
//                )
//            [jalousie2016] => Array
//                (
//                    [collection_slug] => jalousie2016
//                    [collection_name] => JAL-2016
//                    [fabrics_count] => 177
//                )

单元测试

phpunit.xml.dist复制到phpunit.xml,并根据您的需求进行修改。运行PhpUnit测试或类似以下的composer脚本:

$ composer test:unit
$ composer test:database