function processToken($name, $value, $parsedToken)
 {
     $variableName = cVar($value);
     if ($value == "\$this") {
         $this->stateMachine->addJS("this");
     }
     $this->stateMachine->addScopedVariable($variableName, $this->stateMachine->variableFlags);
     if ($this->stateMachine->variableFlags & DECLARATION_TYPE_STATIC) {
         $this->stateMachine->currentScope->addStaticVariable($variableName);
         $this->changeToState(CONVERTER_STATE_VARIABLE_VALUE);
     } else {
         if ($this->stateMachine->variableFlags & DECLARATION_TYPE_PUBLIC) {
             $this->stateMachine->currentScope->addPublicVariable($variableName);
             $this->changeToState(CONVERTER_STATE_VARIABLE_VALUE);
         } else {
             //            if($this->stateMachine->variableFlags & DECLARATION_TYPE_CLASS){
             //			    //All other variables are treated as private
             //                $this->stateMachine->currentScope->addScopedVariable($variableName, $this->stateMachine->variableFlags);
             //            }
             $this->stateMachine->addJS("var ");
             $this->stateMachine->addJS($variableName);
             $this->stateMachine->clearVariableFlags();
             $this->changeToState(CONVERTER_STATE_DEFAULT);
         }
     }
 }
 function processToken($name, $value, $parsedToken)
 {
     $variableName = cVar($value);
     $this->stateMachine->addScopedVariable($variableName, $this->stateMachine->variableFlags);
     $this->stateMachine->addJS($variableName);
     $this->changeToState(CONVERTER_STATE_CAPTURING_DEFAULT_VALUE);
 }
 function processToken($name, $value, $parsedToken)
 {
     $variableName = cVar($value);
     $this->stateMachine->addJS($variableName);
     $this->stateMachine->clearVariableFlags();
     $this->changeToState(CONVERTER_STATE_DEFAULT);
 }
Exemple #4
0
 function processToken($name, $value, $parsedToken)
 {
     $jsToAdd = FALSE;
     //TODO - this is repeating code elsewhere.
     if ($name == 'T_VARIABLE') {
         $jsToAdd = cVar($value);
     } else {
         if ($name == 'T_OBJECT_OPERATOR' || $name == 'T_DOUBLE_COLON') {
             $jsToAdd = '.';
         } else {
             if ($name == 'T_STRING') {
                 if (strtolower($value) == 'self') {
                     $jsToAdd = $this->stateMachine->getClassName();
                 } else {
                     $jsToAdd = $value;
                 }
             } else {
                 if ($name == 'T_WHITESPACE') {
                     $jsToAdd = $value;
                 } else {
                     if ($name == ')') {
                         //Bracket is added magically, when we write the foreach from the extracted names.
                         //$jsToAdd = $name;
                     }
                 }
             }
         }
     }
     if ($name == 'T_AS') {
         $this->subState = CodeConverterState_TFOREACH::$SUBSTATE_KEY_OR_VALUE;
     }
     if ($name == 'T_DOUBLE_ARROW') {
         $this->subState = CodeConverterState_TFOREACH::$SUBSTATE_VALUE;
     }
     if ($jsToAdd != FALSE) {
         switch ($this->subState) {
             case CodeConverterState_TFOREACH::$SUBSTATE_OBJECT:
                 $this->arrayElements[] = $jsToAdd;
                 break;
             case CodeConverterState_TFOREACH::$SUBSTATE_KEY_OR_VALUE:
                 $this->keyOrValueElements[] = $jsToAdd;
                 break;
             case CodeConverterState_TFOREACH::$SUBSTATE_VALUE:
                 $this->valueElements[] = $jsToAdd;
                 break;
         }
     }
     if ($name == '{') {
         $this->finaliseString();
         $this->changeToState(CONVERTER_STATE_DEFAULT);
     }
 }
 function processToken($name, $value, $parsedToken)
 {
     if ($value == "\$this") {
         //TODO - if this ever happens it is a bug.
         $this->stateMachine->addJS("this");
     }
     $variableName = cVar($value);
     $wasAdded = $this->stateMachine->addScopedVariable($variableName, $this->stateMachine->variableFlags);
     if ($wasAdded == true) {
         $this->stateMachine->addJS("var ");
     }
     $enclosedVariableName = $this->stateMachine->encloseVariable($variableName);
     $this->stateMachine->addJS($enclosedVariableName);
     $this->stateMachine->clearVariableFlags();
     $this->changeToState(CONVERTER_STATE_DEFAULT);
 }
 function processToken($name, $value, $parsedToken)
 {
     if ($value == '$this') {
         $this->stateMachine->addJS("this");
         $this->stateMachine->addVariableFlags(DECLARATION_TYPE_CLASS);
         return;
     }
     $variableName = cVar($value);
     $isClassVariable = $this->stateMachine->variableFlags & DECLARATION_TYPE_CLASS;
     if ($this->stateMachine->variableFlags & DECLARATION_TYPE_STATIC && !($this->stateMachine->variableFlags & DECLARATION_TYPE_CLASS)) {
         $this->stateMachine->addScopedVariable($variableName, $this->stateMachine->variableFlags);
         $scopedName = $this->stateMachine->getVariableNameForScope($variableName, $this->stateMachine->variableFlags);
         $this->stateMachine->addJS("if (typeof " . $scopedName . " == 'undefined')\n ");
     }
     if ($isClassVariable == TRUE && ($name == ")" || $name == ',' || $name == ';')) {
         //keyword 'this' has been passed as a variable e.g.
         //json_encode_object(this)
         //$this->stateMachine->addJS("this)");
         $this->stateMachine->addJS($name);
     } else {
         if ($name == "T_OBJECT_OPERATOR") {
             $this->stateMachine->addJS(".");
         } else {
             if ($name == "T_STRING" || $name == "T_VARIABLE") {
                 $scopedVariableName = $this->stateMachine->getVariableNameForScope($variableName, $this->stateMachine->variableFlags);
                 $enclosedVariableName = $this->stateMachine->encloseVariable($scopedVariableName);
                 $this->stateMachine->addJS($enclosedVariableName);
                 $this->stateMachine->variableFlags = 0;
             } else {
                 throw new \Exception("Unexpected token in state CodeConverterState_TVARIABLEFUNCTION, wasn't expected an [" . $name . "]");
             }
         }
     }
     $this->isClassVariable = FALSE;
     $this->stateMachine->clearVariableFlags();
     $this->changeToState(CONVERTER_STATE_DEFAULT);
 }