2017 © Pedro PelĂĄez
 

library specification

Provides specifications following the paper by Eric Evans and Martin Fowler.

image

localheinz/specification

Provides specifications following the paper by Eric Evans and Martin Fowler.

  • Tuesday, June 19, 2018
  • by localheinz
  • Repository
  • 1 Watchers
  • 1 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

specification

CI Status codecov Latest Stable Version Total Downloads, (*1)

Provides specifications following the paper by Eric Evans and Martin Fowler, also see Wikipedia: Specification Pattern., (*2)

Installation

Run, (*3)

$ composer require localheinz/specification

Usage

SpecificationInterface

Implement Localheinz\Specification\SpecificationInterface in your specifications:, (*4)

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

Use Localheinz\Specification\AndSpecification to compose a specification from specifications which all need to be satisfied:, (*5)

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

Use Localheinz\Specification\OrSpecification to compose a specification from specifications where only one needs to be satisfied:, (*6)

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

Use Localheinz\Specification\NotSpecification to compose a specification from specifications where none should be satisfied:, (*7)

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

Mix and match

Mix and match all of the specifications to your need:, (*8)

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

Please have a look at CHANGELOG.md., (*9)

Contributing

Please have a look at CONTRIBUTING.md., (*10)

Code of Conduct

Please have a look at CODE_OF_CONDUCT.md., (*11)

License

This package is licensed using the MIT License., (*12)

The Versions

19/06 2018

dev-master

9999999-dev https://github.com/localheinz/specification

Provides specifications following the paper by Eric Evans and Martin Fowler.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Andreas Möller

16/04 2018

dev-feature/infection

dev-feature/infection https://github.com/localheinz/specification

Provides specifications following the paper by Eric Evans and Martin Fowler.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Andreas Möller

16/04 2018

dev-feature/phpunit

dev-feature/phpunit https://github.com/localheinz/specification

Provides specifications following the paper by Eric Evans and Martin Fowler.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Andreas Möller

16/04 2018

dev-feature/test-util

dev-feature/test-util https://github.com/localheinz/specification

Provides specifications following the paper by Eric Evans and Martin Fowler.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Andreas Möller

16/04 2018

dev-feature/php-cs-fixer-config

dev-feature/php-cs-fixer-config https://github.com/localheinz/specification

Provides specifications following the paper by Eric Evans and Martin Fowler.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Andreas Möller

27/01 2018

dev-feature/urls

dev-feature/urls https://github.com/localheinz/specification

Provides specifications following the paper by Eric Evans and Martin Fowler.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Andreas Möller

21/08 2017

dev-feature/php72

dev-feature/php72

Provides specifications following the paper by Eric Evans and Martin Fowler.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Andreas Möller

09/06 2017

0.1.0

0.1.0.0

Provides specifications following the paper by Eric Evans and Martin Fowler.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Andreas Möller