@param DistanceMatrixRequestInterface $request

@return DistanceMatrixResponse
971660
public function process(DistanceMatrixRequestInterface $request)
    {
        $httpRequest = $this->createRequest($request);
        $httpResponse = $this->getClient()->sendRequest($httpRequest);

        $response = $this->deserialize(
            $httpResponse,
            DistanceMatrixResponse::class,
            (new Context())->setNamingStrategy(new SnakeCaseNamingStrategy())
        );

        $response->setRequest($request);

        return $response;
    }
1009973
public function importLocations(ServerRequestInterface $request): ResponseInterface
    {
        $parent_id = (int) $request->getQueryParams()['parent_id'];

        $files = array_merge(
            glob(WT_DATA_DIR . 'places/*.csv', GLOB_NOSORT),
            glob(WT_DATA_DIR . 'places/*.geojson', GLOB_NOSORT)
        );

        $files = array_map(static function (string $place): string {
            return substr($place, strlen(WT_DATA_DIR . 'places/'));
        }, $files);

        asort($files);

        return $this->viewResponse('admin/map-import-form', [
            'data_folder' => WT_DATA_DIR,
            'title'       => I18N::translate('Import geographic data'),
            'parent_id'   => $parent_id,
            'files'       => $files,
        ]);
    }
12385
public function matchRequest(Request $request, RouteCollectionInterface $routes)
    {
        $path   = $request->getPath();
        $filtered = $this->filterByMethodAndScheme($routes, $request);

        if ($filtered instanceof CachedCollectionInterface && 0 !== count($r = $route->findByStaticPath($path))) {
            $filtered = $r;
        }

        $nomatch = array_diff_key($routes->all(), $filtered->all());

        foreach ($filtered->all() as $name => $route) {
            $rctx = $route->getContext();

            // does it match host?
            if (!$this->matchHost($rctx, $request, $route->getHost())) {
                $nomatch[$name] = $route;
                continue;
            }

            // does it match static path?
            if (0 !== strpos($path, $rctx->getStaticPath())) {
                continue;
            }

            // does it match pattern described on the route?
            if ((bool)preg_match_all($rctx->getRegex(), $path, $matches)) {
                $vars    = $this->getMatchedVars($route, $matches);
                $handler = $route->getHandler();

                return new MatchContext(self::MATCH, $name, $request, $handler, $vars);
            }

            $nomatch[$name] = $route;
        }

        return new MatchContext($this->getMatchFailureReason($nomatch, $request), null, $request, null);
    }
1049870
public function mapDataEdit(ServerRequestInterface $request): ResponseInterface
    {
        $parent_id = (int) $request->getQueryParams()['parent_id'];
        $place_id  = (int) $request->getQueryParams()['place_id'];
        $hierarchy = $this->getHierarchy($place_id);
        $fqpn      = empty($hierarchy) ? '' : $hierarchy[0]->fqpn;
        $location  = new Location($fqpn);

        if ($location->id() !== 0) {
            $lat = $location->latitude();
            $lng = $location->longitude();
            $id  = $place_id;
        } else {
            $lat = '';
            $lng = '';
            $id  = $parent_id;
        }

        $title = e($location->locationName());

        $breadcrumbs = [
            route('admin-control-panel') => I18N::translate('Control panel'),
            route('map-data')            => I18N::translate('Geographic data'),
        ];

        foreach ($hierarchy as $row) {
            $breadcrumbs[route('map-data', ['parent_id' => $row->pl_id])] = $row->pl_place;
        }

        if ($place_id === 0) {
            $breadcrumbs[] = I18N::translate('Add');
        } else {
            $breadcrumbs[] = I18N::translate('Edit');
            $title         .= ' — ' . I18N::translate('Edit');
        }

        return $this->viewResponse('admin/location-edit', [
            'breadcrumbs' => $breadcrumbs,
            'title'       => $title,
            'location'    => $location,
            'place_id'    => $place_id,
            'parent_id'   => $parent_id,
            'hierarchy'   => $hierarchy,
            'lat'         => $lat,
            'lng'         => $lng,
            'ref'         => $id,
            'data'        => $this->mapLocationData($id),
        ]);
    }
662324
public function toResponse($request)
    {
        $resource = new FractalItem(
            $this->item,
            app()->make('InetStudio\PollsPackage\Polls\Contracts\Transformers\Back\Resource\ShowTransformerContract')
        );

        $serializer = app()->make('InetStudio\AdminPanel\Base\Contracts\Serializers\SimpleDataArraySerializerContract');

        $manager = new Manager();
        $manager->setSerializer($serializer);

        $transformation = $manager->createData($resource)->toArray();
        $transformation['success'] = ((bool) $transformation['id']);

        return response()->json($transformation);
    }
1239203
protected double[][] buildDistanceMatrix(ArrayDBIDs ids, DistanceQuery<?> dq) {
    final int size = ids.size();
    double[][] dmat = new double[size][size];
    final boolean square = !dq.getDistanceFunction().isSquared();
    FiniteProgress prog = LOG.isVerbose() ? new FiniteProgress("Computing distance matrix", (size * (size - 1)) >>> 1, LOG) : null;
    Duration timer = LOG.isStatistics() ? LOG.newDuration(this.getClass().getName() + ".runtime.distancematrix").begin() : null;
    DBIDArrayIter ix = ids.iter(), iy = ids.iter();
    for(ix.seek(0); ix.valid(); ix.advance()) {
      double[] dmat_x = dmat[ix.getOffset()];
      for(iy.seek(ix.getOffset() + 1); iy.valid(); iy.advance()) {
        final double dist = dq.distance(ix, iy);
        dmat[iy.getOffset()][ix.getOffset()] = dmat_x[iy.getOffset()] = square ? (dist * dist) : dist;
      }
      if(prog != null) {
        int row = ix.getOffset() + 1;
        prog.setProcessed(row * size - ((row * (row + 1)) >>> 1), LOG);
      }
    }
    LOG.ensureCompleted(prog);
    if(timer != null) {
      LOG.statistics(timer.end());
    }
    return dmat;
  }
947600
public function moveAction(Request $request): Response
    {
        $form = $this->formFactory->moveLocation(
            new LocationMoveData()
        );
        $form->handleRequest($request);

        $location = $form->getData()->getLocation();

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (LocationMoveData $data) {
                $location = $data->getLocation();
                $newParentLocation = $data->getNewParentLocation();

                if (!$newParentLocation->getContent()->getContentType()->isContainer) {
                    throw new InvalidArgumentException(
                        '$newParentLocation',
                        'Cannot move location to a parent that is not a container'
                    );
                }

                $this->locationService->moveSubtree($location, $newParentLocation);

                $this->notificationHandler->success(
                    $this->translator->trans(
                        /** @Desc("'%name%' moved to '%location%'") */
                        'location.move.success',
                        ['%name%' => $location->getContentInfo()->name, '%location%' => $newParentLocation->getContentInfo()->name],
                        'location'
                    )
                );

                return new RedirectResponse($this->generateUrl('_ezpublishLocation', [
                    'locationId' => $location->id,
                ]));
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        return $this->redirect($this->generateUrl('_ezpublishLocation', [
            'locationId' => $location->id,
        ]));
    }
599875
public static function fromRequest(RequestInterface $request)
    {
        if ($request->hasHeader('X-Endpoint')) {
            $name = $request->getHeaderLine('X-Endpoint');
            
            if (! isset(BaseApi::$endpointDefinitions[$name])) {
                throw new \InvalidArgumentException('Could not resolve Endpoint from the request: \n'.$request->getRequestTarget());
            }
            
            /** @var BaseEndpoint $endpointClass */
            $endpointClass = BaseApi::$endpointDefinitions[$name]['class'];

            return new $endpointClass(Region::create($request->getHeaderLine('X-Region')));
        }
        
        $matchingScore = -1;
        /** @var Endpoint $endpointInstance */
        $endpointInstance = null;

        foreach (BaseApi::$endpointDefinitions as $urlTemplate => $definition) {
            $score = levenshtein($request->getRequestTarget(), $urlTemplate);
            if ($score > $matchingScore) {
                $matchingScore = $score;
                $endpointInstance = $definition['instance'];
            }
        }
        
        return $endpointInstance;
    }
717603
public function process(PlaceSearchRequestInterface $request)
    {
        $httpRequest = $this->createRequest($request);
        $httpResponse = $this->getClient()->sendRequest($httpRequest);

        $response = $this->deserialize(
            $httpResponse,
            PlaceSearchResponse::class,
            (new Context())->setNamingStrategy(new SnakeCaseNamingStrategy())
        );

        $response->setRequest($request);

        return new PlaceSearchResponseIterator($this, $response);
    }
1086915
public function create(ServerRequestInterface $request): ResponseInterface
    {
        $tree_name  = $request->get('tree_name', '');
        $tree_title = $request->get('tree_title', '');

        // We use the tree name as a file name, so no directory separators allowed.
        $tree_name = basename($tree_name);

        if (Tree::findByName($tree_name)) {
            FlashMessages::addMessage(I18N::translate('The family tree “%s” already exists.', e($tree_name)), 'danger');

            $url = route('admin-trees');
        } else {
            $tree = Tree::create($tree_name, $tree_title);
            FlashMessages::addMessage(I18N::translate('The family tree “%s” has been created.', e($tree->name())), 'success');

            $url = route('admin-trees', ['ged' => $tree->name()]);
        }

        return redirect($url);
    }
371685
public function onRequest( RequestInterface $request ) {
        $schema = $this->getEndpoint()->getSchema();

        return $request->withHeader( 'X-Schema-Version', $schema );
    }
1261969
private function getIp(ServerRequestInterface $request)
    {
        if ($this->remote && ($remoteIp = $this->getRemoteIp()) !== null) {
            // Found IP address via remote service.
            return $remoteIp;
        }

        $localIp = $this->getLocalIp($request);

        if ($this->proxyIps && !\in_array($localIp, $this->proxyIps, true)) {
            // Local IP address does not point at a known proxy, do not attempt
            // to read proxied IP address.
            return $localIp;
        }

        $proxiedIp = $this->getProxiedIp($request);

        if ($proxiedIp !== null) {
            // Found IP address via proxy-defined headers.
            return $proxiedIp;
        }

        return $localIp;
    }
40780
public function setup(ServerRequestInterface $request): ResponseInterface
    {
        // Mini "bootstrap"
        define('WT_DATA_DIR', 'data/');
        app()->instance(ServerRequestInterface::class, $request);
        app()->instance('cache.array', new Repository(new ArrayStore()));

        $data = $this->userData($request);

        $step = (int) ($request->getParsedBody()['step'] ?? '1');
        $lang = $request->getParsedBody()['lang'] ?? $data['lang'];

        $data['lang']         = I18N::init($lang, null, true);
        $data['cpu_limit']    = $this->maxExecutionTime();
        $data['locales']      = $this->setupLocales();
        $data['memory_limit'] = $this->memoryLimit();

        // Only show database errors after the user has chosen a driver.
        if ($step >= 4) {
            $data['errors']   = $this->server_check_service->serverErrors($data['dbtype']);
            $data['warnings'] = $this->server_check_service->serverWarnings($data['dbtype']);
        } else {
            $data['errors']   = $this->server_check_service->serverErrors();
            $data['warnings'] = $this->server_check_service->serverWarnings();
        }

        if (!$this->checkFolderIsWritable(WT_DATA_DIR)) {
            $data['errors']->push(
                '<code>' . e(realpath(WT_DATA_DIR)) . '</code><br>' .
                I18N::translate('Oops! webtrees was unable to create files in this folder.') . ' ' .
                I18N::translate('This usually means that you need to change the folder permissions to 777.')
            );
        }

        define('WT_LOCALE', $data['lang']);

        switch ($step) {
            default:
            case 1:
                return $this->step1Language($data);
            case 2:
                return $this->step2CheckServer($data);
            case 3:
                return $this->step3DatabaseType($data);
            case 4:
                return $this->step4DatabaseConnection($data);
            case 5:
                return $this->step5Administrator($data);
            case 6:
                return $this->step6Install($data);
        }
    }
398936
private function generatePath(RequestInterface $request)
    {
        $path = array();

        if (null !== $request->getIndex()) {
            $path[] = $request->getIndex();
        }

        if (null !== $request->getType()) {
            $path[] = $request->getType();
        }

        if (null !== $request->getAction()) {
            $path[] = $request->getAction();
        }

        return implode(self::PATH_DIVIDER, $path);
    }
279789
public function request(RequestInterface $request, array $options = []): HttpResultInterface
    {
        $options = $this->handleOptions(array_merge($this->defaultOptions, $options));

        $url = (string)$request->getUri();
        $profileKey = 'HttpClient.' . $url;

        App::profileStart($profileKey);

        list($host, $port) = $this->ipResolve($request, $options);

        $ssl = $request->getUri()->getScheme() === 'https';

        $client = new CoHttpClient($host, $port, $ssl);
        $this->applyOptions($client, $request, $options);
        $this->applyMethod($client, $request, $options);

        $path = $request->getUri()->getPath();
        $query = $request->getUri()->getQuery();
        if ($path === '') $path = '/';
        if ($query !== '') $path .= '?' . $query;

        $client->setDefer();
        $client->execute($path);

        App::profileEnd($profileKey);

        if (null !== $client->errCode && $client->errCode !== 0) {
            App::error(sprintf('HttpClient Request ERROR #%s url=%s', $client->errCode, $url));
            throw new RuntimeException(\socket_strerror($client->errCode), $client->errCode);
        }

        $result = new HttpCoResult(null, $client, $profileKey);
        return $result;
    }
245371
public function match(RequestInterface $request)
    {
        foreach ($this->routes as $name => $route) {
            if (!$route->match($request)) {
                continue;
            }

            foreach ($route->arguments() as $key => $value) {
                $request->query()
                    ->set($key, $value);
            }

            $request->language($request->query()->get('language'));
            $request->format($request->query()->get('format'));

            $request->route($name);

            $this->defaults = [
                'host' => $request->baseName(),
                'route' => $name,
                'language' => $request->language(),
                'format' => $request->format()
            ];

            return $route->controller();
        }

        throw new RouterException('Route for "' . $request->path() . '" not found!');
    }
665117
public function fromRequest(HttpRequestInterface $request)
    {
        return $this->createRequest(
            $request->getMethod(),
            $request->getUri(),
            $request->getHeaders(),
            JsonRpc\json_decode((string) $request->getBody(), true) ?: []
        );
    }