<commit_before><?php
/**
 * This file is part of the Everon framework.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Everon\Rest\Resource;

use Everon\Rest\Dependency;
use Everon\Helper;
use Everon\Rest\Interfaces;

class Navigator implements Interfaces\ResourceNavigator
{
    use Dependency\Request;

    const PARAM_SEPARATOR = ',';

    
    protected $expand = null;
    protected $fields = null;
    protected $order_by = null;
    protected $sort = null;
    protected $offset = null;
    protected $limit = null;
    

    /**
     * @param Interfaces\Request $Request
     */
    public function __construct(Interfaces\Request $Request)
    {
        $this->Request = $Request;
        $this->init();
    }

    /**
     * @param $name
     * @param null $default
     * @return array|mixed|null
     */
    protected function getParameterValue($name, $default=null)
    {
        $as_array = is_array($default);
        $value = $this->getRequest()->getQueryParameter($name, null);
        if ($value !== null) {
            if ($as_array || strpos($value, static::PARAM_SEPARATOR) !== false) {
                $value = explode(static::PARAM_SEPARATOR, trim($value, static::PARAM_SEPARATOR)); //eg. date_added,user_name
                if (is_array($value)) {
                    return $value;
                }
            }
            else {
                return $this->getRequest()->getQueryParameter($name, $default);
            }
        }
        
        return $default;
    }
    
    protected function init()
    {
        $this->fields = $this->getParameterValue('fields', []);
        $this->expand = $this->getParameterValue('expand', []);
        $this->order_by = $this->getParameterValue('order_by', []);
        $this->limit = $this->getParameterValue('limit', 10);
        $this->offset = $this->getParameterValue('offset', 0);
        $this->sort = [];
        
        $collection = $this->getRequest()->getQueryParameter('collection', null);
        if ($collection !== null) {
            $this->expand = array_merge($this->expand, [$collection]);
        }

        for ($a=0; $a<count($this->order_by); $a++) { //eg. -date_added, user_name //show recently added users
            $name = $this->order_by[$a];
            $field_name = ltrim($name, '-');
            $this->sort[$field_name] = 'ASC';
            if ($name[0] === '-') {
                $this->sort[$field_name] = 'DESC';
            }
            
            $this->order_by[$a] = $field_name;
        }
    }

    /**
     * @inheritdoc
     */
    public function setExpand($expand)<commit_msg>paramters are read from GET not from QUERY anymore<commit_after><?php
/**
 * This file is part of the Everon framework.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Everon\Rest\Resource;

use Everon\Rest\Dependency;
use Everon\Helper;
use Everon\Rest\Interfaces;

class Navigator implements Interfaces\ResourceNavigator
{
    use Dependency\Request;

    const PARAM_SEPARATOR = ',';

    
    protected $expand = null;
    protected $fields = null;
    protected $order_by = null;
    protected $sort = null;
    protected $offset = null;
    protected $limit = null;
    

    /**
     * @param Interfaces\Request $Request
     */
    public function __construct(Interfaces\Request $Request)
    {
        $this->Request = $Request;
        $this->init();
    }

    /**
     * @param $name
     * @param null $default
     * @return array|mixed|null
     */
    protected function getParameterValue($name, $default=null)
    {
        $as_array = is_array($default);
        $value = $this->getRequest()->getGetParameter($name, null);
        if ($value !== null) {
            if ($as_array || strpos($value, static::PARAM_SEPARATOR) !== false) {
                $value = explode(static::PARAM_SEPARATOR, trim($value, static::PARAM_SEPARATOR)); //eg. date_added,user_name
                if (is_array($value)) {
                    return $value;
                }
            }
            else {
                return $this->getRequest()->getQueryParameter($name, $default);
            }
        }
        
        return $default;
    }
    
    protected function init()
    {
        $this->fields = $this->getParameterValue('fields', []);
        $this->expand = $this->getParameterValue('expand', []);
        $this->order_by = $this->getParameterValue('order_by', []);
        $this->limit = $this->getParameterValue('limit', 10);
        $this->offset = $this->getParameterValue('offset', 0);
        $this->sort = [];

        $collection = $this->getRequest()->getQueryParameter('collection', null);
        if ($collection !== null) {
            $this->expand = array_merge($this->expand, [$collection]);
        }

        for ($a=0; $a<count($this->order_by); $a++) { //eg. -date_added, user_name //show recently added users
            $name = $this->order_by[$a];
            $field_name = ltrim($name, '-');
            $this->sort[$field_name] = 'ASC';
            if ($name[0] === '-') {
                $this->sort[$field_name] = 'DESC';
            }
            
            $this->order_by[$a] = $field_name;
        }
    }

    /**
     * @inheritdoc
     */
    public function setExpand($expand)
{'fraction_non_alphanumeric': 0.15247127484953493, 'fraction_numerical': 0.001823819077147547, 'mean_word_length': 2.18282066163668, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1198796', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1571, 'n_words': 341}