Collect data for GuzzleHttp

@param GuzzleHttpEvent $event
356717
public function onGuzzleHttpCommand(GuzzleHttpEvent $event)
    {
        $request = $event->getRequest();
        $response = $event->getResponse();
        $statusCode = $response->getStatusCode();

        if ($statusCode > 499) {
            $this->data['guzzleHttp']['has5x'] = true;
        }

        if ($statusCode > 399 && $statusCode < 500) {
            $this->data['guzzleHttp']['has4x'] = true;
        }

        $data = [
            'uri' => $request->getUri(),
            'method' => $request->getMethod(),
            'responseCode' => $statusCode,
            'responseReason' => $response->getReasonPhrase(),
            'executionTime' => $event->getExecutionTime(),
            'curl' => [
                'redirectCount' => (isset($response->curlInfo['redirect_count'])) ? $response->curlInfo['redirect_count'] : 0,
                'redirectTime' => (isset($response->curlInfo['redirect_time'])) ? $response->curlInfo['redirect_time'] : 0,
            ],
            'cache' => (isset($response->cached)) ? 1 : 0,
            'cacheTtl' => (isset($response->cacheTtl)) ? $response->cacheTtl : 0,
        ];

        $this->data['guzzleHttp']['commands']->enqueue($data);
    }
342659
public function onAfterRespond(Event $event)
    {
        /**
         * @var Container $container
         * @var Collector $collector
         * @var Profiler  $profiler
         */
        $container = $event['app']->getContainer();
        $collector = $container->get('debugger.collector');
        $profiler  = $container->get('profiler');

        $profiler->mark(__FUNCTION__, [
            'tag' => 'system.process',
        ]);
    }
65938
protected function sendEvent(RequestInterface $request, ResponseInterface $response)
    {
        $key = $this->getEventKey($request);
        $event = $this->events[$key];

        unset($this->events[$key]);

        $event->setExecutionStop();
        $event->setResponse($response);
        $this->eventDispatcher->dispatch(GuzzleHttpEvent::EVENT_NAME, $event);
    }
31123
public function onRequestException(Event $event)
    {
        if (!$event['exception'] instanceof CurlException) {
            return;
        }

        $request = $event['request'];
        if (!$this->canCache->canCacheRequest($request)) {
            return;
        }

        if ($response = $this->storage->fetch($request)) {
            $response->setHeader('Age', time() - strtotime($response->getDate() ? : 'now'));
            if (!$this->canResponseSatisfyFailedRequest($request, $response)) {
                return;
            }
            $request->getParams()->set('cache.hit', 'error');
            $request->setResponse($response);
            $this->addResponseHeaders($request, $response);
            $event->stopPropagation();
        }
    }
1335982
public function onPostDeserialize(ObjectEvent $event)
    {
        /** @var TargetGroupInterface $targetGroup */
        $targetGroup = $event->getObject();

        if (!$targetGroup instanceof TargetGroupInterface) {
            return;
        }

        /* @var TargetGroupWebspaceInterface $webspace */
        if ($targetGroup->getWebspaces()) {
            foreach ($targetGroup->getWebspaces() as $webspace) {
                $webspace->setTargetGroup($targetGroup);
            }
        }

        if ($targetGroup->getRules()) {
            foreach ($targetGroup->getRules() as $rule) {
                $rule->setTargetGroup($targetGroup);
            }
        }
    }
827225
public function onKernelRequest(GetResponseEvent $event): void
    {
        $request = $event->getRequest();
        if (
            !($attributes = RequestAttributesExtractor::extractAttributes($request))
            || !$attributes['receive']
        ) {
            return;
        }

        if (null === $filters = $request->attributes->get('_api_filters')) {
            $queryString = RequestParser::getQueryString($request);
            $filters = $queryString ? RequestParser::parseRequestParams($queryString) : null;
        }

        $context = null === $filters ? [] : ['filters' => $filters];
        if ($this->serializerContextBuilder) {
            // Builtin data providers are able to use the serialization context to automatically add join clauses
            $context += $normalizationContext = $this->serializerContextBuilder->createFromRequest($request, true, $attributes);
            $request->attributes->set('_api_normalization_context', $normalizationContext);
        }

        if (isset($attributes['collection_operation_name'])) {
            $request->attributes->set('data', $request->isMethod('POST') ? null : $this->getCollectionData($attributes, $context));

            return;
        }

        $data = [];

        if ($this->identifierConverter) {
            $context[IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER] = true;
        }

        try {
            $identifiers = $this->extractIdentifiers($request->attributes->all(), $attributes);

            if (isset($attributes['item_operation_name'])) {
                $data = $this->getItemData($identifiers, $attributes, $context);
            } elseif (isset($attributes['subresource_operation_name'])) {
                // Legacy
                if (null === $this->subresourceDataProvider) {
                    throw new RuntimeException('No subresource data provider.');
                }

                $data = $this->getSubresourceData($identifiers, $attributes, $context);
            }
        } catch (InvalidIdentifierException $e) {
            throw new NotFoundHttpException('Not found, because of an invalid identifier configuration', $e);
        }

        if (null === $data) {
            throw new NotFoundHttpException('Not Found');
        }

        $request->attributes->set('data', $data);
    }
52160
public static function onFlushContent(Event $event)
    {
        $content = $event->getTarget();
        if (!($content instanceof AbstractClassContent)) {
            return;
        }

        $application = $event->getApplication();
        $em = $application->getEntityManager();
        $uow = $em->getUnitOfWork();
        if ($uow->isScheduledForDelete($content)) {
            return;
        }

        if (null !== $page = $content->getMainNode()) {
            if (null !== $page->getMetaData()) {
                $newEvent = new Event($page, $content);
                $newEvent->setDispatcher($event->getDispatcher());
                self::onFlushPage($newEvent);
            }
        }
    }
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));
    }
146573
public function postSetData(FormEvent $event)
    {
        $collection = $event->getData();
        $form = $event->getForm();

        if ($collection instanceof PersistentCollection){
            foreach ($collection as $key => $file){
                if ($file instanceof MultiFileInterface){
                    try {
                        $this->fileManager->copyFileToTemporaryDirectory($file);
                    } catch (\Gaufrette\Exception\FileNotFound $e) {
                        $form->remove($key);
                        $collection->removeElement($file);
                    }
                }
            }
        }
    }
1139257
public function onPostDispatch(ActionDispatchEvent $event)
    {
        $message = sprintf(
            'Complete handle API method "%s". Response object: %s',
            $event->getAction()->getName(),
            get_class($event->getResponse())
        );

        $this->logger->debug($message);
    }
324930
public function request($url, $requestData) {
        if(!class_exists('GuzzleHttp\Client')) {
            throw new RuntimeException('The guzzle client is not installed. Please install guzzlehttp/guzzle');
        }

        $client = new Client();

        //We do not care exceptions, this will handled by the user
        $response = $client->request('POST', $url, ['form_params' => $requestData]);

        return $response->getBody()->getContents();
    }
1217592
public function handleFlush(FlushEvent $event)
    {
        if (count($this->documents) < 1) {
            return;
        }

        foreach ($this->documents as $documentData) {
            $document = $this->documentManager->find($documentData['uuid'], $documentData['locale']);
            $this->documentManager->refresh($document);

            $this->indexer->index($document);
        }
        $this->indexer->flush();
        $this->documents = [];
    }
1062506
public function onAfterRouting(Event $event)
    {
        /**
         * @var Container $container
         * @var Collector $collector
         * @var Profiler  $profiler
         */
        $container = $event['app']->getContainer();
        $collector = $container->get('debugger.collector');
        $profiler  = $container->get('profiler');

        /** @var MainRouter $router */
        $router = $event['app']->router;

        $collector['package.name']    = $container->get('current.package')->getName();
        $collector['package.class']   = get_class($container->get('current.package'));
        $collector['controller.task'] = $container->get('current.package')->getTask();
        $collector['routing.matched'] = iterator_to_array($container->get('current.route'));

        $profiler->mark(__FUNCTION__, [
            'tag' => 'system.process',
        ]);
    }
235818
public function onComplete(CompleteEvent $event)
    {
        $request = $event->getRequest();
        $response = $event->getResponse();

        // Cache the response if it can be cached and isn't already
        if ($request->getConfig()->get('cache_lookup') === 'MISS'
            && call_user_func($this->canCache, $request)
            && Utils::canCacheResponse($response)
        ) {
            // Store the date when the response was cached
            $response->setHeader('X-Guzzle-Cache-Date', gmdate('D, d M Y H:i:s T', time()));
            $this->storage->cache($request, $response);
        }

        $this->addResponseHeaders($request, $response);
    }
969075
public function actionDownload($event)
    {
        $results = $event->object->serve();
        if (!$results || !empty($results['error'])) {
            $errorMessage = isset($results['error']) ? $results['error'] : 'Unknown error';
            throw new HttpException(500, $errorMessage);
        }
        $event->handled = true;
    }
931313
public function receiveEvent(Event $event): void
    {
        $event->freeze();
        $schema = $event::schema();
        $curie = $schema->getCurie();

        $vendor = $curie->getVendor();
        $package = $curie->getPackage();
        $category = $curie->getCategory();

        foreach ($schema->getMixinIds() as $mixinId) {
            $this->dispatch($mixinId, $event);
        }

        foreach ($schema->getMixinCuries() as $mixinCurie) {
            $this->dispatch($mixinCurie, $event);
        }

        $this->dispatch($schema->getCurieMajor(), $event);
        $this->dispatch($curie->toString(), $event);

        $this->dispatch(sprintf('%s:%s:%s:*', $vendor, $package, $category), $event);
        $this->dispatch(sprintf('%s:%s:*', $vendor, $package), $event);
        $this->dispatch(sprintf('%s:*', $vendor), $event);
        $this->dispatch('*', $event);
    }
1030164
public function postSetData(FormEvent $event)
    {
        if ($event->getForm()->isRoot()) {
            // Collect basic information about each form
            $this->dataCollector->collectConfiguration($event->getForm());

            // Collect the default data
            $this->dataCollector->collectDefaultData($event->getForm());
        }
    }