示例#1
0
 function processToken($name, $value, $parsedToken)
 {
     $this->stateMachine->addJS($parsedToken);
     //Maybe should be parsedToken
     if ($name == 'T_CONSTANT_ENCAPSED_STRING') {
         if ($this->defineName == FALSE) {
             $this->defineName = unencapseString($value);
         } else {
             $this->stateMachine->addDefine($this->defineName, unencapseString($value));
             $this->changeToState(CONVERTER_STATE_DEFAULT);
         }
     } else {
         if ($name == 'T_LNUMBER') {
             $this->stateMachine->addDefine($this->defineName, intval($value, 0));
             $this->changeToState(CONVERTER_STATE_DEFAULT);
         } else {
             if ($name == 'T_DNUMBER') {
                 $this->stateMachine->addDefine($this->defineName, floatval($value));
                 $this->changeToState(CONVERTER_STATE_DEFAULT);
             } else {
                 if ($name == 'T_STRING') {
                     $this->stateMachine->addDefine($this->defineName, convertPHPValueToJSValue($value));
                     if ($this->pastDefineToken == true) {
                         $this->changeToState(CONVERTER_STATE_DEFAULT);
                     }
                 }
             }
         }
     }
     $this->pastDefineToken = true;
 }
示例#2
0
 function processToken($name, $value, $parsedToken)
 {
     if ($name == 'T_WHITESPACE' || $name == '=' || $name == 'T_CONSTANT_ENCAPSED_STRING' || $name == 'T_LNUMBER' || $name == 'T_COMMENT' || $name == 'T_STRING') {
         $value = convertPHPValueToJSValue($value);
         $this->stateMachine->currentScope->addToVariableValue($value);
         return;
     }
     if ($name == ';') {
         $this->stateMachine->clearVariableFlags();
         $this->changeToState(CONVERTER_STATE_DEFAULT);
         return;
     }
     if ($name == "T_ARRAY") {
         $this->changeToState(CONVERTER_STATE_ARRAY);
         return true;
         //reprocess token
     }
     if ($name == "[") {
         $classScope = false;
         $this->stateMachine->startArrayScope("", true);
         //			if ($this->stateMachine->currentScope instanceof ClassScope) {
         //				$classScope = $this->stateMachine->currentScope;
         //			}
         //
         //
         //			$this->stateMachine->pushScope(CODE_SCOPE_ARRAY, $value, DECLARATION_TYPE_SQUARE_ARRAY);
         //
         //			if ($classScope != false) {
         //				$this->stateMachine->currentScope->setVariableName($classScope->currentVariableName);
         //			}
         //
         //			$this->changeToState(CONVERTER_STATE_DEFAULT);
         $this->stateMachine->currentTokenStream->insertToken('(');
         return false;
     }
     //		if($this->stateMachine->currentScope instanceof ClassScope){
     //			throw new \Exception("Sorry, initializing class variables to an array is not supported yet. The difficultly is that the initial value must be moved from where it is declared to outside the class declaration code, which is difficult for arrays. Please instead declare the variable as null, and then assign it an array in the constructor.");
     //		}
     throw new \Exception("The only symbols expected here are '=', ';' and some sort of value. Instead received token name [{$name}] with value [{$value}].");
 }
示例#3
0
 function processToken($name, $value, $parsedToken)
 {
     $value = convertPHPValueToJSValue($value);
     if ($this->stateMachine->isDefined($value)) {
         $defineValue = $this->stateMachine->getDefine($value);
         $this->stateMachine->addJS($defineValue);
     } else {
         if (strcmp('static', $value) == 0 || strcmp('self', $value) == 0) {
             $this->stateMachine->addJS($this->stateMachine->getClassName());
         } else {
             if ($this->stateMachine->currentScope instanceof FunctionParameterScope) {
                 //Probably a typehint.
                 $this->stateMachine->addJS("/*" . $value . "*/");
             } else {
                 if ($this->stateMachine->currentScope instanceof CatchScope) {
                     //$this->stateMachine->currentScope->addExceptionName($value);
                     $this->stateMachine->addJS("/*" . $value . "*/");
                 } else {
                     $variable = $this->stateMachine->getVariableFromScope($value, CODE_SCOPE_CLASS);
                     if ($variable) {
                         if ($variable->flags & DECLARATION_TYPE_PRIVATE) {
                             if ($this->stateMachine->previousTokensMatch(['this', '.']) == true) {
                                 //For the record, this is the hackiest bit of code, so far.
                                 $this->stateMachine->deleteTokens(2);
                             }
                         }
                     }
                     $this->stateMachine->addJS($value);
                 }
             }
         }
     }
     //TODO - added this to fix "SomeClass::someFunc()" leaving variableFlags in non zero state
     //But not sure if this is safe.
     $this->stateMachine->variableFlags = 0;
     $this->changeToState(CONVERTER_STATE_DEFAULT);
 }
 function addToJsForPreviousVariable($value)
 {
     if ($this->beforeVariable == TRUE) {
         //It's actually a type-hint not a default value, as it before the variable name
         return;
     }
     $allKeys = array_keys($this->scopedVariables);
     if (count($allKeys) == 0) {
         throw new \Exception("Trying to add default variable but not variables found yet.");
     }
     $variableName = $allKeys[count($allKeys) - 1];
     if (isset($this->defaultValues[$variableName]) == false) {
         $this->defaultValues[$variableName] = '';
     }
     $this->defaultValues[$variableName] .= convertPHPValueToJSValue($value);
 }