Download the PHP package bakame/spec without Composer

On this page you can find all versions of the php package bakame/spec. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package spec

Complex Specifications Pattern in PHP

This package adds support for the Specification pattern in PHP. It helps to leverage complex specification by offloading all the tedious work. Implementing specification pattern is made simpler while leaves all logical wiring to the package.

While framework independent, you can easily integrate this package inside any PHP framework.

Build Latest Version Total Downloads Sponsor development of this project

System Requirements

You need:

Installation

Use composer:

or download the library and:

require 'path/to/spec/repo/autoload.php';

use Bakame\Specification\Chain;

$spec = Chain::one(new Rule1())
    ->and(new Rule2(), new Rule3())
    ->orNot(new Rule4());

$spec->isSatisfiedBy($subject);

What is it ?

"the specification pattern is a particular software design pattern, whereby 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." -- wikipedia

Usage

Each rule that needs to be satisfied MUST implement the Bakame\Specification\Specification interface.

This interface only contains one method isSatisfiedBy(mixed $subject): bool. The method should not throw but if it does no mechanism MUST stop the exception from propagating outside the method.

Here's a quick example to illustrate the package usage.

First, we create a specification implementing class.

Then using the Bakame\Specification\Chain class and all the specifications created, we apply all the specifications according to the business rules.

Here's how the wikipedia example is adapted using the library.

The Bakame\Specification\Chain class exposes the following logical chaining methods

Logical methods isSatisfiedBy will return true
Chain::and if the resulting the current specification and the those added are all satisfied
Chain::or if at least one of the specifications is satisfied
Chain::andNot if the current specification is satisfied AND the ones added are not
Chain::orNot if the current specification is satisfied OR the ones added are not
Chain::not will return the opposite of the current specification

To initiate a new specification logic chain the class exposes 4 named constructors

Named constructor returned instance
Chain::one new instance with a specification attach to it
Chain::all with all specifications attach to it like Chain::and
Chain::any with all specifications attach to it like Chain::or
Chain::none with all specifications attach to it like Chain::not

All the methods from the Bakame\Specification\Chain accept variadic Bakame\Specification\Specification implemented classes except for the Chain::not method which takes not parameter at all.

Creating more complex rules that you can individually test becomes trivial as do their maintenance.

Tips on how to validate a list of subject.

Array

To filter an array of subjects you can use the array_filter function

Traversable

To filter a traversable structure or a generic iterator you can use the CallbackFilterIterator class.

Collections

The package can be used directly on collection that supports the filter method like Doctrine collection classes.

Collection Macro

An alternative for Laravel collections is to register a macro:

And then be used as described below:

Contributing

Contributions are welcome and will be fully credited. Please see CODE OF CONDUCT for details.

Testing

The library:

To run the tests, run the following command from the project folder.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

Attribution

The package is a fork of the work of greydnls on greydnls/spec.

License

The MIT License (MIT). Please see License File for more information.


All versions of spec with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package bakame/spec contains the following files

Loading the files please wait ....