@param ApiResource $variable

@return string
438383
protected function getVariableLevel(ApiResource $variable)
    {
        if ($variable instanceof EnvironmentLevelVariable) {
            return self::LEVEL_ENVIRONMENT;
        } elseif ($variable instanceof ProjectLevelVariable) {
            return self::LEVEL_PROJECT;
        }
        throw new \RuntimeException('Variable level not found');
    }
422483
protected function evalVarLabel($variable)
    {
        $type = $this->getType($variable);
        switch ($type) {
            case 'object':
                return $this->evalObjLabel($variable);

            case 'array':
                return $type . '('.count($variable).')';

            default:
                return $type;
        }
    }
1039256
public static function debug($variable)
    {
        ob_start();
        var_dump($variable);
        $output = ob_get_clean();
        $maps = ['string' => "/(string\((?P<length>\d+)\)) (?P<value>\"(?<!\\\).*\")/i", 'array' => "/\[\"(?P<key>.+)\"(?:\:\"(?P<class>[a-z0-9_\\\]+)\")?(?:\:(?P<scope>public|protected|private))?\]=>/Ui", 'countable' => "/(?P<type>array|int|string)\((?P<count>\d+)\)/", 'resource' => "/resource\((?P<count>\d+)\) of type \((?P<class>[a-z0-9_\\\]+)\)/", 'bool' => "/bool\((?P<value>true|false)\)/", 'float' => "/float\((?P<value>[0-9\.]+)\)/", 'object' => "/object\((?P<class>\S+)\)\#(?P<id>\d+) \((?P<count>\d+)\)/i"];
        foreach ($maps as $function => $pattern) {
            $output = preg_replace_callback($pattern, function ($matches) use ($function) {
                switch ($function) {
                    case 'string':
                        $matches['value'] = htmlspecialchars($matches['value']);

                        return '<span style="color: #0000FF;">string</span>(<span style="color: #1287DB;">'.$matches['length'].')</span> <span style="color: #6B6E6E;">'.$matches['value'].'</span>';

                    case 'array':
                        $key = '<span style="color: #008000;">"'.$matches['key'].'"</span>';
                        $class = '';
                        $scope = '';
                        if (isset($matches['class']) && !empty($matches['class'])) {
                            $class = ':<span style="color: #4D5D94;">"'.$matches['class'].'"</span>';
                        }
                        if (isset($matches['scope']) && !empty($matches['scope'])) {
                            $scope = ':<span style="color: #666666;">'.$matches['scope'].'</span>';
                        }

                        return '['.$key.$class.$scope.']=>';

                    case 'countable':
                        $type = '<span style="color: #0000FF;">'.$matches['type'].'</span>';
                        $count = '(<span style="color: #1287DB;">'.$matches['count'].'</span>)';

                        return $type.$count;

                    case 'bool':
                        return '<span style="color: #0000FF;">bool</span>(<span style="color: #0000FF;">'.$matches['value'].'</span>)';

                    case 'float':
                        return '<span style="color: #0000FF;">float</span>(<span style="color: #1287DB;">'.$matches['value'].'</span>)';

                    case 'resource':
                        return '<span style="color: #0000FF;">resource</span>(<span style="color: #1287DB;">'.$matches['count'].'</span>) of type (<span style="color: #4D5D94;">'.$matches['class'].'</span>)';

                    case 'object':
                        return '<span style="color: #0000FF;">object</span>(<span style="color: #4D5D94;">'.$matches['class'].'</span>)#'.$matches['id'].' (<span style="color: #1287DB;">'.$matches['count'].'</span>)';

                }
            }, $output);
        }
        $header = '';
        list($debugfile) = debug_backtrace();

        if (!empty($debugfile['file'])) {
            $header = '<h4 style="border-bottom:1px solid #bbb;font-weight:bold;margin:0 0 10px 0;padding:3px 0 10px 0">'.$debugfile['file'].'</h4>';
        }

        echo '<pre style="background-color: #CDDCF4;border: 1px solid #bbb;border-radius: 4px;-moz-border-radius:4px;-webkit-border-radius\:4px;font-size:12px;line-height:1.4em;margin:30px;padding:7px">'.$header.$output.'</pre>';
    }
456617
public static function getTypeFromPHPVariable($variable) : ?Type
    {
        if (is_object($variable)) {
            if ($variable instanceof DateTimeInterface) {
                return self::getType('date');
            }

            if ($variable instanceof ObjectId) {
                return self::getType('id');
            }
        } else {
            $type = gettype($variable);
            switch ($type) {
                case 'integer':
                    return self::getType('int');
            }
        }
        return null;
    }
909814
public function render($arrayVariable = null, $objectVariable = null, $keyVariable = null)
    {
        $formatter = $this->getFormatter();

        $arrayVariable = $arrayVariable ?: 'a';
        $objectVariable = $objectVariable ?: 'o';
        $keyVariable = $keyVariable ?: 'k';

        return $formatter->renderClosure($formatter->renderLines([
            $formatter->renderAssignment('var '.$arrayVariable, '[]', true),
            $formatter->renderStatement(
                'for',
                $formatter->renderCall(
                    $formatter->renderProperty($arrayVariable, 'push'),
                    [$objectVariable.'['.$keyVariable.']'],
                    true
                ),
                'var '.$keyVariable.' in '.$objectVariable,
                null,
                false
            ),
            $formatter->renderCode('return '.$arrayVariable, true, false),
        ], true, false), [$objectVariable]);
    }
882240
public function createFiltersMethods(array $names, $variable)
    {
        if($names === array())
        {
            return $variable;
        }

        $filter = array_shift($names);

        if($filter === 'raw')
        {
            $result = $this->createFiltersMethods($names, $variable);
        }
        else
        {
            $begin = '';
            $end   = '';

            if(function_exists($filter))
            {
                $begin = "{$filter}(";
            }
            else
            {
                $begin = "\$env->filter('{$filter}', ";
            }

            $result = $begin.$this->createFiltersMethods($names, $variable).')';
        }

        return $result;
    }
103519
protected function evaluateSPX($variable = array())
    {
        
    	common_Logger::d('SPX TYPE', array('Generis Term evaluateSPX'));
    	$resource = $this->getUniquePropertyValue(new core_kernel_classes_Property(RulesRdf::PROPERTY_TERM_SPX_SUBJET));
    	if($resource instanceof core_kernel_classes_Resource){
    		if(array_key_exists($resource->getUri(),$variable)) {
    			common_Logger::d('Variable uri : ' .  $resource->getUri() . ' found', array('Generis Term evaluateSPX'));
    			common_Logger::d('Variable name : ' .  $resource->getLabel() . ' found', array('Generis Term evaluateSPX'));
    			$resource = new core_kernel_classes_Resource($variable[$resource->getUri()]);
    			common_Logger::d('Variable repaced uri : ' .  $resource->getUri(), array('Generis Term evaluateSPX'));
    			common_Logger::d('Variable repaced name : ' .  $resource->getLabel(), array('Generis Term evaluateSPX'));
    		}
    		
    		try
    		{
    			$propertyInstance = $this->getUniquePropertyValue(new core_kernel_classes_Property(RulesRdf::PROPERTY_TERM_SPX_PREDICATE));
    		}
    		catch (common_Exception $e)
    		{
    			echo $e;
    			var_dump($this);
    			die('unable to get property value in Term');
    		}
//    		if(array_key_exists($propertyInstance->getUri(),$variable)) {
//				$logger->debug('Variable uri : ' .  $propertyInstance->getUri() . ' found' , __FILE__, __LINE__);
//    			$logger->debug('Variable name : ' .  $propertyInstance->getLabel() . ' found' , __FILE__, __LINE__);
//				$propertyInstance = new core_kernel_classes_Resource($variable[$resource->getUri()]);
//    			$logger->debug('Variable repaced uri : ' .  $propertyInstance->getUri() , __FILE__, __LINE__);
//    			$logger->debug('Variable repaced name : ' .  $propertyInstance->getLabel() , __FILE__, __LINE__);
//    	    }
    		$property = new core_kernel_classes_Property($propertyInstance->getUri());
    		common_Logger::d('Property uri ' . $property->getUri(), array('Generis Term evaluateSPX'));
    		common_Logger::d('Property name ' . $property->getLabel(), array('Generis Term evaluateSPX'));
       		$returnValue = $resource->getPropertyValuesCollection($property);
       		common_Logger::d($returnValue->count() . ' values returned ', array('Generis Term evaluateSPX'));

       		if($returnValue->isEmpty()) {
       			$newEmptyTerm = new core_kernel_rules_Term(RulesRdf::INSTANCE_TERM_IS_NULL,__METHOD__);
       			common_Logger::d('Empty Term Created', array('Generis Term evaluateSPX'));
       			$property = new core_kernel_classes_Property(RulesRdf::PROPERTY_TERM_VALUE);
       			$returnValue = $newEmptyTerm->getUniquePropertyValue($property);	
       		}
       		else {
				if($returnValue->count() == 1 ) {
       					$returnValue = $returnValue->get(0);
       			}
       		}

       		
    	}
    	return $returnValue;
        
    }
679912
protected function getApiResults($apiPath, $raw = false)
    {
        $apiUrl = $this->apiUrl . $apiPath;

        $response = Http::sendHttpRequest($apiUrl, 1000, null, null, 5, false, false, true, 'GET', $this->username, $this->password);

        $httpStatus = $response['status'];
        $response = $response['data'];

        if ($httpStatus == 401) {
            throw new AuthenticationFailedException();
        } elseif ($httpStatus != 200) {
            throw new Exception('Error while getting API results', $httpStatus);
        }

        return $raw ? $response : json_decode($response);
    }
1038850
public function toUpperCaseFirst($var)
    {
        $v = '' . $var;
        $len = $this->strlen($var);
        if (!$len) {
            return '';
        }
        if (static::$nativeSupport['mbstring']) {
            if ($len > 1) {
                return mb_strtoupper(mb_substr($v, 0, 1)) . mb_substr($v, 1);
            }
            return mb_strtoupper($v);
        }
        return $v;
    }
861487
public function toUpperCaseLast($var)
    {
        $v = '' . $var;
        $len = $this->strlen($var);
        if (!$len) {
            return '';
        }
        if (static::$nativeSupport['mbstring']) {
            if ($len > 1) {
                return mb_substr($v, 0, $len - 2) . mb_strtoupper(mb_substr($v, $len - 2));
            }
            return mb_strtoupper($v);
        }
        return $v;
    }
934020
protected function getPresenterMethodFromVariable($variable)
    {
        $method = 'present'.str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $variable)));
        if (method_exists($this, $method)) {
            return $method;
        }
    }
109259
protected function getDataCss($variable)
    {
        $css = [
            'padding'               => '7px',
            'background-color'      => $this->zebra ? '#D8D9DB' : '#FFF',
            'color'                 => '#405261',
        ];

        $type = gettype($variable);
        if ($type == 'NULL') {
            $css['color'] = '#999';
        }

        return $this->arrayToCss($css);
    }
1330254
private function replaceVariables($template, array $variables): string
    {
        foreach ($variables as $key => $value) {
            $key = '%'.$key.'%';

            $template = \str_replace($key, $value, $template);
        }

        return $template;
    }
1339682
private function varIsResource($var)
    {
        $this->makeTableHeader("resourceC", "resource", 1);
        echo "<tr>\n<td>\n";
        switch (get_resource_type($var)) {
            case "fbsql result":
            case "mssql result":
            case "msql query":
            case "pgsql result":
            case "sybase-db result":
            case "sybase-ct result":
            case "mysql result":
                $db = current(explode(" ", get_resource_type($var)));
                $this->varIsDBResource($var, $db);
                break;
            case "gd":
                $this->varIsGDResource($var);
                break;
            case "xml":
                $this->varIsXmlResource($var);
                break;
            default:
                echo get_resource_type($var) . $this->closeTDRow();
                break;
        }
        echo $this->closeTDRow() . "</table>\n";
    }
545545
public static function dumperGet(&$variable, $spacing = "") {
        if (is_array($variable)) {
            $type = "Array[" . count( $variable ) . "]";
        } elseif( is_object( $variable ) ) {
            ob_start();
            print_r($variable);
            return ob_get_clean();

        } elseif( gettype( $variable ) == "boolean" ) {
            return $variable ? "true" : "false";
        } elseif( is_null( $variable ) ) {
            return "NULL";
        } else {
            ob_start();
            var_dump($variable);
            return ob_get_clean();
        }
        $buf = $type;
        $spacing .= "    ";
        for (reset( $variable ); list ( $k, $v ) = each( $variable );) {
            if ($k === "GLOBALS" )
                continue;
            $buf .= "\n".$spacing.'['.$k.'] => ' . self::dumperGet( $v, $spacing);
        }

        return $buf;
    }
848291
public function getResourceWildcard($value)
    {
        if (isset($this->parameters[$value])) {
            $value = $this->parameters[$value];
        } elseif (isset(static::$parameterMap[$value])) {
            $value = static::$parameterMap[$value];
        } elseif ($this->parameters === 'singular' || static::$singularParameters) {
            $value = Str::singular($value);
        }

        return str_replace('-', '_', $value);
    }
81749
public function compileVariable($variable)
    {
        if (strpos($variable, '(') == 0) {
            // not a variable variable
            $var = trim($variable, '\'');
            $this->tag_nocache = $this->tag_nocache |
                $this->template->ext->getTemplateVars->_getVariable($this->template, $var, null, true, false)->nocache;
            // todo $this->template->compiled->properties['variables'][$var] = $this->tag_nocache | $this->nocache;
        }
        return '$_smarty_tpl->tpl_vars[' . $variable . ']->value';
    }