pbmedia / specifications
此包已被弃用且不再维护。未建议替代包。
使用属性和分数指定对象
1.0.0
2016-10-11 09:52 UTC
Requires
- php: ~7.0
- tightenco/collect: ^5.3
Requires (Dev)
- phpunit/phpunit: ~5.0
- scrutinizer/ocular: ^1.3
- squizlabs/php_codesniffer: ^2.3
README
安装
通过 Composer
$ composer require pbmedia/specifications
要求
- PHP 7.0 和 7.1。
实现
用法
此包允许您指定对象,例如产品。
use Pbmedia\Specifications\HasSpecifications; use Pbmedia\Specifications\Interfaces\CanBeSpecified; class NotebookProduct implements CanBeSpecified { use HasSpecifications; }
设置 Attribute
和 Score
对象
use Pbmedia\Specifications\Interfaces\Attribute; use Pbmedia\Specifications\Interfaces\Score; class DiskCapacityInGB implements Attribute { public function getIdentifier() { return 'DiskCapacityInGB'; } } class SizeInGB implements Score { private $sizeInGB; public function __construct($sizeInGB) { $this->sizeInGB = $sizeInGB; } public function getValue() { return $this->sizeInGB; } }
现在您可以像这样 '指定' NotebookProduct
$macbookAir = new NotebookProduct; $attribute = new DiskCapacityInGB; $score = new SizeInGB(256); // returns an instance of \Pbmedia\Specifications\Specifications $specifications = $macbookAir->specifications(); $specifications->set($attribute, $score);
查看 Specifications.php
的文档块以了解您可以做什么。此包还附带一个 Matcher
服务,可以根据您提供的 '标准' 对可指定对象集合进行排序。
$matcher = new \Pbmedia\Specifications\Matcher; $matcher->addCandidates([ $macbookAir, $macbookPro ]); // just as a product itself, add 'criteria' to compare against: $matcher->specifications()->set( new DiskCapacityInGB, new SizeInGB(512) ); // get a collection of notebooks sorted based on which ones are most closely to the criteria. $matcher->get();
变更日志
请参阅 CHANGELOG 了解最近更改的详细信息。
测试
$ composer test
贡献
请参阅 CONTRIBUTING 和 CONDUCT 了解详细信息。
安全性
如果您发现任何安全相关的问题,请通过电子邮件 pascal@pascalbaljetmedia.com 联系我们,而不是使用问题跟踪器。
鸣谢
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件。