Download the PHP package hediet/contracts without Composer

On this page you can find all versions of the php package hediet/contracts. 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 contracts

PHP Contracts - A Powerful Assertion Library for PHP

PHP Contracts is an assertion library for PHP to validate arguments and invariants. This library aims to replace my library nunzion/php-expect.

Warning

This library is still in development! However, the signature of the method Contract::requires will not change and it is guaranteed that an exception is beeing thrown if the condition evaluates to false.

Installation

You can use Composer to download and install PHP Contracts. To add PHP Contracts to your project, simply add a dependency on hediet/contracts to your project's composer.json file.

Here is a minimal example of a composer.json file that just defines a dependency on PHP Contracts:

Usage

Using this library is as simple as calling Contract::requires with an arbitrary condition:

If the specified condition evaluates to false, PHP Contracts analyzes the condition and throws an exception with an appropriate error message.

The following code will throw an \InvalidArgumentException with the message Argument 'b' must be of type 'integer', but is of type 'string'.:

Explicitly Supported Tests

Currently PHP Contracts understands the following conditions:

However, currently all expressions must be constants or arguments.

Examples

Internals

If the condition evaluates to true, the requires method returns immediately. Thus, if a condition does not fail, there is no significant performance decrease.

If a condition fails, i.e. evaluates to false, the stacktrace is used to determine the location of the requires call. After that, the invocation is parsed with nikic/PHP-Parser and converted to a set of constraints. These constraints may reference expressions to which the constraints are applied to. By using the stacktrace a second time, the arguments and the value of $this can be obtained for the context of the invocation to evaluate these expressions, so that a constraint can add an explanation of why he has failed.

Todos

Author

Henning Dieterichs - [email protected]

License

PHP Expect is licensed under the MIT License.


All versions of contracts with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
nikic/php-parser Version ^1.1.0
nunzion/stacktrace Version ^0.2.1
hediet/type-reflection Version ^0.1.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 hediet/contracts contains the following files

Loading the files please wait ....