setUserAgent example

try {
            $params = $request->request->all();
            $params['key'] = html_entity_decode($params['key']);

            $ip = $this->ipAnonymizer->anonymize($request->getClientIp());

            $logModel = new Log();
            $logModel->fromArray($params);
            $logModel->setDate(new DateTime('now'));
            $logModel->setIpAddress($ip);
            $logModel->setUserAgent($request->server->get('HTTP_USER_AGENT', 'Unknown'));

            $this->em->persist($logModel);
            $this->em->flush();

            $data = $this->em->toArray($logModel);

            $this->View()->assign(['success' => true, 'data' => $data]);
        } catch (Exception $e) {
            $this->View()->assign(['success' => false, 'errorMsg' => $e->getMessage()]);
        }
    }
}
// And then loop through the remaining options         $config = array();
        foreach ($options as $key => $value) {
            switch (strtolower($key)) {
                case 'browser_type':
                    $this->setBrowserType($value);
                    break;
                case 'http_accept':
                    $this->setHttpAccept($value);
                    break;
                case 'user_agent':
                    $this->setUserAgent($value);
                    break;
                default:
                    // Cache remaining options for $_config                     $config[$key] = $value;
                    break;
            }
        }
        $this->setConfig($config);

        return $this;
    }

    

    public function __construct($userAgent = null, array $server = array(), array $config = array())
    {
        if (is_array($userAgent)) {
            // Restoring from serialized array             $this->_restoreFromArray($userAgent);
        } else {
            // Constructing new object             $this->setUserAgent($userAgent);
            $this->_server    = $server;
            $this->_config    = $config;
            $this->_getDefaultFeatures();
            $this->_defineFeatures();
        }
    }

    /** * Serialize object * * @return string */
Home | Imprint | This part of the site doesn't use cookies.