Determine timezone for this api request.
It takes the value from the Accept-Timezone header.
If that is not present it returns the default value: UTC.

@param Request $request HTTP request

@return string
482489
protected function determineRequestTimezone(Request $request)
    {
        $requestTimezone = 'UTC';

        if (str_is('api.*', $request->getHost()) && $request->hasHeader('Accept-Timezone')) {
            $requestTimezone = $request->header('Accept-Timezone');
        }

        return $requestTimezone;
    }
517300
private function getViewLocale(Request $request)
    {
        $viewLocale = $request->query->get('lang', null);
        if (null === $viewLocale) {
            // fallback for old parameter
            $viewLocale = $request->query->get('locale', null);
        }

        return $viewLocale;
    }
706329
public static function setFromURL(Request $request)
    {
        if(!\Request::route('lang')) {
            // language may be present in url without {param} defined
            $detectLanguageFromRequest = \App\Models\Language::detectLanguageFromRequest($request);
            if ($detectLanguageFromRequest) {
                $request->route()->setParameter('lang', $detectLanguageFromRequest);
                return $detectLanguageFromRequest;
            }
        }
        return null;
    }
201558
public function setRequest(Request $request)
    {
        $context = (new RequestContext())->fromRequest($request);

        $this->cachedRoot = null;
        $this->cachedSchema = null;
        return $this->setContext($context);
    }
908228
private function client_timezone()
    {
        // @TODO: remove this legacy timezone handling in the future
        $props = $this->fix_legacy_props(array('timezone' => $_SESSION['timezone']));

        if (!empty($props['timezone'])) {
            try {
                $tz = new DateTimeZone($props['timezone']);
                return $tz->getName();
            }
            catch (Exception $e) { /* gracefully ignore */ }
        }

        // fallback to server's timezone
        return date_default_timezone_get();
    }
610550
public function saveTemporaryPref(Request $request)
    {
        if (!$request->isXmlHttpRequest()) {
            $this->app->abort(400);
        }

        $prop = $request->request->get('prop');
        $value = $request->request->get('value');
        $success = false;
        $msg = $this->app->trans('Error while saving preference');

        if (!is_null($prop) && !is_null($value)) {
            $this->getSession()->set('phraseanet.' . $prop, $value);
            $success = true;
            $msg = $this->app->trans('Preference saved !');
        }

        return new JsonResponse(['success' => $success, 'message' => $msg]);
    }
577781
public function resolveFromDomain(Request $request)
    {
        $host = $request->getHost();
        $httpHost = $request->getHttpHost();

        if (array_key_exists($host, $this->localeDomainConfig)) {
            return $this->localeDomainConfig[$host];
        } elseif (array_key_exists($httpHost, $this->localeDomainConfig)) {
            return $this->localeDomainConfig[$httpHost];
        }

        error_log(sprintf(
            'Host "%s" is not defined in your locale_pattern_table in app/config/victoire_core.yml (%s available), using default locale (%s) instead',
            $httpHost,
            implode(',', $this->localeDomainConfig),
            $this->defaultLocale
        ));

        return $request->getLocale();
    }
442907
public function readClientLocalesFromRequest(Request $request) {
        $locales = [];

        foreach($request->getLanguages() as $client) {
            try {
                $locale = new Locale($client);
                $locales[] = $locale;
            } catch(\Exception $e) {
                trigger_error($e->getMessage(), E_USER_NOTICE);
            }
        }

        $this->setClientLocales($locales);
    }
428401
protected function prepareRequest(Request $request)
    {
        $curl = curl_init();
        
        // TODO Timeout and Follow Redirect settings
        $options = array(
            CURLOPT_RETURNTRANSFER    => true,
            CURLOPT_HEADER            => true,
            CURLOPT_CONNECTTIMEOUT_MS => 1000,
            CURLOPT_TIMEOUT_MS        => 3000,
            CURLOPT_CUSTOMREQUEST     => $request->getMethod(),
            CURLOPT_URL               => $request->getUri(),
            CURLOPT_HTTPHEADER        => $request->getHeaders(),
            CURLOPT_HTTPGET           => false,
            CURLOPT_NOBODY            => false,
            CURLOPT_POST              => false,
            CURLOPT_POSTFIELDS        => null,           
        );

        switch ($request->getMethod()) {
            case Request::METHOD_HEAD:
                $options[CURLOPT_NOBODY] = true;
                
                $query = http_build_query($request->getParameters());
                if (!empty($query)) {
                    $options[CURLOPT_URL] = $request->getUri().'?'.$query;
                }
                break;

            case Request::METHOD_GET:
                $options[CURLOPT_HTTPGET] = true;
                
                $query = http_build_query($request->getParameters());
                if (!empty($query)) {
                    $options[CURLOPT_URL] = $request->getUri().'?'.$query;
                }
                break;

            case Request::METHOD_POST:
            case Request::METHOD_PUT:
                $options[CURLOPT_POST] = true;
                $options[CURLOPT_POSTFIELDS] = http_build_query($request->getParameters());
                break;
        }
        
        curl_setopt_array($curl, $options);
        
        return $curl;
    }
122971
public function settingsAction(Request $request)
    {
        $response = $this->getCacheTimeKeeper()->getResponse();
        // response was not modified for this request
        if ($response->isNotModified($request)) {
            return $response;
        }

        $entity = (new GeneralEntity())
            ->setTaskScheduler($this->container->getParameter('task_scheduler.enabled'))
            ->setDefaultSearch($this->container->getParameter('anime_db.catalog.default_search'))
            ->setLocale($request->getLocale());

        /* @var $chain ChainSearch */
        $chain = $this->get('anime_db.plugin.search_fill');
        /* @var $form Form */
        $form = $this->createForm(new GeneralForm($chain), $entity)
            ->handleRequest($request);

        if ($form->isValid()) {
            // update params
            $this->get('anime_db.manipulator.parameters')
                ->set('task_scheduler.enabled', $entity->getTaskScheduler());
            $this->get('anime_db.manipulator.parameters')
                ->set('anime_db.catalog.default_search', $entity->getDefaultSearch());
            $this->get('anime_db.manipulator.parameters')
                ->set('locale', $entity->getLocale());
            $this->get('anime_db.app.listener.request')->setLocale($request, $entity->getLocale());
            $this->get('anime_db.cache_clearer')->clear();

            return $this->redirect($this->generateUrl('home_settings'));
        }

        return $this->render('AnimeDbCatalogBundle:Home:settings.html.twig', [
            'form' => $form->createView(),
        ], $response);
    }
1129999
public function currentweather(Request $request)
    {
        $lowm = new LaravelOWM();
        $tz = new \DateTimeZone(config('app.timezone'));

        $city = $request->get('city');
        $coordinates = $request->get('coord');
        $lang = $request->get('lang', 'en');
        $units = $request->get('units', 'metric');

        if ($city === null && $coordinates == null) {
            abort('400','City or coordinates cannot be undefined.');
        }

        $query = ($city) ?: $coordinates;

        try {
            $current_weather = $lowm->getCurrentWeather($query, $lang, $units, true);
        } catch(\Exception $e) {
            return response()->json(['status' => 'error', 'message' => $e->getMessage(), 'code' => $e->getCode()]);
        }

        $data = [
            'city' => [
                'id' => $current_weather->city->id,
                'name' => $current_weather->city->name,
                'lat' => $current_weather->city->lat,
                'lon' => $current_weather->city->lon,
                'country' => $current_weather->city->country,
                'population' => $current_weather->city->population
            ],
            'sun' => [
                'rise' => [
                    'date' => $current_weather->sun->rise->setTimezone($tz)->format('Y-m-d H:i:s'),
                    'timestamp' => $current_weather->sun->rise->setTimezone($tz)->getTimestamp()
                ],
                'set' => [
                    'date' => $current_weather->sun->set->setTimezone($tz)->format('Y-m-d H:i:s'),
                    'timestamp' => $current_weather->sun->set->setTimezone($tz)->getTimestamp()
                ]
            ],
            'lastUpdate' => [
                'date' => $current_weather->lastUpdate->setTimezone($tz)->format('Y-m-d H:i:s'),
                'timestamp' => $current_weather->lastUpdate->setTimezone($tz)->getTimestamp()
            ]
        ];

        $data = array_merge($data, $this->parseData($current_weather));

        return response()->json(['status' => 'ok', 'data' => $data]);
    }
677503
public function forecast(Request $request)
    {
        $lowm = new LaravelOWM();
        $tz = new \DateTimeZone(config('app.timezone'));

        $city = $request->get('city');
        $coordinates = $request->get('coord');
        $lang = $request->get('lang', 'en');
        $units = $request->get('units', 'metric');
        $days = $request->get('days', 5);

        if ($city === null && $coordinates == null) {
            abort('400','City or coordinates cannot be undefined.');
        }

        $query = ($city) ?: $coordinates;

        try {
            $forecast = $lowm->getWeatherForecast($query, $lang, $units, $days, true);
        } catch(\Exception $e){
            return response()->json(['status' => 'error', 'message' => $e->getMessage(), 'code' => $e->getCode()]);
        }

        $data = [
            'city' => [
                'id' => $forecast->city->id,
                'name' => $forecast->city->name,
                'lat' => $forecast->city->lat,
                'lon' => $forecast->city->lon,
                'country' => $forecast->city->country,
                'population' => $forecast->city->population
            ],
            'sun' => [
                'rise' => [
                    'date' => $forecast->sun->rise->setTimezone($tz)->format('Y-m-d H:i:s'),
                    'timestamp' => $forecast->sun->rise->setTimezone($tz)->getTimestamp()
                ],
                'set' => [
                    'date' => $forecast->sun->set->setTimezone($tz)->format('Y-m-d H:i:s'),
                    'timestamp' => $forecast->sun->set->setTimezone($tz)->getTimestamp()
                ]
            ],
            'lastUpdate' => [
                'date' => $forecast->lastUpdate->setTimezone($tz)->format('Y-m-d H:i:s'),
                'timestamp' => $forecast->lastUpdate->setTimezone($tz)->getTimestamp()
            ]
        ];

        foreach ($forecast as $obj) {

            $day = $obj->time->day->setTimezone($tz);
            $from = $obj->time->from->setTimezone($tz);
            $to = $obj->time->to->setTimezone($tz);

            $temp = [

                'time' => [
                    'from' => [
                        'date' => $from->format('Y-m-d H:i:s'),
                        'timestamp' => $from->getTimestamp()
                    ],
                    'to' => [
                        'date' => $to->format('Y-m-d H:i:s'),
                        'timestamp' => $to->getTimestamp()
                    ],
                    'day' => [
                        'date' => $day->format('Y-m-d H:i:s'),
                        'timestamp' => $day->getTimestamp()
                    ],
                ],

                'lastUpdate' => [
                    'date' => $obj->lastUpdate->setTimezone($tz)->format('Y-m-d H:i:s'),
                    'timestamp' => $obj->lastUpdate->setTimezone($tz)->getTimestamp()
                ]
            ];

            if (isset($last_day)) {

                if($day->format('Y-m-d H:i:s') == $last_day){

                    // ISO-8601 numeric representation of the day of the week
                    // 1 (for Monday) through 7 (for Sunday)
                    $day_key = $day->format('N');

                    // The OWM API returns 3 hour forecast data, it means for each day you requested you'll
                    // get weather data each 3 hours in this order:
                    // 06:00 - 09:00, 09:00 - 12:00, 12:00 - 15:00, 15:00 - 18:00, 18:00 - 21:00, 21:00 - 00:00.
                    // So to maintain a well-ordered info I built a key depending on the hours range
                    // (ie: ['06-09'] => [ ... ]).
                    $time_key = $from->format('H').'-'.$to->format('H');

                    $data['days'][$day_key][$time_key] = array_merge($temp, $this->parseData($obj));
                }
            }

            $last_day = $day->format('Y-m-d H:i:s');
        }

        return response()->json(['status' => 'ok', 'data' => $data]);
    }
1354184
public function getTimeZone() {
        $tzs = $this->user->getPropertyValues(GenerisRdf::PROPERTY_USER_TIMEZONE);
        $tz = empty($tzs) ? '' : (string)current($tzs);
        return empty($tz) ? TIME_ZONE : $tz;
    }
158415
private function determineLifeTime(Request $request)
    {
        if ($lifetime = $request->query->getInt('ttl')) {
            return $this->revertToNullOnMinusOne($lifetime);
        }

        try {
            $inputData = new JsonArray($request->getContent());
            if ($inputData->has('ttl')) {
                return $this->revertToNullOnMinusOne(intval($inputData->get('ttl')));
            }
        } catch (\Exception $e) {
            // Swallow exception, we need to return a defined result.
        }

        return 3600;
    }
634318
public function getLocale(HttpRequest $request)
    {
        if ($this->locale) {
            return $this->locale;
        }

        // get locale from language list
        $constraint = new Locale();
        foreach ($request->getLanguages() as $language) {
            if (!$this->validator->validate($language, $constraint)->has(0)) {
                return $language;
            }
        }

        // get default locale
        return $request->getLocale();
    }
583957
protected function determineTargetUrl(Request $request)
    {
        if ($this->options['always_use_default_target_path']) {
            return $this->options['default_target_path'];
        }

        if ($targetUrl = $request->get($this->options['target_path_parameter'], null, true)) {
            return $targetUrl;
        }

        if (null !== $this->providerKey && $targetUrl = $request->getSession()->get('_security.'.$this->providerKey.'.target_path')) {
            $request->getSession()->remove('_security.'.$this->providerKey.'.target_path');

            return $targetUrl;
        }

        if ($this->options['use_referer'] && ($targetUrl = $request->headers->get('Referer')) && $targetUrl !== $this->httpUtils->generateUri($request, $this->options['login_path'])) {
            return $targetUrl;
        }
        return $this->options['default_target_path'];
    }
1314712
protected function normalizeRequestUri(Request $request)
    {
        $query = $request->server->get('QUERY_STRING');

        $uri = '/'.trim(str_replace('?'.$query, '', $request->server->get('REQUEST_URI')), '/').($query ? '?'.$query : '');

        $request->server->set('REQUEST_URI', $uri);
    }