Create a ResponseVariable object from its data model representation.

@param \qtism\data\state\VariableDeclaration $variableDeclaration
@throws \InvalidArgumentException
@return \qtism\runtime\common\ResponseVariable
427155
public static function createFromDataModel(VariableDeclaration $variableDeclaration)
    {
        $variable = parent::createFromDataModel($variableDeclaration);

        if ($variableDeclaration instanceof ResponseDeclaration) {

            $variable->setMapping($variableDeclaration->getMapping());
            $variable->setAreaMapping($variableDeclaration->getAreaMapping());

            $dataModelCorrectResponse = $variableDeclaration->getCorrectResponse();
            if (!empty($dataModelCorrectResponse)) {
                $baseType = $variable->getBaseType();
                $cardinality = $variable->getCardinality();
                $dataModelValues = $dataModelCorrectResponse->getValues();
                $correctResponse = static::dataModelValuesToRuntime($dataModelValues, $baseType, $cardinality);

                $variable->setCorrectResponse($correctResponse);
            }

            return $variable;
        } else {
            $msg = "ResponseVariable::createFromDataModel only accept 'qtism\\data\\state\\ResponseDeclaration' objects, '" . get_class($variableDeclaration) . "' given.";
            throw new InvalidArgumentException($msg);
        }
    }
656556
public final static function factory( & $variable, $name = null )
	{
		isset( self::$_customDataTypes ) or self::_init();

		# save internal data to revert after dumping to properly handle recursions etc
		$revert = array(
			'level'   => self::$_level,
			'objects' => self::$_objects,
		);

		self::$_level++;

		$name          = self::_escape( $name );
		$varData       = new kintVariableData;
		$varData->name = $name;

		# first parse the variable based on its type
		$varType = gettype( $variable );
		$varType === 'unknown type' and $varType = 'unknown'; # PHP 5.4 inconsistency
		$methodName = '_parse_' . $varType;

		# base type parser returning false means "stop processing further": e.g. recursion
		if ( self::$methodName( $variable, $varData ) === false ) {
			self::$_level--;
			return $varData;
		}

		if ( !self::$_skipAlternatives) {
			# if an alternative returns something that can be represented in an alternative way, don't :)
			self::$_skipAlternatives = true;

			# now check whether the variable can be represented in a different way
			foreach ( self::$_customDataTypes as $parserClass ) {
				$className = '\\Arx\\classes\\debug\\Kint_Parsers_' . $parserClass;

				/** @var $object kintParser */
				$object       = new $className;

				$object->name = $name; # the parser may overwrite the name value, so set it first

				if ( $object->_parse( $variable ) !== false ) {
					$varData->alternatives[] = $object;
				}
			}


			# combine extended values with alternative representations if applicable
			if ( !empty( $varData->alternatives ) && isset( $varData->extendedValue ) ) {
				$a = new kintVariableData;

				$a->value = $varData->extendedValue;
				$a->type  = $varData->type;
				$a->size  = $varData->size;

				array_unshift( $varData->alternatives, $a );
				$varData->extendedValue = null;
			}

			self::$_skipAlternatives = false;
		}

		self::$_level   = $revert['level'];
		self::$_objects = $revert['objects'];
		return $varData;
	}
387026
public function setResponse(ResponseDeclaration $response){
        $relatedItem = $this->getRelatedItem();
        if(!is_null($relatedItem)){
            $relatedItem->addResponse($response);
        }
        return $this->setAttribute('responseIdentifier', $response);
    }
518089
private VariableStatementTree parseVariableStatement() {
    SourcePosition start = getTreeStartLocation();
    VariableDeclarationListTree declarations = parseVariableDeclarationList();
    eatPossibleImplicitSemiColon();
    return new VariableStatementTree(getTreeLocation(start), declarations);
  }
1122563
static public function formatVariableToPci(ResponseVariable $var) {
        $value = $var->getValue();
        switch($var->getCardinality()){
            case 'single':
                if(strlen($value) === 0){
                    $formatted = ['base' => null];
                }else{
                    try {
                        $formatted = ['base' => [$var->getBaseType() => self::formatStringValue($var->getBaseType(), $value)]];
                    } catch (\common_exception_NotImplemented $e) {
                        // simply ignore unsupported data/type
                        $formatted = ['base' => null];
                    }
                }
                break;
            case 'ordered':
            case 'multiple':
                if(strlen($value) === 0){
                    $formatted = ['list' => [$var->getBaseType() => []]];
                }else{
                    preg_match_all('/([^\[\];<>]+)/', $value, $matches);
                    $list = [];
                    foreach($matches[1] as $valueString){
                        if(empty(trim($valueString))){
                            continue;
                        }

                        try {
                            $list[] = self::formatStringValue($var->getBaseType(), $valueString);
                        } catch (\common_exception_NotImplemented $e) {
                            // simply ignore unsupported data/type
                        }
                    }
                    $formatted = ['list' => [$var->getBaseType() => $list]];
                }
                break;
            default:
                throw new \common_Exception('unknown response cardinality');
        }
        return $formatted;
    }
1291284
protected function getEffectiveType(
        TypeInterface $variableType,
        VariableDefinitionNode $variableDefinition
    ): TypeInterface {
        return (!$variableDefinition->hasDefaultValue() || $variableType instanceof NonNullType)
            ? $variableType
            : newNonNull($variableType);
    }
546945
final public function createFixedHeader(int $variableHeaderLength): string
    {
        $this->logger->debug('Creating fixed header with values', [
            'controlPacketValue' => self::getControlPacketValue(),
            'specialFlags' => $this->specialFlags,
            'variableHeaderLength' => $variableHeaderLength,
            'composed' => decbin(chr((self::getControlPacketValue() << 4) | $this->specialFlags)),
        ]);

        // Binary OR is safe to do because the first 4 bits are always 0 after shifting
        return
            chr((self::getControlPacketValue() << 4) | $this->specialFlags) .
            Utilities::formatRemainingLengthOutput($variableHeaderLength);
    }
1183005
protected function lexVariable(): VariableNode
    {
        $start = $this->lexer->getToken();

        $this->expect(TokenKindEnum::DOLLAR);

        return new VariableNode($this->lexName(), $this->createLocation($start));
    }
1082420
private Ref functionArgDeclarationVarString() throws PageException {

	cfml.removeSpace();
	StringBuilder str = new StringBuilder();
	String id = null;
	while ((id = identifier(false)) != null) {
	    if (str.length() > 0) str.append('.');
	    str.append(id);
	    cfml.removeSpace();
	    if (!cfml.forwardIfCurrent('.')) break;
	    cfml.removeSpace();
	}
	cfml.removeSpace();
	if (str.length() > 0 && cfml.charAt(cfml.getPos() - 1) != '.') return new LString(str.toString());

	throw new InterpreterException("invalid variable name definition");
    }
1110937
private function getMakeablePropertyDeclaration()
    {

        if( $this->entity->pgClass->isView() or $this->entity->pgClass->isMaterialisedView() ) {
            $makeable = 'MAKEABLE_EXCEPTION';
        }

        if( array_key_exists( 'makeable', $this->entity->normalityTags ) ) {
            $makeable = $this->entity->normalityTags['makeable'];
        }

        if( !isset( $makeable ) ) {
            return;
        }

        if( !defined( "\Bond\Repository::{$makeable}" ) ) {
            throw new \InvalidArgumentException("normality.makeable has bad value `{$makeable}`.");
        }

        $this->class->classComponents[] = new VariableDeclaration(
            'resolver',
            new SFormatf( <<<'PHP'
                /**
                 * Makeable
                 * @var string
                 */
                protected $makeable = self::%s;
PHP
                , $makeable
            )
        );

    }
1200868
public function get(string $variableName = null, int $type = Variables::TYPE_ARRAY)
    {
        if ($variableName === null) {
            throw new BadMethodCallException('Variable name must be specified');
        }
        if (isset($this->variables['MFVARS'][$variableName])) {
            return $this->variables['MFVARS'][$variableName];
        }
        if (isset($this->variables[$variableName])) {
            return $this->variables[$variableName];
        }
        return [];
    }
84695
public final void variableDeclarator() throws RecognitionException {
		variableDeclarator_stack.push(new variableDeclarator_scope());
		int variableDeclarator_StartIndex = input.index();

		Token id=null;
		ParserRuleReturnScope rest =null;


		        variableDeclarator_stack.peek().ident = new JavaLocalDeclarationDescr.IdentifierDescr();
		    
		try {
			if ( state.backtracking>0 && alreadyParsedRule(input, 39) ) { return; }

			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:466:5: (id= Identifier rest= variableDeclaratorRest )
			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:466:7: id= Identifier rest= variableDeclaratorRest
			{
			id=(Token)match(input,Identifier,FOLLOW_Identifier_in_variableDeclarator1355); if (state.failed) return;
			pushFollow(FOLLOW_variableDeclaratorRest_in_variableDeclarator1359);
			rest=variableDeclaratorRest();
			state._fsp--;
			if (state.failed) return;
			if ( state.backtracking==0 ) {
			            variableDeclarator_stack.peek().ident.setIdentifier( (id!=null?id.getText():null) );
			            variableDeclarator_stack.peek().ident.setStart( ((CommonToken)id).getStartIndex() - 1 );
			            if( (rest!=null?(rest.stop):null) != null ) {
			                   variableDeclarator_stack.peek().ident.setEnd( ((CommonToken)(rest!=null?(rest.stop):null)).getStopIndex() );
			            }
			        }
			}

			if ( state.backtracking==0 ) {
			            if( VarDecl_stack.peek().descr != null ) {
			                VarDecl_stack.peek().descr.addIdentifier( variableDeclarator_stack.peek().ident );
			            }
			    }
		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
		}
		finally {
			// do for sure before leaving
			if ( state.backtracking>0 ) { memoize(input, 39, variableDeclarator_StartIndex); }

			variableDeclarator_stack.pop();
		}
	}
1346426
public function extractResultVariableProperty($variableId)
    {
        $variableIds = explode('http://',$variableId);
        $parts = explode(static::PROPERTY_SEPARATOR, $variableIds[2]);

        $itemUri = $variableIds[0] . 'http://' . $parts[0];
        $propertyName = empty($parts[1]) ? 'RESPONSE' : $parts[1];

        return [
            $itemUri,
            $propertyName
        ];
    }
939470
public function handle(VariableRepositoryInterface $variables)
    {
        if (!$group = $variables->group($this->group)) {
            return null;
        }

        return (new Decorator())->decorate($group)->{$this->field};
    }
852709
public final void localVariableDeclaration() throws RecognitionException {
		VarDecl_stack.push(new VarDecl_scope());

		int localVariableDeclaration_StartIndex = input.index();

		ParserRuleReturnScope variableModifier1 =null;
		ParserRuleReturnScope type2 =null;


		            VarDecl_stack.peek().descr = new JavaLocalDeclarationDescr();
		        
		try {
			if ( state.backtracking>0 && alreadyParsedRule(input, 82) ) { return; }

			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:710:5: ( ( variableModifier )* type variableDeclarators ';' )
			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:711:5: ( variableModifier )* type variableDeclarators ';'
			{
			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:711:5: ( variableModifier )*
			loop106:
			while (true) {
				int alt106=2;
				int LA106_0 = input.LA(1);
				if ( (LA106_0==58||LA106_0==83) ) {
					alt106=1;
				}

				switch (alt106) {
				case 1 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:711:7: variableModifier
					{
					pushFollow(FOLLOW_variableModifier_in_localVariableDeclaration2865);
					variableModifier1=variableModifier();
					state._fsp--;
					if (state.failed) return;
					if ( state.backtracking==0 ) {
					            VarDecl_stack.peek().descr.updateStart( ((CommonToken)(variableModifier1!=null?(variableModifier1.start):null)).getStartIndex() - 1 );
					            VarDecl_stack.peek().descr.addModifier( (variableModifier1!=null?input.toString(variableModifier1.start,variableModifier1.stop):null) );
					        }
					}
					break;

				default :
					break loop106;
				}
			}

			pushFollow(FOLLOW_type_in_localVariableDeclaration2888);
			type2=type();
			state._fsp--;
			if (state.failed) return;
			if ( state.backtracking==0 ) {
			            VarDecl_stack.peek().descr.updateStart( ((CommonToken)(type2!=null?(type2.start):null)).getStartIndex() - 1 );
			            VarDecl_stack.peek().descr.setType( (type2!=null?input.toString(type2.start,type2.stop):null) );
			            VarDecl_stack.peek().descr.setEnd( ((CommonToken)(type2!=null?(type2.stop):null)).getStopIndex() );
			        }
			pushFollow(FOLLOW_variableDeclarators_in_localVariableDeclaration2904);
			variableDeclarators();
			state._fsp--;
			if (state.failed) return;
			match(input,52,FOLLOW_52_in_localVariableDeclaration2906); if (state.failed) return;
			}

			if ( state.backtracking==0 ) {
			            addLocalDeclaration( VarDecl_stack.peek().descr );
			        }
		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
		}
		finally {
			// do for sure before leaving
			if ( state.backtracking>0 ) { memoize(input, 82, localVariableDeclaration_StartIndex); }

			VarDecl_stack.pop();

		}
	}
257487
public function addVariables($variables)
    {
        if ($variables instanceof stdClass) {
            $variables = (array) $variables;
        } elseif ($variables instanceof Traversable) {
            $variables = iterator_to_array($variables);
        } elseif (! is_array($variables)) {
            throw new InvalidArgumentException(sprintf(
                'Invalid variables provided; must be an array or Traversable '
                . 'or instance of stdClass, "%s" received.',
                is_object($variables) ? get_class($variables) : gettype($variables)
            ));
        }
        $this->container = array_merge($this->container, $variables);

        return $this;
    }
555137
public function RangeVariableDeclaration()
    {
        if ($this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS) && $this->lexer->glimpse()['type'] === Lexer::T_SELECT) {
            $this->semanticalError('Subquery is not supported here', $this->lexer->token);
        }

        $abstractSchemaName = $this->AbstractSchemaName();

        $this->validateAbstractSchemaName($abstractSchemaName);

        if ($this->lexer->isNextToken(Lexer::T_AS)) {
            $this->match(Lexer::T_AS);
        }

        $token                       = $this->lexer->lookahead;
        $aliasIdentificationVariable = $this->AliasIdentificationVariable();
        $classMetadata               = $this->em->getClassMetadata($abstractSchemaName);

        // Building queryComponent
        $queryComponent = [
            'metadata'     => $classMetadata,
            'parent'       => null,
            'relation'     => null,
            'map'          => null,
            'nestingLevel' => $this->nestingLevel,
            'token'        => $token,
        ];

        $this->queryComponents[$aliasIdentificationVariable] = $queryComponent;

        return new AST\RangeVariableDeclaration($abstractSchemaName, $aliasIdentificationVariable);
    }