How does Go! AOP PHP and PHP Deal override a class with given annotations in the same namespace? -


whilst reading design contract, came across php-deal. now, demo code looks this:

/** @var composer\autoload\classloader $loader */ $loader = include __dir__.'/../vendor/autoload.php'; $loader->add('demo', __dir__);  include_once __dir__.'/aspect_bootstrap.php';  $account = new demo\account(); $account->deposit(100); echo $account->getbalance(); 

the demo\account class looks this:

class account implements accountcontract {     /**      * current balance      *      * @var float      */     protected $balance = 0.0;       /**      * deposits fixed amount of money account      *      * @param float $amount      *      * @contract\verify("$amount>0 && is_numeric($amount)")      * @contract\ensure("$this->balance == $__old->balance+$amount")      */     public function deposit($amount)     {         $this->balance += $amount;     }       /**      * returns current balance      *      * @contract\ensure("$__result == $this->balance")      * @return float      */     public function getbalance()     {         return $this->balance;     } } 

the annotations important part verify , ensure contract within annotations executed.

calling class this:

$account = new demo\account(); $account->deposit(100); echo $account->getbalance(); 

works expected. calling class however:

$account = new demo\account(); $account->deposit("1notanumber"); echo $account->getbalance(); 

throws exception contract not being enforced.

however, if call class this:

$account = new demo\account(); $account->deposit("1notanumber"); echo $account->getbalance();  include_once __dir__.'/aspect_bootstrap.php';  $account = new demo\account(); $account->deposit("1notanumber"); echo $account->getbalance(); 

the contract enforcing stops working. question is, how aspect_bootstrap.php file override predefined php classes allow parsing , execution of annotations, , how possible without invoking entire go aop framework?

github repo php-deal demo


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -