Template method to apply matching system to user agent

@param \Wurfl\Request\GenericRequest $request

@return string Device ID
511807
final public function applyMatch(GenericRequest $request)
    {
        $className                                 = get_class($this);
        $request->getMatchInfo()->matcher          = $className;
        $startTime                                 = microtime(true);
        $request->getMatchInfo()->cleanedUserAgent = $request->getUserAgentNormalized();

        $userAgent                                    = $this->normalizeUserAgent($request->getUserAgentNormalized());
        $request->getMatchInfo()->normalizedUserAgent = $userAgent;
        $this->logger->debug('START: Matching For ' . $userAgent);

        // Get The data associated with this current handler
        $this->userAgentsWithDeviceID = $this->getUserAgentsWithDeviceId();
        $this->userAgents             = $this->getUserAgentsForBucket();

        $matches = array(
            'exact'             => array(
                'history'  => '(exact),',
                'function' => 'applyExactMatch',
                'debug'    => 'Applying Exact Match',
            ),
            'conclusive'        => array(
                'history'  => '(conclusive),',
                'function' => 'applyConclusiveMatch',
                'debug'    => 'Applying Conclusive Match',
            ),
            'recovery'          => array(
                'history'  => '(recovery),',
                'function' => 'applyRecoveryMatch',
                'debug'    => 'Applying Recovery Match',
            ),
            'recovery-catchall' => array(
                'history'  => '(recovery-catchall),',
                'function' => 'applyRecoveryCatchAllMatch',
                'debug'    => 'Applying Catch All Recovery Match',
            ),
        );

        $deviceID = WurflConstants::NO_MATCH;

        foreach ($matches as $matchType => $matchProps) {
            $matchProps = (object) $matchProps;

            $request->getMatchInfo()->matcherHistory .= $className . $matchProps->history;
            $request->getMatchInfo()->matchType   = $matchType;
            $request->setUserAgentsWithDeviceID($this->userAgentsWithDeviceID);

            $this->logger->debug($this->prefix . ' :' . $matchProps->debug . ' for ua: ' . $userAgent);

            $function = $matchProps->function;
            $deviceID = $this->$function($userAgent);

            if (!$this->isBlankOrGeneric($deviceID)) {
                break;
            }
        }

        // All attempts to match have failed
        if ($this->isBlankOrGeneric($deviceID)) {
            $request->getMatchInfo()->matchType = 'none';

            if ($request->getUserAgentProfile()) {
                $deviceID = WurflConstants::GENERIC_MOBILE;
            } else {
                $deviceID = WurflConstants::GENERIC;
            }
        }

        $this->logger->debug('END: Matching For ' . $userAgent);
        $request->getMatchInfo()->lookupTime = microtime(true) - $startTime;

        return $deviceID;
    }
1199000
public function request(string $request): string
    {
        $request  = $this->preRequest($request);
        return $this->send($request);
    }
1164269
protected function getRequestIp($request)
    {
        if ($request->server('HTTP_CF_CONNECTING_IP')) {
            // cloudflare
            return $request->server('HTTP_CF_CONNECTING_IP');
        }

        if ($request->server('X_FORWARDED_FOR')) {
            // forwarded proxy
            return $request->server('X_FORWARDED_FOR');
        }

        if ($request->server('REMOTE_ADDR')) {
            // remote header
            return $request->server('REMOTE_ADDR');
        }
    }
1343295
protected function getAcceptType(ServerRequestInterface $request)
    {
        $accept = $request->getHeaderLine('Accept');
        if (
            strpos($accept, 'text/html') !== false ||
            strpos($accept, 'application/xhtml+xml') !== false
        ) {
            return 'html';
        }
        if (
            strpos($accept, 'application/json') !== false ||
            strpos($accept, 'text/json') !== false ||
            strpos($accept, 'application/x-json') !== false
        ) {
            return 'json';
        }
        return 'text';
    }
756423
protected function _basic($request) {
		$users = $this->_config['users'];
		$username = $request->env('PHP_AUTH_USER');
		$auth = $this->_classes['auth'];
		$basic = $auth::encode($username, $request->env('PHP_AUTH_PW'));
		$encoded = ['response' => null];

		if (isset($users[$username])) {
			$encoded = $auth::encode($username, $users[$username]);
		}
		if ($basic['response'] !== $encoded['response']) {
			$this->_writeHeader("WWW-Authenticate: Basic realm=\"{$this->_config['realm']}\"");
			return;
		}
		return compact('username', 'password');
	}
1235516
public function getDeviceForUserAgent($userAgent = '')
    {
        if (!is_string($userAgent)) {
            $userAgent = '';
        }

        $requestFactory = new Request\GenericRequestFactory();

        $request = $requestFactory->createRequestForUserAgent($userAgent);
        $device  = $this->getDeviceForRequest($request);

        return $device;
    }
547839
public function cgetAction(Request $request)
    {
        try {
            /** @var ListRestHelperInterface $listRestHelper */
            $listRestHelper = $this->get('sulu_core.list_rest_helper');
            $securityChecker = $this->get('sulu_security.security_checker');

            $flat = $this->getBooleanRequestParameter($request, 'flat', false);
            $depth = $request->get('depth', 0);
            $parentId = $request->get('parentId', null);
            $limit = $request->get('limit', null);
            $offset = $this->getOffset($request, $limit);
            $search = $listRestHelper->getSearchPattern();
            $sortBy = $request->get('sortBy');
            $sortOrder = $request->get('sortOrder', 'ASC');
            $includeRoot = $this->getBooleanRequestParameter($request, 'includeRoot', false, false);
            $collectionManager = $this->getCollectionManager();

            if ('root' === $parentId) {
                $includeRoot = false;
                $parentId = null;
            }

            if ($flat) {
                $collections = $collectionManager->get(
                    $this->getRequestParameter($request, 'locale', true),
                    [
                        'depth' => $depth,
                        'parent' => $parentId,
                    ],
                    $limit,
                    $offset,
                    null !== $sortBy ? [$sortBy => $sortOrder] : []
                );
            } else {
                $collections = $collectionManager->getTree(
                    $this->getRequestParameter($request, 'locale', true),
                    $offset,
                    $limit,
                    $search,
                    $depth,
                    null !== $sortBy ? [$sortBy => $sortOrder] : [],
                    $securityChecker->hasPermission('sulu.media.system_collections', 'view')
                );
            }

            if ($includeRoot && !$parentId) {
                $collections = [
                    new RootCollection(
                        $this->get('translator')->trans('sulu_media.all_collections', [], 'admin'),
                        $collections
                    ),
                ];
            }

            $all = $collectionManager->getCount();

            $list = new ListRepresentation(
                $collections,
                self::$entityKey,
                'get_collections',
                $request->query->all(),
                $listRestHelper->getPage(),
                $listRestHelper->getLimit(),
                $all
            );

            $view = $this->view($list, 200);
        } catch (CollectionNotFoundException $cnf) {
            $view = $this->view($cnf->toArray(), 404);
        } catch (MediaException $me) {
            $view = $this->view($me->toArray(), 400);
        }

        return $this->handleView($view);
    }
1225077
public function push($request)
    {
        if (empty($this->devices) && empty($this->users) && empty($this->channels)) {
            throw new \Exception('You must specify something to push to.');
        }

        $responses = [];

        $destinations = [
            'devices'  => 'device_iden',
            'users'    => 'email',
            'channels' => 'channel_tag',
        ];

        foreach ($destinations as $destination => $key) {
            foreach ($this->{$destination} as $dest) {
                $responses[] = $this->pushRequest($request, [$key => $dest]);
            }
        }

        $this->devices  = [];
        $this->users    = [];
        $this->channels = [];

        return $responses;
    }
974827
public function postTypeFinder($request)
    {
        if (key_exists('type', $request->query)) {
            return $request->query['type'];
        }
        if (key_exists(0, $request->params['pass'])) {
            return $request->params['pass'][0];
        }
        return '';
    }
834019
public function index(string $request) : string
    {
        $jsonRpcCall = null;
        try {
            $jsonRpcCall = $this->getJsonRpcCall($request);

            $jsonRpcCallResponse = $this->getJsonRpcCallResponse($jsonRpcCall);

            return $this->getResponseString($jsonRpcCallResponse, $jsonRpcCall);
        } catch (\Exception $exception) {
            // Try to create a valid json-rpc error
            $jsonRpcCallResponse = (new JsonRpcCallResponse())->addResponse(
                $this->exceptionHandler->getJsonRpcResponseFromException($exception)
            );

            return $this->getResponseString($jsonRpcCallResponse, $jsonRpcCall);
        }
    }
1073886
public function getCountryAndPostalCode(Request $request): DeviceAddressInformation
    {
        if (!isset($request->context->system->device->deviceId, $request->context->system->apiAccessToken, $request->context->system->apiEndpoint)) {
            throw new MissingRequestDataException();
        }

        $deviceId    = $request->context->system->device->deviceId;
        $token       = $request->context->system->apiAccessToken;
        $endpoint    = $request->context->system->apiEndpoint;

        $url = sprintf('%s/v1/devices/%s/settings/address/countryAndPostalCode', $endpoint, $deviceId);

        return $this->apiCall($url, $token);
    }
510926
protected function get($request)
    {
        $response = $this->client->get($this->prefix.$this->getLocale().$request)->send();
        if ($response->isError()) {
            throw new \RuntimeException(
                'Failed execute request "'.$request.'" to the server "'.$this->client->getBaseUrl().'"'
            );
        }
        return json_decode($response->getBody(true), true);
    }
1055119
public function fetchAccessToken($request)
    {
        $this->getVersion($request);

        $consumer = $this->getConsumer($request);

        // requires authorized request token
        $token = $this->getToken($request, $consumer, "request");

        $this->checkSignature($request, $consumer, $token);

        $newToken = $this->dataStore->newAccessToken($token, $consumer);

        return $newToken;
    }
467084
public static function getUserAgentProfile($request)
    {
        if (isset($request["HTTP_X_WAP_PROFILE"])) {
            return $request["HTTP_X_WAP_PROFILE"];
        }
        if (isset($request["HTTP_PROFILE"])) {
            return $request["HTTP_PROFILE"];
        }
        if (isset($request["Opt"])) {
            $opt = $request["Opt"];
            $regex = "/ns=\\d+/";
            $matches = array();
            $namespaceProfile = null;
            if (preg_match($regex, $opt, $matches)) {
                $namespaceProfile = substr($matches[0], 2) . "-Profile";
            }
            if ($namespaceProfile !== null && isset($request[$namespaceProfile])) {
                return $request[$namespaceProfile];
            }
        }

        return null;
    }
1149647
public static function initAuth($request) { 
        if($request->getRequiredParameter())
            if(!is_numeric($request->getRequiredParameter()))
                killer('400');
        
        if($request->getRelationalParameter())
            if(!is_numeric($request->getRelationalParameter()))
                killer('400');
        
        if($request->isLogin()) 
            return ServiceAuth::validateAuth($request); 
        if($request->isResetPassword())
            return ServiceAuth::resetPassword($request);
        ServiceAuth::Authenticate($request); 
        return null;
    }
218354
public function getDeviceForRequest(WURFL_Request_GenericRequest $request)
    {
        if (!isset($request)) {
            throw new Exception("The request parameter must be set.");
        }
        WURFL_Handlers_Utils::reset();
        return $this->_wurflService->getDeviceForRequest($request);
    }
819608
public static function getNameId($request, $key = null)
    {
        $nameId = self::getNameIdData($request, $key);
        return $nameId['Value'];
    }