Builds the global code of a concrete event.
@param \ManiaScript\Builder\Event\AbstractEvent $event The event.
@return string The built global code.
186427
protected function buildGlobalCodeOfEvent(AbstractEvent $event) {
        $result = '';
        if (!$event->getInline()) {
            $result .= $this->buildHandlerFunction($event);
        }
        return $result;
    }
1151409
public static function fromEvent(Event $event)
    {
        $io = NutStyle::fromComposer($event->getIO());
        $options = Options::fromEvent($event);

        return new static($io, $options);
    }
614918
public function getEventCallbacks($event = null)
    {
        if ($event === null) {
            return $this->eventCallbacks;
        }

        return $this->eventCallbacks[strtolower($event)] ?? [];
    }
136644
public function setVersionMixin(AbstractMappingEvent $event)
    {
        if (!$this->support($event->getDocument())) {
            return;
        }

        $event->getNode()->addMixin('mix:versionable');
    }
1325929
private function buildService($abstract, $version = '')
    {
        $resolved = null;

        if (is_string($abstract)) {
            // If it's a string, throw it at the IoC container
            $resolved = $this->app->make($abstract, array($version));
        } elseif (is_callable($abstract)) {
            // If it's a callable, lets call it with the application and $this
            $resolved = $abstract($version, $this->app, $this);
        }

        return $resolved;
    }
527564
protected function getClosure($abstract, $concrete)
    {
        return function (Container $container, $parameters = []) use ($abstract, $concrete) {
            if ($abstract == $concrete) {
                return $container->build($concrete);
            }

            return $container->make($concrete, $parameters);
        };
    }
990423
public function logEvent(AbstractEvent $event)
    {
        $eventLog = EventLog::addEventEntry($event);

        return $this->repository->save($eventLog);
    }
852516
public function classNameForEvent($event): string
    {
        if ( ! isset($this->eventClasses[$event])) {
            throw new \InvalidArgumentException("Could not find a class for the event {$event}.");
        }
        return $this->eventClasses[$event];
    }
165359
private function determineFilterConfig(AbstractModelAwareEvent $event)
    {
        $environment  = $event->getEnvironment();
        $model        = $event->getModel();
        $dataProvider = $environment->getDataProvider($model->getProviderName());
        $definition   = $environment->getDataDefinition();
        $relationship = $definition->getModelRelationshipDefinition();

        $root = $relationship->getRootCondition();
        if (null !== $root && $root->matches($model)) {
            return $dataProvider->getEmptyConfig()->setFilter($root->getFilterArray());
        }

        $parentFilter = $relationship->getChildCondition(
            $definition->getBasicDefinition()->getParentDataProvider(),
            $model->getProviderName()
        );

        if (null !== $parentFilter) {
            $parentConfig   = $dataProvider->getEmptyConfig()->setFilter($parentFilter->getInverseFilterFor($model));
            $parentProvider = $environment->getDataProvider($parentFilter->getSourceName());
            $parent         = $parentProvider->fetchAll($parentConfig)->get(0);
            return $dataProvider->getEmptyConfig()->setFilter($parentFilter->getFilter($parent));
        }

        // Trigger BC layer in handleFallback().
        if ((null === $root) && (0 === \count($relationship->getChildConditions()))) {
            return null;
        }

        return $dataProvider->getEmptyConfig();
    }
1250981
protected function _buildAmazonS3Path(Event $Event) {
		$data = $Event->getData();
		extract($data);

		$path = '/' . $this->_buildPath($image, true, $hash);

		$config = StorageManager::config($Event->getData('image.adapter'));
		$bucket = $config['adapterOptions'][1];
		if (!empty($config['cloudFrontUrl'])) {
			$cfDist = $config['cloudFrontUrl'];
		} else {
			$cfDist = null;
		}

		$http = 'http';
		$data = $Event->getData();
		if (!empty($data['options']['ssl']) && $data['options']['ssl'] === true) {
			$http = 'https';
		}

		$path = str_replace('\\', '/', $path);
		$bucketPrefix = !empty($data['options']['bucketPrefix']) && $data['options']['bucketPrefix'] === true;
		$Event->result = $this->_buildCloudFrontDistributionUrl($http, $path, $bucket, $bucketPrefix, $cfDist);
		$Event->setData('path', $Event->result);
		$Event->stopPropagation();
	}
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;
    }
1204548
protected function createResponse(ActionEvent\AbstractOnMethodEvent $event) : JsonRpcResponse
    {
        if ($event instanceof ActionEvent\OnMethodSuccessEvent) {
            return $this->responseCreator->createResultResponse($event->getResult(), $event->getJsonRpcRequest());
        } else {
            /** @var $event ActionEvent\OnMethodFailureEvent */
            return $this->responseCreator->createErrorResponse(
                $event->getException(),
                $event->getJsonRpcRequest()
            );
        }
    }
151811
public function serialize(DomainEvent $event): string {
        $reflect = new ReflectionObject($event);
        $props = $reflect->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PRIVATE);

        return json_encode([
            'eventName' => $this->eventNameForClass(get_class($event)),
            'fields'    => $this->serializeFields($props, $event),
        ]);
    }
231281
public function handleUuid(AbstractMappingEvent $event)
    {
        $document = $event->getDocument();

        if (!$document instanceof UuidBehavior) {
            return;
        }

        $node = $event->getNode();

        $accessor = $event->getAccessor();
        $accessor->set(
            'uuid',
            $node->getIdentifier()
        );
    }
112328
public function buildFinished(BuildEvent $event)
    {
        $error = $event->getException();
        if ($error === null) {
            $msg = PHP_EOL . $this->getBuildSuccessfulMessage() . PHP_EOL;
        } else {
            $msg = PHP_EOL . $this->getBuildFailedMessage() . PHP_EOL;
            self::throwableMessage($msg, $error, Project::MSG_VERBOSE <= $this->msgOutputLevel);
        }
        $msg .= PHP_EOL . "Total time: " . self::formatTime(Phing::currentTimeMillis() - $this->startTime) . PHP_EOL;

        if ($error === null) {
            $this->printMessage($msg, $this->out, Project::MSG_VERBOSE);
        } else {
            $this->printMessage($msg, $this->err, Project::MSG_ERR);
        }
    }
187678
public static function generate(Event $event)
    {
        $args = $event->getArguments();
        if (empty($args)) {
            echo "Usage:\n\n"
                . "    composer yasql-generate -- YASQL_FILE [INDENTATION]\n\n"
                . "By default, INDENTATION is 2\n";
            die(1);
        }

        echo Controller::generate(
            file_get_contents($args[0]),
            null,
            $args[1] ?? 2
        );
    }
406265
protected function buildInlineCode() {
        $result = '';
        foreach ($this->events as $event) {
            /* @var $event \ManiaScript\Builder\Event\AbstractEvent */
            if ($event->getInline()) {
                $result .= $event->getCode() . PHP_EOL;
            } else {
                $result .= $this->buildHandlerFunctionCall($event);
            }
        }
        return $result;
    }