示例#1
0
 /**
  * @param Pipeline $pipeline
  * @param string $storeName
  * @param array $storeConfiguration
  * @throws InvalidConfigurationException
  */
 public function buildStore($pipeline, $storeName, $storeConfiguration = [])
 {
     $triggeredByActions = is_array($storeConfiguration) && array_key_exists("triggered_by_actions", $storeConfiguration) ? $storeConfiguration["triggered_by_actions"] : [];
     $triggeredByStores = is_array($storeConfiguration) && array_key_exists("triggered_by_stores", $storeConfiguration) ? $storeConfiguration["triggered_by_stores"] : [];
     $triggeredEvent = is_array($storeConfiguration) && array_key_exists("triggered_event", $storeConfiguration) ? $storeConfiguration["triggered_event"] : null;
     $service = is_array($storeConfiguration) && array_key_exists("service", $storeConfiguration) ? $storeConfiguration["service"] : null;
     $store = $pipeline->hasStore($storeName) ? $pipeline->getStore($storeName) : new Store($storeName);
     $store->setService($service);
     foreach ($triggeredByActions as $triggeredByAction) {
         if (!$pipeline->hasAction($triggeredByAction)) {
             throw new InvalidConfigurationException("Store {$storeName} depends on an unknown action : {$triggeredByAction}");
         }
         $store->addTriggeredByAction($pipeline->getAction($triggeredByAction));
     }
     foreach ($triggeredByStores as $storeName) {
         $triggeredByStore = new Store($storeName);
         if ($pipeline->hasStore($storeName)) {
             $triggeredByStore = $pipeline->getStore($storeName);
         }
         $store->addTriggeredByStore($triggeredByStore);
     }
     // check that store is triggered by an action or another store.
     if ($store->isNeverTriggered()) {
         throw new InvalidConfigurationException("Store {$storeName} is never triggered");
     }
     // add triggered event
     if (isset($triggeredEvent)) {
         $event = $pipeline->hasOutgoingEvent($triggeredEvent) ? $pipeline->getOutgoingEvent($triggeredEvent) : new Event($triggeredEvent);
         $store->setTriggeredEvent($event);
         $pipeline->addOutgoingEvent($event);
     }
     $pipeline->addStore($store);
 }