Parse the given event and payload and prepare them for dispatching.

@param mixed $event
@param mixed $payload

@return array
964560
protected function parseEventAndPayload($event, $payload)
    {
        if (is_object($event)) {
            list($payload, $event) = [[$event], get_class($event)];
        }

        return [$event, Arr::wrap($payload)];
    }
763582
function parseRequest( $payload )
    {
        $request = new ggRESTRequest();
        if ( $request->decodeStream( $payload ) )
        {
            $this->ResponseType = $request->responseType();
            $this->JsonpCallback = $request->jsonpCallback();
            return $request;
        }
        else
        {
            $this->ResponseType = '';
            return false;
        }
    }
155805
protected function getBindings(string $event) {
        if (!isset($this->bindings[$event]) || !is_array($this->bindings[$event])) {
            return [];
        }
        return $this->bindings[$event];
    }
979270
protected function fireEvent($event, $payload = [ ], $halt = false)
    {
        if (! isset($this->dispatcher)) {
            $this->initEventDispatcher();
        }

        $dispatcher = $this->dispatcher;
        $status     = $this->dispatcherStatus;
        if (! $dispatcher || $status === false) {
            return;
        }
        $method = $halt ? 'until' : 'fire';

        return $dispatcher->{$method}($event, $payload);
    }
147008
public static function json($payload){
        static::type(static::TYPE_JSON);
        static::$payload[] = json_encode($payload, Options::get('core.response.json_flags',JSON_NUMERIC_CHECK|JSON_BIGINT_AS_STRING));
    }
827791
public function handle($event, $payload)
    {
        list($model) = $payload;

        // Get the action from the event name
        preg_match('#\.(\w+)#', $event, $matches);
        $action = $matches[1];

        // If there is matching callback method on the model, call it, passing
        // any additional event arguments to it
        $method = 'on'.Str::studly($action);
        if (method_exists($model, $method)) {
            return call_user_func_array([$model, $method], array_slice($payload, 1));
        }
    }
423796
public function onDeleted($event, $payload) {

        // Destructure params
        list($model) = $payload;

        // If the model is soft deleted and the config states to NOT delete if
        // soft deleted, abort here.
        if ($this->keepsFilesOnDelete($model)) return;

        // Check that the model supports uploads through Upchuck
        if (!$this->supportsUploads($model)
            || !($attributes = $model->getUploadAttributes())) return;

        // Loop through the all of the upload attributes and get the values using
        // "original" so that you get the file value before it may have been cleared.
        event(new Events\HandlingDeleted($model));
        foreach($attributes as $attribute) {
            if (!$url = $model->getOriginal($attribute)) continue;
            $this->storage->delete($url);
        }
        event(new Events\HandledDeleted($model));
    }
386159
private function performPostRequest($payload)
	{
	    $payload[] = ['type' => $this->apiXType, 'routing' => $this->apiXRoute, 'token' => $this->apiXToken];
		$this->response = $this->client->request('POST', [
            'query' => $payload
        ]);
	}
1228687
public function handle($event, $payload)
    {
        list($model) = $payload;

        // Don't log changes to pivot models.  Even though a user may have initiated
        // this, it's kind of meaningless to them.  These events can happen when a
        // user messes with drag and drop positioning.
        if (is_a($model, \Illuminate\Database\Eloquent\Relations\Pivot::class)) {
            return;
        }

        // Get the action of the event
        preg_match('#eloquent\.(\w+)#', $event, $matches);
        $action = $matches[1];
        if (!in_array($action, $this->supported)) {
            return;
        }

        // Get the admin acting on the record
        $admin = app('decoy.user');

        // If `log_changes` was configed as a callable, see if this model event
        // should not be logged
        if ($check = config('decoy.site.log_changes')) {
            if (is_bool($check) && !$check) {
                return;
            }
            if (is_callable($check)) {
                \Log::error('Callable log_changes have been deprecated');
                if (!call_user_func($check, $model, $action, $admin)) {
                    return;
                }
            }
        } else {
            return;
        }

        // Check with the model itself to see if it should be logged
        if (method_exists($model, 'shouldLogChange')) {
            if (!$model->shouldLogChange($action)) {
                return;
            }

        // Default to not logging changes if there is no shouldLogChange()
        } else {
            return;
        }

        // Log the event
        Change::log($model, $action, $admin);
    }
1085751
private function setPayload($payload)
	{
		if ( (is_string($payload) && empty($payload)) || (is_array($payload) && count($payload) == 0) )
		{
			// Empty strings or arrays are not allowed
			throw new \InvalidArgumentException('Invalid payload for message. Payload was empty, but not null)');
		}
		else if (is_array($payload) || null === $payload)
		{
			if ( isset($payload['aps']) )
			{
				// Reserved key is used
				throw new \InvalidArgumentException('Invalid payload for message. Custom payload may not contain the reserved "aps" key.');
			}
			else
			{
				// This is okay, set as payload
				$this->payload = $payload;
			}
		}
		else
		{
			// Try to decode JSON string payload
			$payload = json_decode($payload, true);

			// Check if decoding the payload worked
			if (null === $payload) {
				throw new \InvalidArgumentException('Invalid payload for message. Payload was invalid JSON.');
			}

			// Set as payload
			$this->payload = $payload;
		}
	}
895864
protected function getContext(Event $event)
    {
        $context = [
            'event_name' => $event->getEventName(),
            'event_details' => $event->getEventDetails(),
        ];

        if ($event instanceof ExternalSystemHTTPEvent) {
            $context['http_uri'] = $event->getHttpURI();
            $context['request_body'] = $event->getRequestHttpBody();
            $context['request_headers'] = $event->getRequestHttpHeaders();
            $context['response_body'] = $event->getResponseHttpBody();
            $context['response_headers'] = $event->getResponseHttpHeaders();
            $context['status'] = $event->getStatus();
            $context['exchange'] = [
                'id' => $event->getExchangeId(),
            ];
            $context['transaction'] = [
                'id' => $event->getTransactionId(),
                'uri' => $event->getFromUri(),
            ];
        } elseif (
            $event instanceof HandlerEvent ||
            $event instanceof ProcessEvent
        ) {
            $contextExchangeDetails = $event->getExchange();
            $context['exchange'] = [
                'id' => $contextExchangeDetails->getId(),
                'uri' => $contextExchangeDetails->getHeader('from'),
                'type' => (true === $contextExchangeDetails->getHeader('async')) ? 'async' : 'sync',
            ];
        }

        if ($event instanceof ProcessEvent) {
            $endpointUri = $event->getProcessingContext()->get('resolved_uri');
            if ($endpointUri) {
                $context['endpoint_uri'] = $endpointUri;
            }

            $processor = $event->getProcessor();
            $context['processor'] = $this->getProcessorInfo($processor);

            if ($processor instanceof LogsExchangeDetails) {
                $context['exchange']['detail'] = $event->getExchange();
            }
        }

        if ($event instanceof HandlerEvent) {
            $context['exchange']['detail'] = $event->getExchange();
        }

        if ($event instanceof ProcessingErrorEvent || $event instanceof HandlerErrorEvent || $event instanceof MalformedInputEvent) {
            $context['exception'] = $event->getException();
        }

        return $context;
    }
1152556
private function normalizeEvent($event)
    {
        if (is_object($event)) {
            $event = get_class($event);
        }

        if (preg_match('/^bootstrapp(ing|ed): /', $event)) {
            return $event;
        }

        // Events can be formatted as 'event.name: parameters'
        $segments = explode(':', $event);

        return $segments[0];
    }
747052
public function serialize(Event $event)
    {
        $editable = $event->getWorkspace() ?
            $this->authorization->isGranted('EDIT', $event) :
            false !== $event->isEditable();

        return [
            'id' => $event->getId(),
            'title' => $event->getTitle(),
            'start' => $event->getStart() ? DateNormalizer::normalize($event->getStart()) : null,
            'end' => $event->getEnd() ? DateNormalizer::normalize($event->getEnd()) : null,
            'color' => $event->getPriority(),
            'allDay' => $event->isAllDay(),
            'durationEditable' => !$event->isTask() && false !== $event->isEditable(),
            'owner' => $this->userSerializer->serialize($event->getUser()),
            'description' => $event->getDescription(),
            'workspace' => $event->getWorkspace() ? $this->workspaceSerializer->serialize($event->getWorkspace(), [Options::SERIALIZE_MINIMAL]) : null,
            'className' => 'event_'.$event->getId(),
            'editable' => $editable,
            'meta' => $this->serializeMeta($event),
        ];
    }
1283516
protected function resolveAndHandle(array $payload)
    {
        list($class, $method) = Str::parseCallback($payload['job'], 'handle');

        $this->instance = $this->resolve($class);

        call_user_func(array($this->instance, $method), $this, $payload['data']);
    }
674864
protected function respond($event, $error, $status, $payload = [])
    {
        $response = $this->events->fire($event, $payload, true);

        return $response ?: $this->response->json(arrayView('phpsoft.users::errors/authenticate', [
            'error' => $error
        ]), $status);
    }
818004
public function fire($event, $payload=[], $halt=false)
    {
        return $this->dispatcher->fire($event, $payload, $halt);
    }
1050593
protected function fireCacheEvent( $event, $payload )
	{
		if ( !isset( $this->events ) )
			return null;

		switch ( $event )
		{
			case 'hit':
				if ( count( $payload ) == 2 )
					$payload[] = [];

				return $this->events->fire( new Events\CacheHit( $payload[0], $payload[1], $payload[2] ) );
			case 'missed':
				if ( count( $payload ) == 1 )
					$payload[] = [];

				return $this->events->fire( new Events\CacheMissed( $payload[0], $payload[1] ) );
			case 'delete':
				if ( count( $payload ) == 1 )
					$payload[] = [];

				return $this->events->fire( new Events\KeyForgotten( $payload[0], $payload[1] ) );
			case 'write':
				if ( count( $payload ) == 3 )
					$payload[] = [];

				return $this->events->fire( new Events\KeyWritten( $payload[0], $payload[1], $payload[2], $payload[3] ) );
		}
		return null;
	}