Your IP : 216.73.216.240


Current Path : /home/juvelize/saulnois/tmp/install_695d2cf0b4957/src/
Upload File :
Current File : /home/juvelize/saulnois/tmp/install_695d2cf0b4957/src/TInput.php

<?php
/*
* @package		Tech Fry Library
* @license		https://www.gnu.org/licenses/gpl-3.0.en.html
*/

namespace TechFry\Library;

defined('_JEXEC') or die;

use Joomla\CMS\Factory;

// Class to retrieve data from any source like REQUEST, POST, GET, SERVER, FILES and Clean/Filter data
class TInput
{
    public $input;

    public function __construct()
    {
        $this->input = Factory::getApplication()->input;
    }
    
    public function get_value($name, $default = null, $filter = 'cmd')
    {
        /*
            $filter: int, uint (unsigned integer), float, boolean
            word, alnum, cmd (task), base64, string, html, raw, username, array, path, trim
        */
        
        $value = $this->input->get($name, $default, $filter);

        return $value;
    }
    
    // Get Array
    public function get_array($method = '')
    {
        if (empty($method))
        {
            return $this->input->getArray();
        }

        $method = strtoupper($method);

        if ($method == 'GET')
        {
            return $this->input->get->getArray();
        }

        if ($method == 'POST')
        {
            return $this->input->post->getArray();
        }

        if ($method == 'FILES')
        {
            return $this->input->files->getArray();
        }

        if ($method == 'SERVER')
        {
            return $this->input->server->getArray();
        }
    }

    public function get_values($array = [])
    {
        // $array - names are in keys and filter type in value

        return $this->input->getArray($array);
    }

    public function set_value($name, $value)
    {
        $this->input->set($name, $value);
    }

    // Value will only be set if there is no value for the name or if it is null
    public function def_value($name, $value)
    {
        $this->input->def($name, $value);
    }

    // Get files
    public function get_files($name = '')
    {
        // File info - name, type, tmp_name, error, size

        if (empty($name))
        {
            $files = $this->input->files->getArray();
        }
        else
        {
            $files = $this->input->files->get($name);
        }

        return $files;
    }

    // Get json
    public function get_json($name)
    {
        return $this->input->json->get($name);
    }

    // Get server parameter
    public function get_server($name, $default = null, $filter = 'raw')
    {
        $name = strtoupper($name);

        return $this->input->server->get($name, $default, $filter);
    }

    public function get_int($name, $default = null)
    {
        return $this->input->get($name, $default, 'int');
    }

    public function get_string($name, $default = null)
    {
        return $this->input->get($name, $default, 'string');
    }

    public function get_raw($name, $default = null)
    {
        return $this->input->get($name, $default, 'raw');
    }
}

/*
int: /[-+]?[0-9]+/
uint: /[-+]?[0-9]+/
word: /[^A-Z_]/i
alnum: /[^A-Z0-9]/i
cmd: /[^A-Z0-9_\.-]/i
base64: /[^A-Z0-9\/+=]/i
username: /[\x00-\x1F\x7F<>"\'%&]/
*/