Esempio n. 1
0
 /**
  * Returns the service provider which is responsible for the service item.
  *
  * @param MShop_Service_Item_Interface $item Delivery or payment service item object
  * @return MShop_Service_Provider_Interface Returns a service provider implementing MShop_Service_Provider_Interface
  * @throws MShop_Service_Exception If provider couldn't be found
  */
 public function getProvider(MShop_Service_Item_Interface $item)
 {
     $type = ucwords($item->getType());
     $names = explode(',', $item->getProvider());
     if (ctype_alnum($type) === false) {
         throw new MShop_Service_Exception(sprintf('Invalid characters in type name "%1$s"', $type));
     }
     if (($provider = array_shift($names)) === null) {
         throw new MShop_Service_Exception(sprintf('Provider in "%1$s" not available', $item->getProvider()));
     }
     if (ctype_alnum($provider) === false) {
         throw new MShop_Service_Exception(sprintf('Invalid characters in provider name "%1$s"', $provider));
     }
     $interface = 'MShop_Service_Provider_Factory_Interface';
     $classname = 'MShop_Service_Provider_' . $type . '_' . $provider;
     if (class_exists($classname) === false) {
         throw new MShop_Service_Exception(sprintf('Class "%1$s" not available', $classname));
     }
     $context = $this->_getContext();
     $config = $context->getConfig();
     $provider = new $classname($context, $item);
     if ($provider instanceof $interface === false) {
         $msg = sprintf('Class "%1$s" does not implement interface "%2$s"', $classname, $interface);
         throw new MShop_Service_Exception($msg);
     }
     /** mshop/service/provider/delivery/decorators
      * Adds a list of decorators to all delivery 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_Service_Provider_Decorator_*") around the delivery provider.
      *
      *  mshop/service/provider/delivery/decorators = array( 'decorator1' )
      *
      * This would add the decorator named "decorator1" defined by
      * "MShop_Service_Provider_Decorator_Decorator1" to all delivery provider
      * objects.
      *
      * @param array List of decorator names
      * @since 2014.03
      * @category Developer
      * @see mshop/service/provider/payment/decorators
      */
     /** mshop/service/provider/payment/decorators
      * Adds a list of decorators to all payment 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_Service_Provider_Decorator_*") around the payment provider.
      *
      *  mshop/service/provider/payment/decorators = array( 'decorator1' )
      *
      * This would add the decorator named "decorator1" defined by
      * "MShop_Service_Provider_Decorator_Decorator1" to all payment provider
      * objects.
      *
      * @param array List of decorator names
      * @since 2014.03
      * @category Developer
      * @see mshop/service/provider/delivery/decorators
      */
     $decorators = $config->get('mshop/service/provider/' . $item->getType() . '/decorators', array());
     $provider = $this->_addServiceDecorators($item, $provider, $names);
     return $this->_addServiceDecorators($item, $provider, $decorators);
 }
Esempio n. 2
0
 /**
  * Copys all data from a given service item.
  *
  * @param MShop_Service_Item_Interface $service New service item
  */
 public function copyFrom(MShop_Service_Item_Interface $service)
 {
     $this->setCode($service->getCode());
     $this->setName($service->getName());
     $this->setType($service->getType());
     $this->setServiceId($service->getId());
     $items = $service->getRefItems('media', 'default', 'default');
     if (($item = reset($items)) !== false) {
         $this->setMediaUrl($item->getUrl());
     }
     $this->setModified();
 }
Esempio n. 3
0
 /**
  * Returns the service provider which is responsible for the service item.
  *
  * @param MShop_Service_Item_Interface $item Delivery or payment service item object
  * @return MShop_Service_Provider_Interface Returns a service provider implementing MShop_Service_Provider_Interface
  * @throws MShop_Service_Exception If provider couldn't be found
  */
 public function getProvider(MShop_Service_Item_Interface $item)
 {
     $domain = ucwords($item->getType());
     $names = explode(',', $item->getProvider());
     if (ctype_alnum($domain) === false) {
         throw new MShop_Service_Exception(sprintf('Invalid characters in domain name "%1$s"', $domain));
     }
     if (($provider = array_shift($names)) === null) {
         throw new MShop_Service_Exception(sprintf('Provider in "%1$s" not available', $item->getProvider()));
     }
     if (ctype_alnum($provider) === false) {
         throw new MShop_Service_Exception(sprintf('Invalid characters in provider name "%1$s"', $provider));
     }
     $interface = 'MShop_Service_Provider_Factory_Interface';
     $classname = 'MShop_Service_Provider_' . $domain . '_' . $provider;
     if (class_exists($classname) === false) {
         throw new MShop_Service_Exception(sprintf('Class "%1$s" not available', $classname));
     }
     $context = $this->_getContext();
     $provider = new $classname($context, $item);
     if ($provider instanceof $interface === false) {
         $msg = sprintf('Class "%1$s" does not implement interface "%2$s"', $classname, $interface);
         throw new MShop_Service_Exception($msg);
     }
     $config = $context->getConfig();
     $decorators = $config->get('mshop/service/provider/' . $item->getType() . '/decorators', array());
     $provider = $this->_addServiceDecorators($item, $provider, $names);
     return $this->_addServiceDecorators($item, $provider, $decorators);
 }