class EventEmittingService (View source)

Main entry point for generating events

  • TODO: explain Nested events

Properties

protected Event $lastGeneratedEvent

a reference to the last-generated event

protected Event[] $eventContext

This array implements a stack of events. The last element of this stack is the current "parent event".

protected string $currentUsername
protected EventRepository $eventRepository
protected UserService $userDomainService
protected bool $enabled

Methods

bool
isEnabled()

No description

emit(string $eventType, array $data, string $eventClassName = Event::class)

Convenience method for generating an event and directly adding it afterwards to persistence.

generate(string $eventType, array $data, string $eventClassName = Event::class)

Generates a new event, without persisting it yet.

void
add(Event $nodeEvent)

Add the passed event (which has been generated by generate()) to persistence.

void
pushContext()

Push the last-generated event onto the context, nesting all further generated events underneath the top-level one.

void
popContext()

Remove an element from the context stack. Is the reverse operation to pushContext().

Event|null
getCurrentContext()

The current context-event or NULL if none exists currently.

void
initializeCurrentUsername()

Try to set the current username emitting the events, if possible

Details

bool isEnabled()

No description

Return Value

bool

true if the event log is enabled and events should be captured

Event emit(string $eventType, array $data, string $eventClassName = Event::class)

Convenience method for generating an event and directly adding it afterwards to persistence.

Parameters

string $eventType
array $data
string $eventClassName

Return Value

Event

Exceptions

Exception

Event generate(string $eventType, array $data, string $eventClassName = Event::class)

Generates a new event, without persisting it yet.

Note: Make sure to call add($event) afterwards.

Parameters

string $eventType
array $data
string $eventClassName

Return Value

Event

See also

emit()

void add(Event $nodeEvent)

Add the passed event (which has been generated by generate()) to persistence.

This only happens for top-level-events. All events which are attached to some parent event are persisted together with the parent.

Parameters

Event $nodeEvent

Return Value

void

Exceptions

Exception

See also

emit()

void pushContext()

Push the last-generated event onto the context, nesting all further generated events underneath the top-level one.

Return Value

void

void popContext()

Remove an element from the context stack. Is the reverse operation to pushContext().

Return Value

void

protected Event|null getCurrentContext()

The current context-event or NULL if none exists currently.

Return Value

Event|null

protected void initializeCurrentUsername()

Try to set the current username emitting the events, if possible

Return Value

void