PHPackages                             lisachenko/php-deal - 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. [Framework](/categories/framework)
4. /
5. lisachenko/php-deal

Abandoned → [php-deal/framework](/?search=php-deal%2Fframework)Library[Framework](/categories/framework)

lisachenko/php-deal
===================

Design by Contract framework for PHP

1.0.0(7y ago)2534.2k21[1 issues](https://github.com/lisachenko/php-deal/issues)[2 PRs](https://github.com/lisachenko/php-deal/pulls)1MITPHPPHP ~7.1

Since Feb 10Pushed 4y ago14 watchersCompare

[ Source](https://github.com/lisachenko/php-deal)[ Packagist](https://packagist.org/packages/lisachenko/php-deal)[ RSS](/packages/lisachenko-php-deal/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (6)Dependencies (8)Versions (12)Used By (1)

PhpDeal
-------

[](#phpdeal)

Design by Contract framework for PHP

What is Design by Contract?
---------------------------

[](#what-is-design-by-contract)

The specification of a class or interface is the collection of non-private items provided as services to the caller, along with instructions for their use, as stated in phpDoc. [Design By Contract](http://en.wikipedia.org/wiki/Design_by_contract) is an effective technology for creating a specification.

The fundamental idea of Design By Contract is to treat the services offered by a class or interface as a contract between the class (or interface) and its caller. Here, the word "contract" is meant to convey a kind of formal, unambiguous agreement between two parties:

- requirements upon the caller made by the class
- promises made by the class to the caller

If the caller fulfills the requirements, then the class promises to deliver some well-defined service. Some changes to a specification/contract will break the caller, and some won't. For determining if a change will break a caller, C++ FAQs uses the memorable phrase "require no more, promise no less": if the new specification does not require more from the caller than before, and if it does not promise to deliver less than before, then the new specification is compatible with the old, and will not break the caller.

[![Build Status](https://camo.githubusercontent.com/08e4b1ed3fbf138a13641a67e364b179aa6d514523ea35c8c36d1fdc94166603/68747470733a2f2f6170692e7472617669732d63692e6f72672f7068702d6465616c2f6672616d65776f726b2e706e673f6272616e63683d312e78)](https://travis-ci.org/php-deal/framework)[![GitHub release](https://camo.githubusercontent.com/44b0d50139d9cbfe7075fcdc7ab57f8e4270eed3eb30793870362cab4326703d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7068702d6465616c2f6672616d65776f726b2e737667)](https://github.com/php-deal/framework/releases/latest)[![Code Coverage](https://camo.githubusercontent.com/8efa49066fb7605f7e4f86c1d653219f63d533a409c1b5aa6c9d7c49837de0dc/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068702d6465616c2f6672616d65776f726b2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/php-deal/framework/?branch=1.x)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/4a9762aae2fdea82388ac81b0a3ae6c9f2abeaf8baf502ca6842f4909049d753/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068702d6465616c2f6672616d65776f726b2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/php-deal/framework/?branch=1.x)[![Minimum PHP Version](https://camo.githubusercontent.com/ea1981b82245d665d0a74d4f6afa46433325109dc8099e3b024a99f9cbc210ef/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344372e312d626c75652e737667)](https://php.net/)[![License](https://camo.githubusercontent.com/81e581875dd8ab981e3702c2bb49a99db09cb4954ba89c72972debfed181a1ec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7068702d6465616c2f6672616d65776f726b2e737667)](https://packagist.org/packages/php-deal/framework)

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

[](#installation)

PhpDeal framework can be installed with composer. Installation is quite easy, just ask composer to download the framework with its dependencies by running the command:

```
$ composer require php-deal/framework
```

Setup
-----

[](#setup)

Put the following code at the beginning of your application entry point or require it from an external file.

```
$instance = ContractApplication::getInstance();
$instance->init(array(
    'debug'    => true,
    'appDir'   => __DIR__,
    'excludePaths' => [
        __DIR__ . '/vendor'
    ],
    'includePaths' => [

    ],
    'cacheDir' => __DIR__.'/cache/',
));
```

Symfony setup
-------------

[](#symfony-setup)

Put the following code in app\_dev.php and adapt it to match your folder structure. The appDir must point to the folder containing the src files, not the document root folder !

```
$instance = ContractApplication::getInstance();
$instance->init(array(
    'debug'    => true,
    'appDir'   => __DIR__ . '/../src',
    'excludePaths' => [

    ],
    'includePaths' => [

    ],
    'cacheDir' => __DIR__.'/var/cache/',
));
```

Pre and Post Contracts
----------------------

[](#pre-and-post-contracts)

The pre contracts specify the preconditions (requirements) before a statement is executed. The most typical use of this would be in validating the parameters to a function. The post contracts (promises) validate the result of the statement. The most typical use of this would be in validating the return value of a method and of any side effects it has. The syntax is:

```
