Is there a framework or library for 开发者_高级运维php that will help me implement design by contract in my applications?
In the best case it would use javadoc like annotations in the comments.
I've started work on a design-by-contract project PHP-Contracts
There are a few blog posts about the subject as well:
- Towards a style of contract programming
- Design by contract in PHP with assertions
New DbC framework for PHP based on Aspect-Oriented Programming: https://github.com/lisachenko/php-deal
/**
* Simple trade account contract
*/
interface AccountContract
{
/**
* Deposits fixed amount of money to the account
*
* @param float $amount
*
* @Contract\Verify("$amount>0 && is_numeric($amount)")
* @Contract\Ensure("$this->balance == $__old->balance+$amount")
*/
public function deposit($amount);
/**
* Returns current balance
*
* @Contract\Ensure("$__result == $this->balance")
*
* @return float
*/
public function getBalance();
}
Would it be something like http://code.google.com/p/addendum/?
精彩评论