/** * Returns the coupon model which belongs to the given code. * * @param MShop_Coupon_Item_Interface $item Coupon item interface * @return MShop_Coupon_Provider_Interface Returns a coupon provider instance * @throws MShop_Coupon_Exception If coupon couldn't be found */ public function getProvider(MShop_Coupon_Item_Interface $item, $code) { $names = explode(',', $item->getProvider()); if (($providername = array_shift($names)) === null) { throw new MShop_Coupon_Exception(sprintf('Provider in "%1$s" not available', $item->getProvider())); } if (ctype_alnum($providername) === false) { throw new MShop_Coupon_Exception(sprintf('Invalid characters in provider name "%1$s"', $providername)); } $interface = 'MShop_Coupon_Provider_Factory_Interface'; $classname = 'MShop_Coupon_Provider_' . $providername; if (class_exists($classname) === false) { throw new MShop_Coupon_Exception(sprintf('Class "%1$s" not available', $classname)); } $context = $this->_getContext(); $provider = new $classname($context, $item, $code); if ($provider instanceof $interface === false) { $msg = sprintf('Class "%1$s" does not implement interface "%2$s"', $classname, $interface); throw new MShop_Coupon_Exception($msg); } $decorators = $context->getConfig()->get('mshop/coupon/provider/decorators', array()); $object = $this->_addCouponDecorators($item, $code, $provider, $names); $object = $this->_addCouponDecorators($item, $code, $object, $decorators); $object->setObject($object); return $object; }
/** * Returns the coupon model which belongs to the given code. * * @param MShop_Coupon_Item_Interface $item Coupon item interface * @return MShop_Coupon_Provider_Interface Returns a coupon provider instance * @throws MShop_Coupon_Exception If coupon couldn't be found */ public function getProvider(MShop_Coupon_Item_Interface $item, $code) { $names = explode(',', $item->getProvider()); if (($providername = array_shift($names)) === null) { throw new MShop_Coupon_Exception(sprintf('Provider in "%1$s" not available', $item->getProvider())); } if (ctype_alnum($providername) === false) { throw new MShop_Coupon_Exception(sprintf('Invalid characters in provider name "%1$s"', $providername)); } $interface = 'MShop_Coupon_Provider_Factory_Interface'; $classname = 'MShop_Coupon_Provider_' . $providername; if (class_exists($classname) === false) { throw new MShop_Coupon_Exception(sprintf('Class "%1$s" not available', $classname)); } $context = $this->_getContext(); $provider = new $classname($context, $item, $code); if ($provider instanceof $interface === false) { $msg = sprintf('Class "%1$s" does not implement interface "%2$s"', $classname, $interface); throw new MShop_Coupon_Exception($msg); } /** mshop/coupon/provider/decorators * Adds a list of decorators to all coupon provider objects automatcally * * Decorators extend the functionality of a class by adding new aspects * (e.g. log what is currently done), executing the methods of the underlying * class only in certain conditions (e.g. only for logged in users) or * modify what is returned to the caller. * * This option allows you to wrap decorators * ("MShop_Coupon_Provider_Decorator_*") around the coupon provider. * * mshop/coupon/provider/decorators = array( 'decorator1' ) * * This would add the decorator named "decorator1" defined by * "MShop_Coupon_Provider_Decorator_Decorator1" to all coupon provider * objects. * * @param array List of decorator names * @since 2014.05 * @category Developer * @see client/html/common/decorators/default * @see client/html/account/favorite/decorators/excludes * @see client/html/account/favorite/decorators/local */ $decorators = $context->getConfig()->get('mshop/coupon/provider/decorators', array()); $object = $this->_addCouponDecorators($item, $code, $provider, $names); $object = $this->_addCouponDecorators($item, $code, $object, $decorators); $object->setObject($object); return $object; }