PHPackages                             danfekete/spec - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. danfekete/spec

ActiveLibrary

danfekete/spec
==============

Specification pattern

0.3.2(9y ago)058MITPHPPHP &gt;5.6.0

Since May 25Pushed 9y ago1 watchersCompare

[ Source](https://github.com/danfekete/Spec)[ Packagist](https://packagist.org/packages/danfekete/spec)[ RSS](/packages/danfekete-spec/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (2)Versions (6)Used By (0)

Spec
====

[](#spec)

[![Build Status](https://camo.githubusercontent.com/889596047f9b07015c43fd9e613b8aae61de36b522eadc7969bf1d32454b5e47/68747470733a2f2f7472617669732d63692e6f72672f64616e66656b6574652f537065632e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/danfekete/Spec)

Spec is a PHP implementation of the Specification pattern which can be used for building simple or complex business rules.

> In computer programming, the **specification pattern** is a particular [software design pattern](https://en.wikipedia.org/wiki/Software_design_pattern), whereby [business rules](https://en.wikipedia.org/wiki/Business_rules) can be recombined by chaining the business rules together using boolean logic. The pattern is frequently used in the context of [domain-driven design](https://en.wikipedia.org/wiki/Domain-driven_design).
>
> [https://en.wikipedia.org/wiki/Specification\_pattern](https://en.wikipedia.org/wiki/Specification_pattern)

The library uses the incredible [expression-language](https://packagist.org/packages/symfony/expression-language) component from Symfony to provide the DSL for expressions.

Installation
------------

[](#installation)

`$ composer require danfekete/spec `

Usage
-----

[](#usage)

#### 1. Simple expression

[](#1-simple-expression)

```
$d = [2];
$spec = new Specification(new ExpressionSpec('1 > d[0]'));
$spec->isSatisfiedBy(['d' => $d]); // return false
```

#### 2. Boolean chaining

[](#2-boolean-chaining)

```
/*
 * You can use classes in expression code
*/
class Nan {

    public function isNan($value)
    {
        return is_nan($value);
    }

}

$spec = new Specification(new AndSpec(
    new NotSpec(new ExpressionSpec('checker.isNan(d)')),
    new OrSpec(
        new ExpressionSpec('d != 12'),
        new ExpressionSpec('d > 10')
    ),
    new AndSpec(
        new ExpressionSpec('d > 5'),
        new ExpressionSpec('d < 20')
    )
));

$spec->isSatisfiedBy(['d' => 17, 'checker' => new Nan()]); // return true
```

TODO
----

[](#todo)

1. Cache parsed code permanently
2. Array builder, builds specification from arrays
3. JSON builder

License
-------

[](#license)

MIT, see LICENSE

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~40 days

Total

5

Last Release

3480d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/44952ac11bee81804ffd10caecf0e48b8bdba1161efade40a781232b1641aa13?d=identicon)[danfekete](/maintainers/danfekete)

### Embed Badge

![Health badge](/badges/danfekete-spec/health.svg)

```
[![Health](https://phpackages.com/badges/danfekete-spec/health.svg)](https://phpackages.com/packages/danfekete-spec)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[simplesamlphp/simplesamlphp

A PHP implementation of a SAML 2.0 service provider and identity provider.

1.1k12.4M193](/packages/simplesamlphp-simplesamlphp)[winzou/state-machine

A very lightweight yet powerful PHP state machine

52113.7M18](/packages/winzou-state-machine)[friendsofsymfony/http-cache-bundle

Set path based HTTP cache headers and send invalidation requests to your HTTP cache

43813.2M47](/packages/friendsofsymfony-http-cache-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[thecodingmachine/graphqlite

Write your GraphQL queries in simple to write controllers (using webonyx/graphql-php).

5723.1M30](/packages/thecodingmachine-graphqlite)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
