<commit_before><?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;

class Dase_Request 
{
    public static $types = array(
        'atom' =>'application/atom+xml',
        'cats' =>'application/atomcat+xml',
        'css' =>'text/css',
        'csv' =>'text/csv',
        'default' =>'text/html',
        'doc' =>'application/msword',
        'docx' =>'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
        'gif' =>'image/gif',
        'html' =>'text/html',
        'jpg' =>'image/jpeg',
        'json' =>'application/json',
        'kml' =>'application/vnd.google-earth.kml+xml',
        'mov' =>'video/quicktime',
        'mp3' =>'audio/mpeg',
        'mp4' =>'video/mp4',
        'oga' => 'audio/ogg',
        'ogv' => 'video/ogg',
        'png' =>'image/png',
        'pdf' =>'application/pdf',
        'txt' =>'text/plain',
        'uris' =>'text/uri-list',
        'uri' =>'text/uri-list',
        'wav' =>'audio/wav',
        'xhtml' =>'application/xhtml+xml',
        'xml' =>'application/xml',
    );

    private $auth_config;
    private $cache;
    private $config;
    private $db;
    private $default_handler;
    private $eid_cookie;
    private $eid_is_serviceuser;
    private $eid_is_superuser;
    private $null_user;
    private $params;
    private $serviceusers = array();
    private $sf_request;
    private $sf_response;
    private $superusers = array();

    public $app_root;
    public $ext;
    public $format;
    public $handler;
    public $handler_path;
    public $log;
    public $method;
    public $mime;
    public $module;
    public $path;
    public $request_uri;
    public $template;
    public $user;
    public $user_is_null_user; //needed to allow Twig to NOT force login

    public function __construct()
    {
        $this->sf_request = Request::createFromGlobals();
        $this->sf_response = new Response();

        list ($this->path,$this->ext) = $this->getPathAndExtension();

        $this->request_uri = $this->sf_request->getRequestUri();
        $this->host = $this->sf_request->getHttpHost();
        $this->format = $this->sf_request->getRequestFormat($this->ext);
        $this->query_string = $this->sf_request->getQueryString();
        $this->method = strtolower($this->sf_request->getMethod());
        $this->mime = $this->sf_request->getMimeType($this->format);
        $this->htuser = $this->sf_request->server->get('PHP_AUTH_USER');
        $this->htpass = $this->sf_request->server->get('PHP_AUTH_PW');
        $this->handler = $this->getHandler($this->path);
        $this->handler_path = $this->handler;
        $this->app_root =
            $this->sf_request->getScheme().'://'.$this->sf_request->getHttpHost().$this->sf_request->getBaseUrl();
        $this->module = $this->getModule();
        $this->module_root = $this->app_root.'/modules/'.$this->module;

        $this->log = Dase_Logger::instance(LOG_DIR,LOG_LEVEL);
    }

    public function getResponse()
    {
        return $this->sf_response;
    }

    public function getContentType()
    {
        $ct = $this->sf_request->headers->get('content_type');
        $parts = explode(';',$ct);
        $content_type = array_shift($parts);
        return $content_type;
    }

    public function init($db,$config,$template)
    {
        $this->template = $template;
        $this->db = $db;
        $this->config = $config;
        $this->checkForceHttps($config);
        $this->initDefaultHandler();
        $this->initUser();
        $this->initCache();
        $this->initCookie();
        $this->initAuth();
        $this->initPlugin();
        $this->logRequest();
    }

    //todo: needs work -- set by handler route var matches
    public function setParams($params) 
    {
        $this->params = $params; 
    }

    public function getAppSettings()
    {
        return $this->config->getAppSettings();
    }

    public function has($key)
    {
        if ($this->sf_request->request->has($key)) {
            return true;
        }
        if ($this->sf_request->query->has($key)) {
            return true;
        }
        if (isset($this->params[$key])) {
            return true;
        }
        return false;
    }

    public function hasFile($key)
    {
        if ($this->sf_request->files->has($key)) {
            return true;
        }
        return false;
    }

    public function getFile($key)
    {
        if ($this->sf_request->files->has($key)) {
            return $this->sf_request->files->get($key);
        }
    }

    //todo: work on returning arrays when appropriate
    public function get($key)
    {
        if ($this->sf_request->request->has($key)) {
            return trim($this->sf_request->request->filter($key));
        }
        if ($this->sf_request->query->has($key)) {
            return trim($this->sf_request->query->filter($key));
        }
        if (isset($this->params[$key])) {
            return trim($this->params[$key]);
        }
    }

    public function getBody()
    {
        return trim($this->sf_request->getContent());
    }

    public function __call( $method,$args ) 
    {
        return $this->sf_request->$method($args);
    }

    public function assign($key,$val)
    {
        $this->template->assign($key,$val);
    }
<commit_msg>added keys function to request<commit_after><?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;

class Dase_Request 
{
    public static $types = array(
        'atom' =>'application/atom+xml',
        'cats' =>'application/atomcat+xml',
        'css' =>'text/css',
        'csv' =>'text/csv',
        'default' =>'text/html',
        'doc' =>'application/msword',
        'docx' =>'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
        'gif' =>'image/gif',
        'html' =>'text/html',
        'jpg' =>'image/jpeg',
        'json' =>'application/json',
        'kml' =>'application/vnd.google-earth.kml+xml',
        'mov' =>'video/quicktime',
        'mp3' =>'audio/mpeg',
        'mp4' =>'video/mp4',
        'oga' => 'audio/ogg',
        'ogv' => 'video/ogg',
        'png' =>'image/png',
        'pdf' =>'application/pdf',
        'txt' =>'text/plain',
        'uris' =>'text/uri-list',
        'uri' =>'text/uri-list',
        'wav' =>'audio/wav',
        'xhtml' =>'application/xhtml+xml',
        'xml' =>'application/xml',
    );

    private $auth_config;
    private $cache;
    private $config;
    private $db;
    private $default_handler;
    private $eid_cookie;
    private $eid_is_serviceuser;
    private $eid_is_superuser;
    private $null_user;
    private $params;
    private $serviceusers = array();
    private $sf_request;
    private $sf_response;
    private $superusers = array();

    public $app_root;
    public $ext;
    public $format;
    public $handler;
    public $handler_path;
    public $log;
    public $method;
    public $mime;
    public $module;
    public $path;
    public $request_uri;
    public $template;
    public $user;
    public $user_is_null_user; //needed to allow Twig to NOT force login

    public function __construct()
    {
        $this->sf_request = Request::createFromGlobals();
        $this->sf_response = new Response();

        list ($this->path,$this->ext) = $this->getPathAndExtension();

        $this->request_uri = $this->sf_request->getRequestUri();
        $this->host = $this->sf_request->getHttpHost();
        $this->format = $this->sf_request->getRequestFormat($this->ext);
        $this->query_string = $this->sf_request->getQueryString();
        $this->method = strtolower($this->sf_request->getMethod());
        $this->mime = $this->sf_request->getMimeType($this->format);
        $this->htuser = $this->sf_request->server->get('PHP_AUTH_USER');
        $this->htpass = $this->sf_request->server->get('PHP_AUTH_PW');
        $this->handler = $this->getHandler($this->path);
        $this->handler_path = $this->handler;
        $this->app_root =
            $this->sf_request->getScheme().'://'.$this->sf_request->getHttpHost().$this->sf_request->getBaseUrl();
        $this->module = $this->getModule();
        $this->module_root = $this->app_root.'/modules/'.$this->module;

        $this->log = Dase_Logger::instance(LOG_DIR,LOG_LEVEL);
    }

    public function getResponse()
    {
        return $this->sf_response;
    }

    public function getContentType()
    {
        $ct = $this->sf_request->headers->get('content_type');
        $parts = explode(';',$ct);
        $content_type = array_shift($parts);
        return $content_type;
    }

    public function init($db,$config,$template)
    {
        $this->template = $template;
        $this->db = $db;
        $this->config = $config;
        $this->checkForceHttps($config);
        $this->initDefaultHandler();
        $this->initUser();
        $this->initCache();
        $this->initCookie();
        $this->initAuth();
        $this->initPlugin();
        $this->logRequest();
    }

    //todo: needs work -- set by handler route var matches
    public function setParams($params) 
    {
        $this->params = $params; 
    }

    public function getAppSettings()
    {
        return $this->config->getAppSettings();
    }

    public function has($key)
    {
        if ($this->sf_request->request->has($key)) {
            return true;
        }
        if ($this->sf_request->query->has($key)) {
            return true;
        }
        if (isset($this->params[$key])) {
            return true;
        }
        return false;
    }

    public function hasFile($key)
    {
        if ($this->sf_request->files->has($key)) {
            return true;
        }
        return false;
    }

    public function getFile($key)
    {
        if ($this->sf_request->files->has($key)) {
            return $this->sf_request->files->get($key);
        }
    }

    public function keys()
    {  
        return $this->sf_request->request->keys();
    }

    //todo: work on returning arrays when appropriate
    public function get($key)
    {
        if ($this->sf_request->request->has($key)) {
            return trim($this->sf_request->request->filter($key));
        }
        if ($this->sf_request->query->has($key)) {
            return trim($this->sf_request->query->filter($key));
        }
        if (isset($this->params[$key])) {
            return trim($this->params[$key]);
        }
    }

    public function getBody()
    {
        return trim($this->sf_request->getContent());
    }

    public function __call( $method,$args ) 
    {
        return $this->sf_request->$method($args);
    }

    public function assign($key,$val)
    {
        $this->template->assign($key,$val);
    }

{'fraction_non_alphanumeric': 0.17024793388429751, 'fraction_numerical': 0.0005509641873278236, 'mean_word_length': 2.376007439553627, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 266, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4584936', 'n_tokens_mistral': 3417, 'n_tokens_neox': 3359, 'n_words': 589}