Adds an Event to the Aggregates pending Events.

Events added here will be change the state of the Aggregate
when applyChanges() is called on the Aggregate.

@param AggregateInterface $aggregate
@param EventInterface     $event

@return AggregateInterface
423974
public function apply(AggregateInterface $aggregate, EventInterface $event): AggregateInterface
    {
        // Increase version on each apply call.
        $aggregate->setVersion($event->getCommand()->getOnVersion() + 1);

        // Add Event to pending Events.
        return $aggregate->addPendingEvent($event);
    }
1231522
public function onFlush(OnFlushEventArgs $eventArgs)
	{
		$em = $eventArgs->getEntityManager();
		$uow = $em->getUnitOfWork();

		foreach ($uow->getScheduledEntityUpdates() as $entity) {
			if ($entity instanceof TimestampableInterface) {
				$entity->setModificationTime();
				$className = get_class($entity);
				$class = $em->getClassMetadata($className);
				$uow->recomputeSingleEntityChangeSet($class, $entity);
			}
		}
	}
816510
public function put(EventInterface $event) {
        $request = $event->getRequest();
        $metadata = json_decode($request->getContent(), true);

        $event->getManager()
            ->trigger('db.metadata.delete')
            ->trigger('db.metadata.update', [
                'metadata' => $metadata,
            ]);

        $model = new Model\Metadata();
        $model->setData($metadata);

        $event->getResponse()->setModel($model);
    }
1014098
public function process(EventInterface $event)
    {
        $events = $this->getEventManager();
        $mapper = $this->getMapper();
        $optionsProvider = $this->getOptionsProvider();
        $translator = $this->getTranslator();
        $pane = $event->getParam('pane');
        if (! $optionsProvider->hasIdentifier($pane)) {
            return;
        }
        $ids = $event->getParam('id');
        if (empty($ids)) {
            return;
        }
        $options = $optionsProvider->getOptions($pane);
        if ($options->getRoot() == 'site') {
            $this->error(self::DeleteFromSite);
            return $this->redirect($event);
        }
        foreach ($ids as $id) {
            try {
                $mapper->beginTransaction();
                $tid = $mapper->getTransactionIdentifier();
                $events->trigger(
                    __FUNCTION__ . '.delete.pre',
                    null,
                    [
                        'content' => $id,
                        'tid' => $tid,
                    ]
                );
                $mapper->delete($id, $tid);
                $mapper->commit();
            } catch (UnavailableSourceException $e) {
                $mapper->rollBack();
                $this->setValue($id)->error(self::SourceNotFound);
            } catch (Exception $e) {
                if (DEBUG_MODE) {
                    throw new DebugException(
                        $translator->translate('Error: ') . $e->getMessage(),
                        $e->getCode(),
                        $e
                    );
                }
                $meta = $mapper->findMetaById($id);
                $name = isset($meta['title']) ? $meta['title'] : $id;
                $this->setValue($name)->error(self::UnexpectedError);
            }
        }

        return $this->redirect($event, 'sc-admin/file/delete');
    }
178508
public function afterCreate(PersistenceEvent $event) {
    if ($event->getAction() == PersistenceAction::CREATE) {
      $oldOid = $event->getOldOid();
      $oldOidStr = $oldOid != null ? $oldOid->__toString() : null;
      if ($oldOidStr != null && isset($this->createdTranslations[$oldOidStr])) {
        foreach ($this->createdTranslations[$oldOidStr] as $translation) {
          $translation->setValue('objectid', $event->getObject()->getOID()->__toString());
        }
      }
    }
  }
936292
public static function buildFrom(StreamEvents $events): Aggregate {
        $aggregate = new static;
        $events->each(function (StreamEvent $event) use ($aggregate) {
            $aggregate->apply($event->event());
            if ( ! $event->version()->equals($aggregate->aggregateVersion())) {
                throw new UnexpectedAggregateVersionWhenBuildingFromEvents("When building from stream events aggregate {$aggregate->aggregateId()->toString()} expected version {$event->version()->toInt()} but got {$aggregate->aggregateVersion()->toInt()}.");
            }
        });
        return $aggregate;
    }
1143383
public function handle(EventInterface $event)
    {
        if ($event instanceof StatsEvent) {
            $this->writeProgressionLine('');
            $this->style->success('Phar creation successful');
            $this->style->table([], [
                ['Path', '<info>' . $event->getStats()->getFinalPath() . '</info>'],
                ['File size', '<info>' . $event->getSize() . '</info>'],
                ['Process duration', '<info>' . $event->getDuration() . '</info>']
            ]);
        }

        if ($event instanceof BuilderAddEvent) {
            $this->writeProgressionLine('Adding <comment>' . $event->getPath() . '</comment>');
        }

        if ($event instanceof CompressorEvent) {
            $this->writeProgressionLine('<info>Compressing...</info>');
        }

        if (0 === strpos($event->getName(), 'options.')) {
            $this->writeProgressionLine(
                '<comment>Read options...</comment> (' . ucfirst(substr($event->getName(), \strlen('options.'))) . ')',
                true
            );
        }
    }
956011
public function onStoryAggregation(AnEvent $event)
    {
        if (!empty($this->_story_aggregation)) {
            $event->aggregations->append(array(
                $this->component => $this->_story_aggregation,
            ));
        }
    }
701460
public function addEventToList(Event $event)
    {
        if ($this->_eventList) {
            $this->_eventList->add($event);
        }

        return $this;
    }
256713
public function addEvent(Event $event)
    {
        $this->clear();
        $this->events[$event->getName()] = $event;

        return $this;
    }
1001697
public function subscribe(EventInterface $event) {
        $resources = Resource::getAllResources();

        if ($this->params['additionalResources']) {
            $resources = array_merge($resources, $this->params['additionalResources']);
        }

        $events = [];
        foreach ($resources as $resource) {
            $events[$resource] = ['checkAccess' => 500];
        }

        $manager = $event->getManager();
        $manager->addCallbacks($event->getHandler(), $events);
    }
291203
public static function addEventEntry(AbstractEvent $event)
    {
        return new self(
            null !== $event->aggregateRoot ? $event->aggregateRoot->getId() : null,
            null !== $event->aggregateRoot ? get_class($event->aggregateRoot) : null,
            $event->author,
            get_class($event),
            $event->date,
            serialize($event)
        );
    }
747209
public function updateModel(EventInterface $event) {
        $image = $event->getArgument('image');

        if ($image->hasBeenTransformed()) {
            $image->setBlob($this->imagick->getImageBlob());
        }
    }
1049806
public function storeEvent(EventInterface $event, $granularity = Event::BAT_HOURLY) {
    $stored = TRUE;
    $transaction = db_transaction();

    try {
      // Itemize an event so we can save it
      $itemized = $event->itemize(new EventItemizer($event, $granularity));

      //Write days
      foreach ($itemized[Event::BAT_DAY] as $year => $months) {
        foreach ($months as $month => $days) {
          db_merge($this->day_table_no_prefix)
            ->key(array(
              'unit_id' => $event->getUnitId(),
              'year' => $year,
              'month' => $month
            ))
            ->fields($days)
            ->execute();
        }
      }

      if (($granularity == Event::BAT_HOURLY) && isset($itemized[Event::BAT_HOUR])) {
        // Write Hours
        foreach ($itemized[Event::BAT_HOUR] as $year => $months) {
          foreach ($months as $month => $days) {
            foreach ($days as $day => $hours) {
              // Count required as we may receive empty hours for granular events that start and end on midnight
              if (count($hours) > 0) {
                db_merge($this->hour_table_no_prefix)
                  ->key(array(
                    'unit_id' => $event->getUnitId(),
                    'year' => $year,
                    'month' => $month,
                    'day' => substr($day, 1)
                  ))
                  ->fields($hours)
                  ->execute();
              }
            }
          }
        }

        // If we have minutes write minutes
        foreach ($itemized[Event::BAT_MINUTE] as $year => $months) {
          foreach ($months as $month => $days) {
            foreach ($days as $day => $hours) {
              foreach ($hours as $hour => $minutes) {
                db_merge($this->minute_table_no_prefix)
                  ->key(array(
                    'unit_id' => $event->getUnitId(),
                    'year' => $year,
                    'month' => $month,
                    'day' => substr($day, 1),
                    'hour' => substr($hour, 1)
                  ))
                  ->fields($minutes)
                  ->execute();
              }
            }
          }
        }
      }
    } catch (\Exception $e) {
      $stored = FALSE;
      $transaction->rollback();
      watchdog_exception('BAT Event Save Exception', $e);
    }

    return $stored;
  }
1249675
public function filter(EventInterface $event)
    {
        $result = $this->filter->filter($event);
        if ($result === null) {
            return null;
        }
        return !$result;
    }
775270
public function save(EventInterface $event)
    {
        $this->events[(string) $event->uuid()][] = new $event(
            $event->uuid(),
            $event->type(),
            $event->body(),
            $this->count($event->uuid()),
            $event->occurredOn()->format('Y-m-d H:i:s.u')
        );
    }
692222
public function add(EventInterface $event)
    {
        $index = $this->computeIndex($event);
        if (isset($this->events[$index])) {
            $this->events[$index][] = $event;
        } else {
            $this->events[$index] = array($event);
        }

        ++$this->count;
    }