Gets the api attributes and makes them available to the forum.

@param Serializing $event
965850
public function prepareApiAttributes(Serializing $event)
    {
        if ($event->isSerializer(ForumSerializer::class)) {
            $event->attributes['canUpload'] = $event->actor->can('flagrow.upload');
            $event->attributes['canDownload'] = $event->actor->can('flagrow.upload.download');
        }
    }
982300
private function getOptionsData($event)
    {
        $items = [];
        
        foreach ($this->model->find()->asArray($this->asArray)->all() as $item) {
            if (is_callable($this->labelField, false)) {
                $label = call_user_func($this->labelField, $item);
            } else {
                if ($this->labelField === null) {
                    $this->labelField = array_keys($item);
                }
                $array = ArrayHelper::filter($item, $this->labelField);
                
                foreach ($array as $key => $value) {
                    if ($event->sender->isI18n($key)) {
                        $array[$key] = I18n::decodeFindActive($value);
                    }
                }
                
                $label = $this->labelTemplate ? vsprintf($this->labelTemplate, $array) : implode(', ', $array);
            }
        
            $items[] = ['value' => (int) $item[$this->modelPrimaryKey], 'label' => $label];
        }
        
        return ['items' => $items];
    }
375404
public function evaluateAttributes($event)
    {
        if (in_array($event->name, $this->events)) {
            foreach ($this->attributes as $type => $attributes) {
                $method = 'get' . $type . 'value';
                if (method_exists($this, $method)) {
                    foreach ( (array) $attributes as $attribute) {
                        $this->owner->$attribute = $this->$method($this->owner->$attribute, $event->name);
                    }
                }
            }
        }
    }
1305733
private function addEvent($event)
    {
        if (is_string($event)) {
            $event = Event::named($event);
        }

        if (!$event instanceof EventInterface) {
            throw new \InvalidArgumentException(
                'Events should be provides as Event instances or string, received type: ' . gettype($event)
            );
        }

        $this->events[] = $event;

        return $event;
    }
453667
public function beforeApiRequestSend($event)
    {
        $request = $event->request;
        $data = $request->getData();
        $data['openid'] = $this->getOpenid();
        $request->setData($data);

        parent::beforeApiRequestSend($event);
    }
454770
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        $theme = $this->activeTheme->getName();
        $controllers = $request->attributes->get(static::ATTRIBUTE_KEY);
        if (isset($controllers[$theme])) {
            $request->attributes->set('_controller', $controllers[$theme]);
        }

        // Get rid of the attribute in the request to avoid it showing up in generated URLs
        $request->attributes->remove(static::ATTRIBUTE_KEY);
        $routeParams = $request->attributes->get('_route_params');
        if (null !== $routeParams) {
            unset($routeParams[static::ATTRIBUTE_KEY]);
            $request->attributes->set('_route_params', $routeParams);
        }
    }
155805
protected function getBindings(string $event) {
        if (!isset($this->bindings[$event]) || !is_array($this->bindings[$event])) {
            return [];
        }
        return $this->bindings[$event];
    }
185538
public function addUrlsOnPostSerialize(ObjectEvent $event)
    {
        $article = $event->getObject();
        $visitor = $event->getVisitor();
        $context = $event->getContext();
        $request = $this->requestStack->getCurrentRequest();

        if (!$article instanceof ArticleDocument || !$context->attributes->containsKey('website') || !$request) {
            return;
        }

        /** @var RequestAttributes $attributes */
        $attributes = $request->get('_sulu');
        if (!$attributes) {
            return;
        }

        /** @var Webspace $webspace */
        $webspace = $attributes->getAttribute('webspace');
        if (!$webspace) {
            return;
        }

        $urls = [];
        foreach ($webspace->getAllLocalizations() as $localization) {
            $locale = $localization->getLocale();
            $route = $this->routeRepository->findByEntity(get_class($article), $article->getUuid(), $locale);

            $urls[$locale] = '/';
            if ($route) {
                $urls[$locale] = $route->getPath();
            }
        }

        $visitor->addData('urls', $context->accept($urls));
    }
401975
public function onKernelRequestAuthToken($event)
  {
    if (!$event->isMasterRequest()) return;
    
    // Bearer jwt
    $auth = $event->getRequest()->getHeaderLine('Authorization');
    if (!$auth) return;
    
    $authParts = explode(' ',$auth);
    $jwt = $authParts[count($authParts)-1];
    
    if (!$jwt) return;

    $jwtPayload = $this->jwtCoder->decode($jwt);
    
    $authToken = new AuthToken($jwtPayload['username'],$jwtPayload['roles']);
    
    $event->getRequest()->setAttribute('authToken',$authToken);
  }
1101721
protected function getEventObject($event, $data)
    {
        $eventClass = new ReflectionClass($this->getEventClass($event));

        return $eventClass->newInstanceArgs($data);
    }
220548
private function getEventMessage(Event $event)
    {
        return json_encode([
            'title' => $event->getTitle(),
            'text' => $event->getText(),
            'timestamp' => $event->getTimeStamp(),
            'host' => $event->getHost(),
            'type' => $event->getType()
        ]);
    }
213131
protected function getPayloadFromEvent($event)
    {
        if (method_exists($event, 'broadcastWith')) {
            return $event->broadcastWith();
        }

        $payload = array();

        //
        $reflection = new ReflectionClass($event);

        foreach ($reflection->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
            $key = $property->getName();

            $value = $property->getValue($event);

            $payload[$key] = $this->formatProperty($value);
        }

        return $payload;
    }
182878
protected function getValue($event)
    {
        if (!empty($this->owner->{$this->attribute})) {
            return $this->owner->{$this->attribute};
        }
        if ($this->value === null) {
            $uuid = $this->generateUUID();
        } else {
            $uuid = parent::getValue($event);
        }
        return $this->ensureUnique ? $this->makeUnique($uuid) : $uuid;
    }
993281
public function getHooks(string $event): array
	{
		return isset(static::$traitHooks[static::class][$event]) ? $this->bindHooks(static::$traitHooks[static::class][$event]) : [];
	}
882184
public function resolveContentOnPostSerialize(ObjectEvent $event)
    {
        $article = $event->getObject();
        $visitor = $event->getVisitor();
        $context = $event->getContext();

        if (!$article instanceof ArticleInterface || !$context->attributes->containsKey('website')) {
            return;
        }

        $visitor->addData('uuid', $context->accept($article->getArticleUuid()));
        $visitor->addData('pageUuid', $context->accept($article->getPageUuid()));

        $extensionData = $article->getExtensionsData()->toArray();
        $extension = [];
        foreach ($extensionData as $name => $data) {
            $extension[$name] = $this->extensionManager->getExtension('article', $name)->getContentData($data);
        }

        $visitor->addData('extension', $extension);
    }
1127058
public function process(array $event)
    {
        $serverData = $this->getServerData();

        /** skip processing if for some reason request data is not present (CLI or wonky SAPIs) */
        /** @noinspection UnSafeIsSetOverArrayInspection */
        if (!isset($serverData['REQUEST_URI'])) {
            return $event;
        }

        $extras = [];

        /** @noinspection UnSafeIsSetOverArrayInspection */
        if (isset($serverData['REQUEST_METHOD'])) {
            $extras['http_method'] = $serverData['REQUEST_METHOD'];
        }

        /** @noinspection UnSafeIsSetOverArrayInspection */
        if (isset($serverData['SERVER_NAME'])) {
            $extras['server'] = $serverData['SERVER_NAME'];
        }

        /** @noinspection UnSafeIsSetOverArrayInspection */
        if (isset($serverData['HTTP_REFERER'])) {
            $extras['referrer'] = $serverData['HTTP_REFERER'];
        }

        /** @noinspection UnSafeIsSetOverArrayInspection */
        if (isset($serverData['REMOTE_ADDR'])) {
            $extras['ip'] = $serverData['REMOTE_ADDR'];
        }

        /** @noinspection SpellCheckingInspection */
        $event['extra'] = array_merge($event['extra'], $extras);

        return $event;
    }
673639
public function getSuccessLines(Event $event, $apiResponse)
    {
        $json = json_decode($apiResponse);
        $json = $json->responseData;

        $messages = [];

        $messages[] = sprintf(
            "%s results [ %s ]",
            (isset($json->cursor->estimatedResultCount)) ? $json->cursor->estimatedResultCount : "0",
            $json->cursor->moreResultsUrl
        );

        return $messages;
    }