localheinz / specification
此包已被废弃,不再维护。未建议替代包。
提供遵循Eric Evans和Martin Fowler论文的规范。
0.1.0
2017-06-09 02:12 UTC
Requires
- php: ^7.0
Requires (Dev)
- codeclimate/php-test-reporter: 0.4.4
- localheinz/php-cs-fixer-config: 1.2.1
- phpunit/phpunit: ^6.2.1
This package is auto-updated.
Last update: 2019-12-07 10:51:03 UTC
README
提供遵循Eric Evans和Martin Fowler论文的规范,也请参阅维基百科:规范模式。
安装
运行
$ composer require localheinz/specification
使用
SpecificationInterface
在你的规范中实现Localheinz\Specification\SpecificationInterface
namespace Foo\Bar; use Localheinz\Specification\SpecificationInterface; final class IsInstanceOfStdClass implements SpecificationInterface { public function isSatisfiedBy($candidate): bool { return $candidate instanceof \stdClass; } } final class HasFooProperty implements SpecificationInterface { public function isSatisfiedBy($candidate): bool { return property_exists($candidate, 'foo'); } } final class HasBarProperty implements SpecificationInterface { public function isSatisfiedBy($candidate): bool { return property_exists($candidate, 'bar'); } }
AndSpecification
使用Localheinz\Specification\AndSpecification
从需要满足的所有规范中组合规范
use Localheinz\Specification\AndSpecification; use Localheinz\Specification\Test\Fixture; $specification = new AndSpecification( new Fixture\Specification\IsInstanceOfStdClass(), new Fixture\Specification\HasFooProperty(), new Fixture\Specification\HasBarProperty() ); $candidate = new \stdClass(); $candidate->foo = 9000; $candidate->bar = 'Hello, my name is Jane'; $specification->isSatisfiedBy($candidate); // true
OrSpecification
使用Localheinz\Specification\OrSpecification
从只需要满足其中一个规范的规范中组合规范
use Localheinz\Specification\OrSpecification; use Localheinz\Specification\Test\Fixture; $specification = new OrSpecification( new Fixture\Specification\IsInstanceOfStdClass(), new Fixture\Specification\HasFooProperty(), new Fixture\Specification\HasBarProperty() ); $candidate = new \stdClass(); $specification->isSatisfiedBy($candidate); // true
NotSpecification
使用Localheinz\Specification\NotSpecification
从不应该满足的规范中组合规范
use Localheinz\Specification\NotSpecification; use Localheinz\Specification\Test\Fixture; $specification = new NotSpecification( new Fixture\Specification\IsInstanceOfStdClass(), new Fixture\Specification\HasFooProperty(), new Fixture\Specification\HasBarProperty() ); $candidate = new \SplObjectStorage(); $specification->isSatisfiedBy($candidate); // true
混合匹配
根据需要混合匹配所有规范
use Localheinz\Specification\AndSpecification; use Localheinz\Specification\NotSpecification; use Localheinz\Specification\OrSpecification; use Localheinz\Specification\Test\Fixture; $specification = new AndSpecification( new NotSpecification(new Fixture\Specification\IsInstanceOfStdClass()), new OrSpecification( new Fixture\Specification\HasFooProperty(), new Fixture\Specification\HasBarProperty() ) ); class Baz { public $foo; } $candidate = new Baz(); $specification->isSatisfiedBy($candidate); // true
变更日志
请参阅CHANGELOG.md
。
贡献
请参阅CONTRIBUTING.md
。
行为准则
许可证
此包使用MIT许可证许可。