pbmedia / specifications
This package is abandoned and no longer maintained.
No replacement package was suggested.
Specify objects using attributes and scores
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
Install
Via Composer
$ composer require pbmedia/specifications
Requirements
- PHP 7.0 and 7.1.
Implementations
Usage
This package lets you specify objects, for example products.
use Pbmedia\Specifications\HasSpecifications; use Pbmedia\Specifications\Interfaces\CanBeSpecified; class NotebookProduct implements CanBeSpecified { use HasSpecifications; }
Set up Attribute
and Score
objects:
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; } }
Now you can 'specify' you NotebookProduct
like this:
$macbookAir = new NotebookProduct; $attribute = new DiskCapacityInGB; $score = new SizeInGB(256); // returns an instance of \Pbmedia\Specifications\Specifications $specifications = $macbookAir->specifications(); $specifications->set($attribute, $score);
Take a look at the docblocks of Specifications.php
to see what else you can do with it. This package also comes with a Matcher
service which can sort collections of specificable objects based on 'criteria' you provide.
$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();
Change log
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CONDUCT for details.
Security
If you discover any security related issues, please email pascal@pascalbaljetmedia.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.