/**
* Calculate a shipment price for a given customer using a specific provider
*
* @service
*/
class ShipmentQuote {
/**
* The customer discount fee service to use.
*
* @reference
* @binding.php ../DiscountFeeRate/DiscountFeeRate.php
*/
public $discountFee;
/**
* The shipping service to use.
*
* @reference
* @binding.wsdl ../Shipper/ShipperQuote.wsdl
*/
public $shipper;
/**
* Get a quote for a given customer using a specific provider
*
* @param string $shipping The shipping company
* @param string $customer The customer requiring shipment, in order to obtain discount rate
* @return float The quote for a given customer using a certain shipping provider.
*/
function getQuote($shippingCo, $customer)
{
$rateShip = $this->shipper->getShippingPrice($shippingCo);
$rate = $this->discountFee->getDiscountRate($customer);
return $rate * $rateShip;
}
}
?>
上次陈述的最重要的内容是那些made in @statements,自从每一个都提供特定的SCA行为。东西完成是 @service tag, which is charged with exposing the class in question as a service.这特定的例子,getQuote公式是唯一通过服务执行,有些是通过使用the @param and @return annotations获得。
实际执行或采用这个服务代表PHP SCA runtime -- 将让我们进入 point capable制作一个 WSDL contract, 和你想获得其它web服务一样。除了简单的采用这个服务在in this manner,真正好处是让SCA's model成为更好证据,当你测试getQuote function code时
陈述 $this-<shipper->getShippingPrice($shippingCo)和 $this->discountFee->getDiscountRate($customer),是2个基本的references出现在早些是候的课. 每个 references 都保留在 underlying services -- 感谢 SCA's @reference and @binding annotations -- 例 $discountFee 这是 a PHP class and in shipper's case 成为标准的 WSDL backed service。
你也了解到,大多的能量在 SCA's programming model是很简单,你可以建立 chained calling sequences services不需要 tainting the actual business logic, 可以简单得结论:简单移去所有我们只欠描述的 SCA annotations . 若这样做了, 就只留下 plain business logic 而没其他的依赖, 一个很高利益characteristic which is highly beneficial to不仅是为发展 SOA服务, 同时在software方面的利益。