├── bin ├── php-to-zephir └── php-to-zephir.php ├── tests ├── PhpToZephir │ └── Tests │ │ ├── CodeCollector │ │ ├── FileCodeCollector │ │ │ ├── test.zep │ │ │ └── GetCodeTest.php │ │ ├── DirectoryCodeCollector │ │ │ ├── myDirTest │ │ │ │ ├── afile.php │ │ │ │ └── recursive │ │ │ │ │ └── recursive.php │ │ │ ├── test.zep │ │ │ └── GetCodeTest.php │ │ └── StringCodeCollector │ │ │ └── GetCodeTest.php │ │ ├── Render │ │ ├── StringRender │ │ │ └── RenderTest.php │ │ └── FileRender │ │ │ └── RenderTest.php │ │ ├── Service │ │ └── CliFactory │ │ │ └── GetInstanceTest.php │ │ ├── Command │ │ ├── Convertactory │ │ │ └── GetInstanceTest.php │ │ └── Convert │ │ │ └── ExecuteTest.php │ │ └── EngineFactory │ │ └── GetInstanceTest.php ├── Converter │ └── Code │ │ ├── Oop │ │ ├── UnkownInterfaceTest.php │ │ ├── InstanceTest.php │ │ ├── StaticPropertyTest.php │ │ ├── DynamicInstanceTest.php │ │ └── AttributeTest.php │ │ ├── Simple │ │ ├── SilentErrorTest.php │ │ ├── StringConcatTest.php │ │ ├── CastTest.php │ │ ├── ReturnStmtTest.php │ │ ├── AnonymeFunctionStmtTest.php │ │ └── SimpleAssignTest.php │ │ ├── StrongType │ │ ├── ReturnStmt │ │ │ ├── UndefinedTypeReturnTest.php │ │ │ └── DefinedInInterfaceReturnTest.php │ │ └── FunctionStmt │ │ │ └── MethodTypeUndefinedTest.php │ │ ├── Condition │ │ ├── TernaryOperatorTest.php │ │ ├── IfStmt │ │ │ ├── IsWithYodaConditionTest.php │ │ │ ├── IfWithVarModificationInLeftTest.php │ │ │ ├── IfWithAssignementArrayDimInConditionTest.php │ │ │ ├── IfWithAssignementArrayDimInCondition │ │ │ │ └── IncrementInArrayDimTest.php │ │ │ └── InstanceOfTest.php │ │ └── SwitchStmt │ │ │ └── SwitchWithEvaluateTest.php │ │ ├── ArrayManipulation │ │ ├── ArrayNestedTest.php │ │ ├── ArrayDimScalarWithAssignLetTest.php │ │ ├── Bug2Test.php │ │ ├── Left │ │ │ ├── ArrayDimLetWithAssignScalarTest.php │ │ │ ├── ArrayDimLeftAssignArrayDimLetTest.php │ │ │ └── ArrayDimLeftWithScalarAssignScalarTest.php │ │ ├── ArrayPlusTest.php │ │ ├── Both │ │ │ └── AssignLeftWithArrayDimLeftRightTest.php │ │ ├── Bug1Test.php │ │ └── DeclareArrayWithAssignInTernaryOperationTest.php │ │ ├── Method │ │ ├── MethodExistTest.php │ │ ├── PregMatchTest.php │ │ ├── CallUserFuncArrayTest.php │ │ ├── AssignInFuncCallTest.php │ │ ├── AssignInMethodCallTest.php │ │ └── UnsetTest.php │ │ ├── Loops │ │ ├── ForStmt │ │ │ ├── ForMinusTest.php │ │ │ ├── ForEqualsTest.php │ │ │ ├── ForWithCountTest.php │ │ │ ├── ForWithMutipleAssignTest.php │ │ │ ├── ForWithoutStmtTest.php │ │ │ ├── ForWithBreakOutsideTest.php │ │ │ ├── ForWithBooleanContinueTest.php │ │ │ └── ForWithIteratorTest.php │ │ ├── ContinueStmtTest.php │ │ ├── ForeachStmt │ │ │ └── SimpleForeachTest.php │ │ └── WhileStmt │ │ │ ├── SimpleWhileTest.php │ │ │ └── ListInWhileTest.php │ │ ├── TryCatch │ │ └── SimpleTryCatchTest.php │ │ ├── FuntionCall │ │ └── FunctionCallWithAssignInsideTest.php │ │ ├── Variable │ │ └── StaticVarTest.php │ │ └── Concat │ │ └── ConcatWithCallFuncWithTmpVarTest.php └── Bootstrap.php ├── src └── PhpToZephir │ ├── Converter │ ├── PrinterCollection.php │ ├── ConverterFactory.php │ ├── Printer │ │ ├── Expr │ │ │ ├── ClonePrinter.php │ │ │ ├── EvalPrinter.php │ │ │ ├── PrintPrinter.php │ │ │ ├── EmptyPrinter.php │ │ │ ├── IssetPrinter.php │ │ │ ├── ExitPrinter.php │ │ │ ├── PreDecPrinter.php │ │ │ ├── ShellExecPrinter.php │ │ │ ├── PostDecPrinter.php │ │ │ ├── UnaryPlusPrinter.php │ │ │ ├── BitwiseNotPrinter.php │ │ │ ├── UnaryMinusPrinter.php │ │ │ ├── BooleanNotPrinter.php │ │ │ ├── Cast │ │ │ │ ├── IntPrinter.php │ │ │ │ ├── BoolPrinter.php │ │ │ │ ├── ArrayPrinter.php │ │ │ │ ├── DoublePrinter.php │ │ │ │ ├── ObjectPrinter.php │ │ │ │ ├── StringPrinter.php │ │ │ │ └── UnsetPrinter.php │ │ │ ├── InstanceofPrinter.php │ │ │ ├── BinaryOp │ │ │ │ ├── DivPrinter.php │ │ │ │ ├── ModPrinter.php │ │ │ │ ├── MulPrinter.php │ │ │ │ ├── PowPrinter.php │ │ │ │ ├── PlusPrinter.php │ │ │ │ ├── EqualPrinter.php │ │ │ │ ├── MinusPrinter.php │ │ │ │ ├── ConcatPrinter.php │ │ │ │ ├── GreaterPrinter.php │ │ │ │ ├── SmallerPrinter.php │ │ │ │ ├── NotEqualPrinter.php │ │ │ │ ├── BitwiseOrPrinter.php │ │ │ │ ├── BooleanOrPrinter.php │ │ │ │ ├── IdenticalPrinter.php │ │ │ │ ├── LogicalOrPrinter.php │ │ │ │ ├── ShiftLeftPrinter.php │ │ │ │ ├── BitwiseAndPrinter.php │ │ │ │ ├── BitwiseXorPrinter.php │ │ │ │ ├── BooleanAndPrinter.php │ │ │ │ ├── LogicalAndPrinter.php │ │ │ │ ├── LogicalXorPrinter.php │ │ │ │ ├── ShiftRightPrinter.php │ │ │ │ ├── NotIdenticalPrinter.php │ │ │ │ ├── GreaterOrEqualPrinter.php │ │ │ │ └── SmallerOrEqualPrinter.php │ │ │ ├── PostIncPrinter.php │ │ │ ├── AssignOp │ │ │ │ ├── PowPrinter.php │ │ │ │ ├── DivPrinter.php │ │ │ │ ├── ModPrinter.php │ │ │ │ ├── MulPrinter.php │ │ │ │ ├── MinusPrinter.php │ │ │ │ ├── ConcatPrinter.php │ │ │ │ ├── ShiftLeftPrinter.php │ │ │ │ ├── BitwiseXorPrinter.php │ │ │ │ ├── ShiftRightPrinter.php │ │ │ │ ├── BitwiseOrPrinter.php │ │ │ │ ├── BitwiseAndPrinter.php │ │ │ │ └── PlusPrinter.php │ │ │ ├── ConstFetchPrinter.php │ │ │ ├── PreIncPrinter.php │ │ │ ├── ClassConstFetchPrinter.php │ │ │ ├── PropertyFetchPrinter.php │ │ │ ├── NewPrinter.php │ │ │ ├── StaticPropertyFetchPrinter.php │ │ │ ├── ErrorSuppressPrinter.php │ │ │ ├── IncludePrinter.php │ │ │ ├── AssignRefPrinter.php │ │ │ ├── ArrayItemPrinter.php │ │ │ ├── YieldPrinter.php │ │ │ ├── StaticCallPrinter.php │ │ │ ├── VariablePrinter.php │ │ │ ├── ClosureUsePrinter.php │ │ │ ├── MethodCallPrinter.php │ │ │ ├── ArrayPrinter.php │ │ │ └── FuncCallPrinter.php │ │ ├── Name │ │ │ ├── RelativePrinter.php │ │ │ └── FullyQualifiedPrinter.php │ │ ├── Scalar │ │ │ ├── MagicConst │ │ │ │ ├── DirPrinter.php │ │ │ │ ├── FilePrinter.php │ │ │ │ ├── LinePrinter.php │ │ │ │ ├── ClassPrinter.php │ │ │ │ ├── MethodPrinter.php │ │ │ │ ├── FunctionPrinter.php │ │ │ │ └── NamespacePrinter.php │ │ │ ├── DNumberPrinter.php │ │ │ ├── LNumberPrinter.php │ │ │ ├── EncapsedPrinter.php │ │ │ └── StringPrinter.php │ │ ├── Stmt │ │ │ ├── EchoPrinter.php │ │ │ ├── ConstPrinter.php │ │ │ ├── GlobalPrinter.php │ │ │ ├── ClassConstPrinter.php │ │ │ ├── TraitPrinter.php │ │ │ ├── TraitUsePrinter.php │ │ │ ├── NamespacePrinter.php │ │ │ ├── DeclarePrinter.php │ │ │ ├── LabelPrinter.php │ │ │ ├── TraitUseAdaptation │ │ │ │ ├── AliasPrinter.php │ │ │ │ └── PrecedencePrinter.php │ │ │ ├── ThrowPrinter.php │ │ │ ├── ElsePrinter.php │ │ │ ├── UsePrinter.php │ │ │ ├── BreakPrinter.php │ │ │ ├── DeclareDeclarePrinter.php │ │ │ ├── ElseIfPrinter.php │ │ │ ├── StaticVarPrinter.php │ │ │ ├── CatchPrinter.php │ │ │ ├── CasePrinter.php │ │ │ ├── PropertyPropertyPrinter.php │ │ │ ├── ContinuePrinter.php │ │ │ ├── ForeachPrinter.php │ │ │ ├── TryCatchPrinter.php │ │ │ ├── FunctionPrinter.php │ │ │ ├── UnsetPrinter.php │ │ │ ├── StaticPrinter.php │ │ │ ├── UseUsePrinter.php │ │ │ ├── DoPrinter.php │ │ │ ├── ReturnPrinter.php │ │ │ ├── PropertyPrinter.php │ │ │ └── WhilePrinter.php │ │ ├── CommaSeparatedPrinter.php │ │ ├── EncapsListPrinter.php │ │ ├── ImplodePrinter.php │ │ ├── VarOrNewExprPrinter.php │ │ ├── PrefixOpPrinter.php │ │ ├── PostfixOpPrinter.php │ │ ├── ArgPrinter.php │ │ ├── InfixOpPrinter.php │ │ ├── NamePrinter.php │ │ ├── ConstPrinter.php │ │ ├── ModifiersPrinter.php │ │ ├── ParamPrinter.php │ │ ├── ObjectPropertyPrinter.php │ │ ├── StmtsPrinter.php │ │ └── PrecPrinter.php │ ├── ClassInformationFactory.php │ ├── SimplePrinter.php │ ├── Manipulator │ │ ├── ArrayDto.php │ │ └── ClassManipulator.php │ └── DispatcherFactory.php │ ├── Render │ ├── RenderInterface.php │ ├── StringRender.php │ └── FileRender.php │ ├── CodeCollector │ ├── CodeCollectorInterface.php │ ├── StringCodeCollector.php │ ├── FileCodeCollector.php │ └── DirectoryCodeCollector.php │ ├── ClassCollectorFactory.php │ ├── EngineFactory.php │ ├── Command │ └── ConvertFactory.php │ ├── Service │ └── CliFactory.php │ ├── CodeValidator.php │ ├── NodeFetcher.php │ └── ReservedWordReplacer.php ├── .travis.yml ├── phpunit.xml ├── LICENSE ├── composer.json └── README.md /bin/php-to-zephir: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | assertEquals('test', $sUT->render(array('zephir' => 'test'))); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/Converter/Code/Oop/UnkownInterfaceTest.php: -------------------------------------------------------------------------------- 1 | assertConvertToZephir($php, null); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/PhpToZephir/Tests/CodeCollector/StringCodeCollector/GetCodeTest.php: -------------------------------------------------------------------------------- 1 | assertEquals(array('myStirng'), $sUT->getCode()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/PhpToZephir/Tests/Service/CliFactory/GetInstanceTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('\Symfony\Component\Console\Application', CliFactory::getInstance(new NullOutput())); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/ClonePrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->p($node->expr); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/EvalPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->p($node->expr).')'; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/PrintPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->p($node->expr); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/EmptyPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->p($node->expr).')'; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Name/RelativePrinter.php: -------------------------------------------------------------------------------- 1 | parts); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/IssetPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pCommaSeparated($node->vars).''; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Scalar/MagicConst/DirPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pCommaSeparated($node->exprs).';'; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Scalar/MagicConst/FilePrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pCommaSeparated($node->consts).';'; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/GlobalPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pCommaSeparated($node->vars).';'; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/PhpToZephir/Tests/CodeCollector/FileCodeCollector/GetCodeTest.php: -------------------------------------------------------------------------------- 1 | assertEquals(array(__DIR__.'/test.zep' => 'this is a test !'), $sUT->getCode()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/ClassInformationFactory.php: -------------------------------------------------------------------------------- 1 | expr ? '('.$this->dispatcher->p($node->expr).')' : ''); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/PreDecPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pPostfixOp('Expr_PreDec', $node->var, '--'); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/ShellExecPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pEncapsList($node->parts, '`').'`'; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Scalar/MagicConst/MethodPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pPostfixOp('Expr_PostDec', $node->var, '--'); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/UnaryPlusPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pPrefixOp('Expr_UnaryPlus', '+', $node->expr); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BitwiseNotPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pPrefixOp('Expr_BitwiseNot', '~', $node->expr); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/UnaryMinusPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pPrefixOp('Expr_UnaryMinus', '-', $node->expr); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Scalar/MagicConst/FunctionPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pCommaSeparated($node->consts).';'; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/PhpToZephir/Tests/Command/Convertactory/GetInstanceTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf( 13 | '\PhpToZephir\Command\Convert', 14 | ConvertFactory::getInstance(new NullOutput()) 15 | ); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Scalar/MagicConst/NamespacePrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pPrefixOp('Expr_BooleanNot', '!(', $node->expr) . ')'; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/TraitPrinter.php: -------------------------------------------------------------------------------- 1 | logger->logNode('trait does not exist in zephir', $node, $this->dispatcher->getMetadata()->getClass()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/Cast/IntPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pPrefixOp('Expr_Cast_Int', '(int) ', $node->expr); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/InstanceofPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_Instanceof', $node->expr, ' instanceof ', $node->class); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/CodeCollector/StringCodeCollector.php: -------------------------------------------------------------------------------- 1 | code = $code; 18 | } 19 | 20 | /** 21 | * @return array 22 | */ 23 | public function getCode() 24 | { 25 | return $this->code; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/DivPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_Div', $node->left, ' / ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/ModPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_Mod', $node->left, ' % ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/MulPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_Mul', $node->left, ' * ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/PowPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_Pow', $node->left, ' ** ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/TraitUsePrinter.php: -------------------------------------------------------------------------------- 1 | logger->logNode('trait does not exist in zephir', $node, $this->dispatcher->getMetadata()->getClass()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/PlusPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_Plus', $node->left, ' + ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/Cast/BoolPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pPrefixOp('Expr_Cast_Bool', '(bool) ', $node->expr); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/NamespacePrinter.php: -------------------------------------------------------------------------------- 1 | name->parts).';'."\n".$this->dispatcher->pStmts($node->stmts, false); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/EqualPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_Equal', $node->left, ' == ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/MinusPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_Minus', $node->left, ' - ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/Cast/ArrayPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pPrefixOp('Expr_Cast_Array', '(array) ', $node->expr); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/PostIncPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pPostfixOp('Expr_PostInc', $node->var, '++'); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/ConcatPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_Concat', $node->left, ' . ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/Cast/DoublePrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pPrefixOp('Expr_Cast_Double', '(double) ', $node->expr); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/Cast/ObjectPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pPrefixOp('Expr_Cast_Object', '(object) ', $node->expr); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/GreaterPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_Greater', $node->left, ' > ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/SmallerPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_Smaller', $node->left, ' < ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/PhpToZephir/Tests/EngineFactory/GetInstanceTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf( 14 | '\PhpToZephir\Engine', 15 | EngineFactory::getInstance( 16 | new Logger(new NullOutput(), false) 17 | ) 18 | ); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/NotEqualPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_NotEqual', $node->left, ' != ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/AssignOp/PowPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_AssignOp_Pow', $node->var, ' **= ', $node->expr); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/BitwiseOrPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_BitwiseOr', $node->left, ' | ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/BooleanOrPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_BooleanOr', $node->left, ' || ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/IdenticalPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_Identical', $node->left, ' === ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/LogicalOrPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_LogicalOr', $node->left, ' or ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/ShiftLeftPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_ShiftLeft', $node->left, ' << ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/DeclarePrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pCommaSeparated($node->declares).') {' 18 | .$this->dispatcher->pStmts($node->stmts)."\n".'}'; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/AssignOp/DivPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_AssignOp_Div', $node->var, ' /= ', $node->expr); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/AssignOp/ModPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_AssignOp_Mod', $node->var, ' %= ', $node->expr); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/AssignOp/MulPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_AssignOp_Mul', $node->var, ' *= ', $node->expr); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/BitwiseAndPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_BitwiseAnd', $node->left, ' & ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/BitwiseXorPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_BitwiseXor', $node->left, ' ^ ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/BooleanAndPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_BooleanAnd', $node->left, ' && ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/LogicalAndPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_LogicalAnd', $node->left, ' and ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/LogicalXorPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_LogicalXor', $node->left, ' xor ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/ShiftRightPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_ShiftRight', $node->left, ' >> ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/AssignOp/MinusPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_AssignOp_Minus', $node->var, ' -= ', $node->expr); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/NotIdenticalPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_NotIdentical', $node->left, ' !== ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/PhpToZephir/Tests/Render/FileRender/RenderTest.php: -------------------------------------------------------------------------------- 1 | getMock('PhpToZephir\FileWriter'); 12 | 13 | $fileWriter->expects($this->once()) 14 | ->method('write') 15 | ->with(array('zephir' => 'test')); 16 | 17 | $sUT = new FileRender($fileWriter); 18 | 19 | $sUT->render(array('zephir' => 'test')); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/AssignOp/ConcatPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_AssignOp_Concat', $node->var, ' .= ', $node->expr); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/CommaSeparatedPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pImplode($nodes, ', '); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/GreaterOrEqualPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_GreaterOrEqual', $node->left, ' >= ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/BinaryOp/SmallerOrEqualPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_BinaryOp_SmallerOrEqual', $node->left, ' <= ', $node->right); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/Cast/StringPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pPrefixOp('Expr_Cast_String', '(string) ', $node->expr); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/LabelPrinter.php: -------------------------------------------------------------------------------- 1 | name.':'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/AssignOp/ShiftLeftPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_AssignOp_ShiftLeft', $node->var, ' <<= ', $node->expr); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/AssignOp/BitwiseXorPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_AssignOp_BitwiseXor', $node->var, ' ^= ', $node->expr); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/AssignOp/ShiftRightPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pInfixOp('Expr_AssignOp_ShiftRight', $node->var, ' >>= ', $node->expr); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/TraitUseAdaptation/AliasPrinter.php: -------------------------------------------------------------------------------- 1 | logger->logNode('trait does not exist in zephir', $node, $this->dispatcher->getMetadata()->getClass()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Scalar/DNumberPrinter.php: -------------------------------------------------------------------------------- 1 | value; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Scalar/LNumberPrinter.php: -------------------------------------------------------------------------------- 1 | value; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/SimplePrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher = $dispatcher; 25 | $this->logger = $logger; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/AssignOp/BitwiseOrPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->p($node->var).' = '.$this->dispatcher->p($node->var).' | '.$this->dispatcher->p($node->expr); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/ThrowPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->p($node->expr).';'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/ElsePrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pStmts($node->stmts)."\n".'}'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/ConstFetchPrinter.php: -------------------------------------------------------------------------------- 1 | name->parts); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/PreIncPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pPostfixOp('Expr_PostInc', $node->var, '++'); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Name/FullyQualifiedPrinter.php: -------------------------------------------------------------------------------- 1 | parts); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/UsePrinter.php: -------------------------------------------------------------------------------- 1 | type === Stmt\Use_::TYPE_FUNCTION ? 'function ' : '') 19 | .($node->type === Stmt\Use_::TYPE_CONSTANT ? 'const ' : '') 20 | .$this->dispatcher->pCommaSeparated($node->uses).';'; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/BreakPrinter.php: -------------------------------------------------------------------------------- 1 | num !== null ? ' '.$this->dispatcher->p($node->num) : '').';'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Scalar/EncapsedPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pEncapsList($node->parts, '"').'"'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/TraitUseAdaptation/PrecedencePrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->p($node->trait).'::'.$node->method 18 | .' insteadof '.$this->dispatcher->pCommaSeparated($node->insteadof).';'; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/DeclareDeclarePrinter.php: -------------------------------------------------------------------------------- 1 | key.' = '.$this->dispatcher->p($node->value); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/Converter/Code/Simple/SilentErrorTest.php: -------------------------------------------------------------------------------- 1 | void 28 | { 29 | unlink("test"); 30 | } 31 | 32 | } 33 | EOT; 34 | $this->assertConvertToZephir($php, $zephir); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/ClassConstFetchPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->p($node->class).'::'.$node->name; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/PhpToZephir/Tests/CodeCollector/DirectoryCodeCollector/GetCodeTest.php: -------------------------------------------------------------------------------- 1 | assertEquals( 14 | array( 15 | __DIR__.'/myDirTest/afile.php' => 'a file', 16 | __DIR__.'/myDirTest/recursive/recursive.php' => 'recursive!', 17 | ), 18 | $sUT->getCode() 19 | ); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/PhpToZephir/CodeCollector/FileCodeCollector.php: -------------------------------------------------------------------------------- 1 | files = $files; 18 | } 19 | 20 | /** 21 | * @return array 22 | */ 23 | public function getCode() 24 | { 25 | $files = array(); 26 | 27 | foreach ($this->files as $file) { 28 | $files[$file] = file_get_contents($file); 29 | } 30 | 31 | return $files; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/ElseIfPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->p($node->cond).' {' 26 | .$this->dispatcher->pStmts($node->stmts)."\n".'}'; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/StaticVarPrinter.php: -------------------------------------------------------------------------------- 1 | name 26 | .(null !== $node->default ? ' = '.$this->dispatcher->p($node->default) : ''); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/PhpToZephir/Render/FileRender.php: -------------------------------------------------------------------------------- 1 | fileWriter = $fileWriter; 20 | } 21 | 22 | /* (non-PHPdoc) 23 | * @see \PhpToZephir\Render\RenderInterface::render() 24 | */ 25 | public function render(array $file) 26 | { 27 | $this->fileWriter->write($file); 28 | 29 | return $file['zephir']; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/PropertyFetchPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pVarOrNewExpr($node->var).'->'.$this->dispatcher->pObjectProperty($node->name); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/CatchPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->p($node->type).', '.$node->var.' {' 26 | .$this->dispatcher->pStmts($node->stmts)."\n".'}'; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/CasePrinter.php: -------------------------------------------------------------------------------- 1 | cond ? 'case '.$this->dispatcher->p($node->cond) : 'default').':' 26 | .$this->dispatcher->pStmts($node->stmts); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/PropertyPropertyPrinter.php: -------------------------------------------------------------------------------- 1 | name.(null !== $node->default ? ' = '.$this->dispatcher->p($node->default) : ''); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/Converter/Code/Oop/InstanceTest.php: -------------------------------------------------------------------------------- 1 | void 28 | { 29 | var myInstance; 30 | 31 | let myInstance = new StdClass(); 32 | } 33 | 34 | } 35 | EOT; 36 | $this->assertConvertToZephir($php, $zephir); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/NewPrinter.php: -------------------------------------------------------------------------------- 1 | class instanceof \PhpParser\Node\Expr\Variable) { 18 | return 'new {'.$this->dispatcher->p($node->class).'}('.$this->dispatcher->pCommaSeparated($node->args).')'; 19 | } 20 | 21 | return 'new '.$this->dispatcher->p($node->class).'('.$this->dispatcher->pCommaSeparated($node->args).')'; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/StaticPropertyFetchPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->p($node->class).'::'.$this->dispatcher->pObjectProperty($node->name); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | sudo : false 3 | php: 4 | - 5.5 5 | - 5.6 6 | - 7.0 7 | 8 | install: 9 | - phpize -v 10 | - composer selfupdate 11 | - composer install --prefer-source 12 | - cd ./vendor/phalcon/zephir/ 13 | - ./unit-tests/ci/before_install.sh 14 | - export LD_LIBRARY_PATH="$TRAVIS_BUILD_DIR/build/lib":$LD_LIBRARY_PATH 15 | - export LIBRARY_PATH="$TRAVIS_BUILD_DIR/build/lib":$LIBRARY_PATH 16 | - export C_INCLUDE_PATH="$TRAVIS_BUILD_DIR/build/include" 17 | - ./install-nosudo -c 18 | - cd ./../../../ 19 | 20 | script: ./vendor/bin/phpunit --coverage-clover coverage.clover 21 | 22 | after_script: 23 | - wget https://scrutinizer-ci.com/ocular.phar 24 | - php ocular.phar code-coverage:upload --format=php-clover coverage.clover 25 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/EncapsListPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->p($element).'}'; 22 | } 23 | } 24 | 25 | return $return; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/ImplodePrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->p($node); 28 | } 29 | 30 | return implode($glue, $pNodes); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/Converter/Code/StrongType/ReturnStmt/UndefinedTypeReturnTest.php: -------------------------------------------------------------------------------- 1 | assertConvertToZephir($php, $zephir); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/Converter/Code/Oop/StaticPropertyTest.php: -------------------------------------------------------------------------------- 1 | void 31 | { 32 | let StaticProperty::x = 1; 33 | } 34 | 35 | } 36 | EOT; 37 | $this->assertConvertToZephir($php, $zephir); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/VarOrNewExprPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->p($node).')'; 28 | } else { 29 | return $this->dispatcher->p($node); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /bin/php-to-zephir.php: -------------------------------------------------------------------------------- 1 | run($input, $output); 23 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/Cast/UnsetPrinter.php: -------------------------------------------------------------------------------- 1 | logger->logIncompatibility( 19 | '(unset) unset cast', 20 | '(unset) does not exist in zephir, remove cast', 21 | $node, 22 | $this->dispatcher->getMetadata()->getClass() 23 | ); 24 | 25 | return $this->dispatcher->pPrefixOp('Expr_Cast_Unset', '', $node->expr); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/Converter/Code/Condition/TernaryOperatorTest.php: -------------------------------------------------------------------------------- 1 | void 29 | { 30 | var tmp; 31 | 32 | let tmp = "Hello ". ( null ? null : "Guest"); 33 | } 34 | 35 | } 36 | EOT; 37 | $this->assertConvertToZephir($php, $zephirExpected); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/ContinuePrinter.php: -------------------------------------------------------------------------------- 1 | num !== null) { 18 | $this->logger->logIncompatibility( 19 | 'continue $number;', 20 | '"continue $number;" no supported in zephir', 21 | $node, 22 | $this->dispatcher->getMetadata()->getFullQualifiedNameClass() 23 | ); 24 | } 25 | 26 | return 'continue;'; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/Converter/Code/ArrayManipulation/ArrayNestedTest.php: -------------------------------------------------------------------------------- 1 | "apple"), array("b" => "ball")); 19 | } 20 | } 21 | EOT; 22 | $zephir = <<<'EOT' 23 | namespace Code\Simple; 24 | 25 | class ArrayNested 26 | { 27 | public function test() -> void 28 | { 29 | var returnn; 30 | 31 | let returnn = [["a" : "apple"], ["b" : "ball"]]; 32 | } 33 | 34 | } 35 | EOT; 36 | $this->assertConvertToZephir($php, $zephir); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/ErrorSuppressPrinter.php: -------------------------------------------------------------------------------- 1 | logger->logIncompatibility( 18 | '(@=) ErrorSuppress', 19 | 'ErrorSuppress is not supported in Zephir (see #906)', 20 | $node, 21 | $this->dispatcher->getMetadata()->getFullQualifiedNameClass() 22 | ); 23 | 24 | return $this->dispatcher->pPrefixOp('Expr_ErrorSuppress', '', $node->expr); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/Converter/Code/Method/MethodExistTest.php: -------------------------------------------------------------------------------- 1 | void 30 | { 31 | var foo; 32 | 33 | let foo = "simpleTest"; 34 | method_exists(this, foo); 35 | } 36 | 37 | } 38 | EOT; 39 | $this->assertConvertToZephir($php, $zephir); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/IncludePrinter.php: -------------------------------------------------------------------------------- 1 | 'include', 19 | Expr\Include_::TYPE_INCLUDE_ONCE => 'include_once', 20 | Expr\Include_::TYPE_REQUIRE => 'require', 21 | Expr\Include_::TYPE_REQUIRE_ONCE => 'require_once', 22 | ); 23 | 24 | return $map[$node->type] . ' ' . $this->dispatcher->p($node->expr); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/Converter/Code/StrongType/FunctionStmt/MethodTypeUndefinedTest.php: -------------------------------------------------------------------------------- 1 | void 28 | { 29 | var test; 30 | 31 | let test = "tutu"; 32 | } 33 | 34 | } 35 | EOT; 36 | $this->assertConvertToZephir($php, $zephir); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/Converter/Code/Loops/ForStmt/ForMinusTest.php: -------------------------------------------------------------------------------- 1 | void 29 | { 30 | var i; 31 | 32 | let i = 0; 33 | for i in range(0, 9) { 34 | echo i; 35 | } 36 | } 37 | 38 | } 39 | EOT; 40 | $this->assertConvertToZephir($php, $zephir); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/Converter/Code/Oop/DynamicInstanceTest.php: -------------------------------------------------------------------------------- 1 | void 30 | { 31 | var myClass, myInstance; 32 | 33 | let myClass = "test"; 34 | let myInstance = new {myClass}(); 35 | } 36 | 37 | } 38 | EOT; 39 | $this->assertConvertToZephir($php, $zephir); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/PrefixOpPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->getPrecedenceMap($type); 25 | 26 | return $operatorString.$this->dispatcher->pPrec($node, $precedence, $associativity, 1); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/ForeachPrinter.php: -------------------------------------------------------------------------------- 1 | keyVar ? $this->dispatcher->p($node->keyVar).', ' : '').$this->dispatcher->p($node->valueVar). 26 | ' in '.$this->dispatcher->p($node->expr).' {'. 27 | $this->dispatcher->pStmts($node->stmts)."\n".'}'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/PostfixOpPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->getPrecedenceMap($type); 25 | 26 | return $this->dispatcher->pPrec($node, $precedence, $associativity, -1).$operatorString; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/Converter/Code/Condition/IfStmt/IsWithYodaConditionTest.php: -------------------------------------------------------------------------------- 1 | void 30 | { 31 | if toto === "tata" { 32 | echo "tata"; 33 | } 34 | } 35 | 36 | } 37 | EOT; 38 | $this->assertConvertToZephir($php, $zephir); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/Converter/Code/Loops/ForStmt/ForEqualsTest.php: -------------------------------------------------------------------------------- 1 | void 29 | { 30 | var i; 31 | 32 | let i = 1; 33 | for i in range(1, 10) { 34 | echo i; 35 | } 36 | } 37 | 38 | } 39 | EOT; 40 | $this->assertConvertToZephir($php, $zephir); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/AssignOp/BitwiseAndPrinter.php: -------------------------------------------------------------------------------- 1 | logger->logIncompatibility( 19 | '(&=) BitwiseAnd', 20 | '(&=) BitwiseAnd does not exist in zephir, assign', 21 | $node, 22 | $this->dispatcher->getMetadata()->getClass() 23 | ); 24 | 25 | return 'let '.$this->dispatcher->pInfixOp('Expr_AssignOp_BitwiseAnd', $node->var, ' = ', $node->expr); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/AssignOp/PlusPrinter.php: -------------------------------------------------------------------------------- 1 | expr instanceof Array_) { 20 | return 'let '.$this->dispatcher->pInfixOp('Expr_AssignOp_Plus', $node->var, ' = this->array_plus(' .$this->dispatcher->p($node->var) . ', ', $node->expr) . ')'; 21 | } else { 22 | return 'let '.$this->dispatcher->pInfixOp('Expr_AssignOp_Plus', $node->var, ' += ', $node->expr); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/TryCatchPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->pStmts($node->stmts)."\n".'}' 26 | .$this->dispatcher->pImplode($node->catches) 27 | .($node->finallyStmts !== null 28 | ? ' finally {'.$this->dispatcher->pStmts($node->finallyStmts)."\n".'}' 29 | : ''); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/ArgPrinter.php: -------------------------------------------------------------------------------- 1 | byRef) { 26 | $this->logger->logIncompatibility( 27 | 'reference', 28 | 'Reference not supported', 29 | $node, 30 | $this->dispatcher->getMetadata()->getClass() 31 | ); 32 | } 33 | 34 | return ($node->unpack ? '...' : '').$this->dispatcher->p($node->value); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/FunctionPrinter.php: -------------------------------------------------------------------------------- 1 | byRef) { 18 | $this->logger->logIncompatibility( 19 | 'reference', 20 | 'Reference not supported', 21 | $node, 22 | $this->dispatcher->getMetadata()->getClass() 23 | ); 24 | } 25 | 26 | return 'function '.$node->name 27 | .'('.$this->dispatcher->pCommaSeparated($node->params).')' 28 | ."\n".'{'.$this->dispatcher->pStmts($node->stmts)."\n".'}'; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/Converter/Code/TryCatch/SimpleTryCatchTest.php: -------------------------------------------------------------------------------- 1 | void 32 | { 33 | var e; 34 | 35 | try { 36 | echo "try"; 37 | } catch Exception, e { 38 | echo "catsh"; 39 | } 40 | } 41 | 42 | } 43 | EOT; 44 | $this->assertConvertToZephir($php, $zephir); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/InfixOpPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher->getPrecedenceMap($type); 24 | 25 | return $this->dispatcher->pPrec($leftNode, $precedence, $associativity, -1) 26 | .$operatorString 27 | .$this->dispatcher->pPrec($rightNode, $precedence, $associativity, 1); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/Converter/Code/Method/PregMatchTest.php: -------------------------------------------------------------------------------- 1 | void 32 | { 33 | var regex, src, matches; 34 | 35 | let regex = ""; 36 | let src = ""; 37 | let matches = ""; 38 | preg_match(regex, src, matches); 39 | } 40 | 41 | } 42 | EOT; 43 | $this->assertConvertToZephir($php, $zephir); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | 14 | 15 | ./src/ 16 | 17 | 18 | 19 | 20 | ./tests/ 21 | 22 | 23 | ./tests/ 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/UnsetPrinter.php: -------------------------------------------------------------------------------- 1 | vars as $var) { 28 | if ($var instanceof Expr\Variable) { 29 | $unset .= 'let '.$this->dispatcher->p($var).' = null;'."\n"; 30 | } else { 31 | $unset .= 'unset '.$this->dispatcher->p($var).';'."\n"; 32 | } 33 | } 34 | 35 | return $unset; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/AssignRefPrinter.php: -------------------------------------------------------------------------------- 1 | logger->logIncompatibility( 26 | '(=&) AssignRef', 27 | '(=&) AssignRef does not exist in zephir, assign', 28 | $node, 29 | $this->dispatcher->getMetadata()->getFullQualifiedNameClass() 30 | ); 31 | 32 | return 'let '.$this->dispatcher->pInfixOp('Expr_AssignRef', $node->var, ' = ', $node->expr); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/PhpToZephir/Command/ConvertFactory.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | namespace PhpToZephir\Command; 12 | 13 | use Symfony\Component\Console\Output\OutputInterface; 14 | use PhpToZephir\EngineFactory; 15 | use PhpToZephir\Render\FileRender; 16 | use PhpToZephir\FileWriter; 17 | 18 | /** 19 | * Convert command. 20 | * 21 | * @author Stéphane Demonchaux 22 | */ 23 | class ConvertFactory 24 | { 25 | /** 26 | * @param OutputInterface $output 27 | * 28 | * @return \PhpToZephir\Command\Convert 29 | */ 30 | public static function getInstance(OutputInterface $output) 31 | { 32 | return new Convert(EngineFactory::getInstance(), new FileRender(new FileWriter()), $output); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/Converter/Code/FuntionCall/FunctionCallWithAssignInsideTest.php: -------------------------------------------------------------------------------- 1 | void 29 | { 30 | var name, test2, test; 31 | 32 | let name = ["toto"]; 33 | let test = implode(",", name); 34 | let test2 = strtolower(test); 35 | } 36 | 37 | } 38 | EOT; 39 | $this->assertConvertToZephir($php, $zephir); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/NamePrinter.php: -------------------------------------------------------------------------------- 1 | reservedWordReplacer = $reservedWordReplacer; 21 | } 22 | 23 | /** 24 | * @return string 25 | */ 26 | public static function getType() 27 | { 28 | return 'pName'; 29 | } 30 | 31 | /** 32 | * @param Name $node 33 | * 34 | * @return Ambigous 35 | */ 36 | public function convert(Name $node) 37 | { 38 | return $this->reservedWordReplacer->replace(implode('\\', $node->parts)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/Converter/Code/Loops/ForStmt/ForWithCountTest.php: -------------------------------------------------------------------------------- 1 | void 31 | { 32 | var myArray, i; 33 | 34 | let myArray = ["test", "2"]; 35 | let i = 0; 36 | for i in range(0, count(myArray)) { 37 | echo i; 38 | } 39 | } 40 | 41 | } 42 | EOT; 43 | $this->assertConvertToZephir($php, $zephir); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/Converter/Code/ArrayManipulation/ArrayDimScalarWithAssignLetTest.php: -------------------------------------------------------------------------------- 1 | 10); 20 | 21 | $myArray[1] = $number++; 22 | } 23 | } 24 | EOT; 25 | $zephir = <<<'EOT' 26 | namespace Code\Simple; 27 | 28 | class ArrayDim 29 | { 30 | public function testArrayDimScalarWithAssignLet() -> void 31 | { 32 | var number, myArray; 33 | 34 | let number = 0; 35 | let myArray = [1 : 10]; 36 | let number++; 37 | let myArray[1] = number; 38 | } 39 | 40 | } 41 | EOT; 42 | $this->assertConvertToZephir($php, $zephir, true); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/ConstPrinter.php: -------------------------------------------------------------------------------- 1 | value instanceof Node\Expr\Array_) { 26 | $this->logger->logNode( 27 | 'Array not supported in const, transform as empty string (see #188)', 28 | $node, 29 | $this->dispatcher->getMetadata()->getFullQualifiedNameClass() 30 | ); 31 | $node->value = new Node\Scalar\String_(''); 32 | } 33 | 34 | return $node->name.' = '.$this->dispatcher->p($node->value); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/ArrayItemPrinter.php: -------------------------------------------------------------------------------- 1 | byRef) { 26 | $this->logger->logIncompatibility( 27 | 'reference', 28 | 'Reference not supported', 29 | $node, 30 | $this->dispatcher->getMetadata()->getClass() 31 | ); 32 | } 33 | 34 | return (null !== $node->key ? $this->dispatcher->p($node->key).' : ' : '') 35 | .$this->dispatcher->p($node->value); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tests/Converter/Code/Loops/ForStmt/ForWithMutipleAssignTest.php: -------------------------------------------------------------------------------- 1 | void 31 | { 32 | var myArray, i, count; 33 | 34 | let myArray = ["test", "2"]; 35 | let i = 0; 36 | let count = count(myArray); 37 | for i in range(0, count) { 38 | echo i; 39 | } 40 | } 41 | 42 | } 43 | EOT; 44 | $this->assertConvertToZephir($php, $zephir); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/Converter/Code/Loops/ContinueStmtTest.php: -------------------------------------------------------------------------------- 1 | void 35 | { 36 | var tests, test; 37 | 38 | let tests = ["im a test"]; 39 | for test in tests { 40 | continue; 41 | } 42 | for test in tests { 43 | continue; 44 | } 45 | } 46 | 47 | } 48 | EOT; 49 | $this->assertConvertToZephir($php, $zephir); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/Converter/Code/Loops/ForStmt/ForWithoutStmtTest.php: -------------------------------------------------------------------------------- 1 | 10) { 20 | break; 21 | } 22 | echo $i; 23 | $i++; 24 | } 25 | } 26 | } 27 | EOT; 28 | $zephir = <<<'EOT' 29 | namespace Code\Loops\ForStmt; 30 | 31 | class ForWithoutStmt 32 | { 33 | public function testSampleFromPhpDoc3() -> void 34 | { 35 | var i; 36 | 37 | let i = 1; 38 | loop { 39 | 40 | if i > 10 { 41 | break; 42 | } 43 | echo i; 44 | let i++; 45 | 46 | } 47 | } 48 | 49 | } 50 | EOT; 51 | $this->assertConvertToZephir($php, $zephir); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /tests/Converter/Code/ArrayManipulation/Bug2Test.php: -------------------------------------------------------------------------------- 1 | 'test'); 22 | 23 | $this->parameters['$' . $parameter['name']] = array($type, ''); 24 | } 25 | } 26 | EOT; 27 | $zephir = <<<'EOT' 28 | namespace Code\ArrayManipulation; 29 | 30 | class Bug2 31 | { 32 | protected parameters = []; 33 | public function test() -> void 34 | { 35 | var type, parameter; 36 | 37 | let type = "test"; 38 | let parameter = ["name" : "test"]; 39 | let this->parameters["$" . parameter["name"]] = [type, ""]; 40 | } 41 | 42 | } 43 | EOT; 44 | $this->assertConvertToZephir($php, $zephir); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/YieldPrinter.php: -------------------------------------------------------------------------------- 1 | logger->logIncompatibility( 18 | 'Yield', 19 | 'Yield does not exist in zephir', 20 | $node, 21 | $this->dispatcher->getMetadata()->getClass() 22 | ); 23 | 24 | if ($node->value === null) { 25 | return 'yield'; 26 | } else { 27 | // this is a bit ugly, but currently there is no way to detect whether the parentheses are necessary 28 | return '(yield ' 29 | .($node->key !== null ? $this->dispatcher->p($node->key).' => ' : '') 30 | .$this->dispatcher->p($node->value) 31 | .')'; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/ModifiersPrinter.php: -------------------------------------------------------------------------------- 1 | void 33 | { 34 | var lineCnt, lineNumber; 35 | 36 | let lineCnt = 0; 37 | let lineNumber = 1; 38 | let lineCnt++; 39 | if lineCnt == lineNumber { 40 | echo "not allowed"; 41 | } 42 | } 43 | 44 | } 45 | EOT; 46 | $this->assertConvertToZephir($php, $zephirExpected); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/StaticPrinter.php: -------------------------------------------------------------------------------- 1 | vars as $var) { 21 | $this->logger->logIncompatibility( 22 | 'Static var', 23 | 'Static var does not exist in Zephir see #941', 24 | $var, 25 | $this->dispatcher->getMetadata()->getFullQualifiedNameClass() 26 | ); 27 | /* @var $var \PhpParser\Node\Stmt\StaticVar */ 28 | if (!empty($var->default)) { 29 | $vars[] = new Expr\Assign(new Expr\Variable($var->name), $var->default); 30 | } 31 | } 32 | 33 | return $this->dispatcher->pStmts($vars); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/Converter/Code/Condition/IfStmt/IfWithAssignementArrayDimInConditionTest.php: -------------------------------------------------------------------------------- 1 | true); 19 | 20 | if ($averylongvariable = $toto[1]) { 21 | echo 'tata'; 22 | } 23 | } 24 | } 25 | EOT; 26 | $zephir = <<<'EOT' 27 | namespace Code\Condition\IfStmt; 28 | 29 | class IfWithAssignementArrayDimInCondition 30 | { 31 | public function test() -> void 32 | { 33 | var toto, averylongvariable; 34 | 35 | let toto = [1 : true]; 36 | let averylongvariable = toto[1]; 37 | if averylongvariable { 38 | echo "tata"; 39 | } 40 | } 41 | 42 | } 43 | EOT; 44 | $this->assertConvertToZephir($php, $zephir); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/Converter/Code/Loops/ForStmt/ForWithBreakOutsideTest.php: -------------------------------------------------------------------------------- 1 | 10) { 19 | break; 20 | } 21 | echo $i; 22 | } 23 | } 24 | } 25 | EOT; 26 | $zephir = <<<'EOT' 27 | namespace Code\Loops\ForStmt; 28 | 29 | class ForWithBreakOutside 30 | { 31 | public function testSampleFromPhpDoc2() -> void 32 | { 33 | var i; 34 | 35 | 36 | let i = 1; 37 | loop { 38 | 39 | if i > 10 { 40 | break; 41 | } 42 | echo i; 43 | 44 | let i++; 45 | } 46 | } 47 | 48 | } 49 | EOT; 50 | $this->assertConvertToZephir($php, $zephir); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Manipulator/ArrayDto.php: -------------------------------------------------------------------------------- 1 | collected[] = $value; 22 | } 23 | 24 | public function setExpr($value) 25 | { 26 | $this->expr = $value; 27 | } 28 | 29 | /** 30 | * @return string 31 | */ 32 | public function getCollected() 33 | { 34 | if (!empty($this->collected)) { 35 | return implode(";\n", $this->collected).";\n"; 36 | } 37 | 38 | return ''; 39 | } 40 | 41 | public function getExpr() 42 | { 43 | return $this->expr; 44 | } 45 | 46 | public function hasCollected() 47 | { 48 | return !empty($this->collected); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/ParamPrinter.php: -------------------------------------------------------------------------------- 1 | byRef) { 26 | $this->logger->logIncompatibility( 27 | 'reference', 28 | 'Reference not supported', 29 | $node, 30 | $this->dispatcher->getMetadata()->getClass() 31 | ); 32 | } 33 | 34 | return ($node->type ? (is_string($node->type) ? $node->type : $this->dispatcher->p($node->type)).' ' : '') 35 | .($node->variadic ? '... ' : '') 36 | .''.$node->name 37 | .($node->default ? ' = '.$this->dispatcher->p($node->default) : '').''; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Stéphane 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/StaticCallPrinter.php: -------------------------------------------------------------------------------- 1 | class instanceof Expr\Variable) ? '{'.$this->dispatcher->p($node->class).'}' : $this->dispatcher->p($node->class)).'::' 26 | .($node->name instanceof Expr 27 | ? ($node->name instanceof Expr\Variable 28 | || $node->name instanceof Expr\ArrayDimFetch 29 | ? $this->dispatcher->p($node->name) 30 | : '{'.$this->dispatcher->p($node->name).'}') 31 | : $node->name) 32 | .'('.$this->dispatcher->pCommaSeparated($node->args).')'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Scalar/StringPrinter.php: -------------------------------------------------------------------------------- 1 | pNoIndent(addcslashes($node->value, '\"\\')).'"'; 28 | } 29 | 30 | /** 31 | * Signals the pretty printer that a string shall not be indented. 32 | * 33 | * @param string $string Not to be indented string 34 | * 35 | * @return string String marked with $this->noIndentToken's. 36 | */ 37 | private function pNoIndent($string) 38 | { 39 | return str_replace("\n", "\n".Dispatcher::noIndentToken, $string); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/Bootstrap.php: -------------------------------------------------------------------------------- 1 | 10); 20 | 21 | $myArray[$number++] = 11; 22 | } 23 | } 24 | EOT; 25 | $zephir = <<<'EOT' 26 | namespace Code\Simple; 27 | 28 | class ArrayDimLetWithAssignScalarTest 29 | { 30 | public function testArrayDimLetWithAssignScalar() -> void 31 | { 32 | var number, myArray, tmpNumber1; 33 | 34 | let number = 0; 35 | let myArray = [1 : 10]; 36 | 37 | let number++; 38 | let tmpNumber1 = number; 39 | 40 | let myArray[tmpNumber1] = 11; 41 | } 42 | 43 | } 44 | EOT; 45 | $this->assertConvertToZephir($php, $zephir, true); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/Converter/Code/Simple/StringConcatTest.php: -------------------------------------------------------------------------------- 1 | assertConvertToZephir($php, $zephir); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "fezfez/php-to-zephir", 3 | "description" : "Transform php code to zephir", 4 | "type" : "library", 5 | "authors" : [{ 6 | "name" : "Stéphane Demonchaux", 7 | "email" : "demonchaux.stephane@gmail.com" 8 | } 9 | ], 10 | "keywords" : [ 11 | "convert php", 12 | "zephir", 13 | "php to zephir", 14 | "code conversion" 15 | ], 16 | "homepage" : "https://github.com/fezfez/php-to-zephir", 17 | "require" : { 18 | "nikic/PHP-Parser" : "1.4.*", 19 | "phpdocumentor/reflection-docblock" : "2.0.*", 20 | "phalcon/zephir" : "0.8.*", 21 | "symfony/console" : "2.7.*" 22 | }, 23 | "require-dev" : { 24 | "phpunit/phpunit" : "4.8.*" 25 | }, 26 | "autoload" : { 27 | "psr-0" : { 28 | "PhpToZephir" : "src/" 29 | } 30 | }, 31 | "support" : { 32 | "source" : "https://github.com/fezfez/php-to-zephir", 33 | "email" : "demonchaux.stephane@gmail.com", 34 | "issues" : "https://github.com/fezfez/php-to-zephir/issues", 35 | "wiki" : "https://github.com/fezfez/php-to-zephir/blob/master/README.md" 36 | }, 37 | "minimum-stability" : "dev", 38 | "prefer-stable" : true, 39 | "bin" : [ 40 | "bin/php-to-zephir" 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /tests/Converter/Code/Loops/ForStmt/ForWithBooleanContinueTest.php: -------------------------------------------------------------------------------- 1 | void 31 | { 32 | var messages, i; 33 | 34 | let messages = []; 35 | 36 | let i = 0; 37 | loop { 38 | if isset messages[i] { 39 | break; 40 | } 41 | 42 | let messages[i] = messages[i]; 43 | 44 | let i++; 45 | } 46 | } 47 | 48 | } 49 | EOT; 50 | $this->assertConvertToZephir($php, $zephir); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/Converter/Code/Loops/ForStmt/ForWithIteratorTest.php: -------------------------------------------------------------------------------- 1 | markTestIncomplete("Support in version 0.3"); 10 | 11 | $php = <<<'EOT' 12 | void 33 | { 34 | var i; 35 | 36 | let i = 1; 37 | loop { 38 | 39 | if i > 10 { 40 | break; 41 | } 42 | echo i; 43 | let i++; 44 | 45 | } 46 | } 47 | 48 | } 49 | EOT; 50 | $this->assertConvertToZephir($php, $zephir); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/Converter/Code/Loops/ForeachStmt/SimpleForeachTest.php: -------------------------------------------------------------------------------- 1 | $myValue) { 24 | echo "my stmt"; 25 | } 26 | } 27 | } 28 | EOT; 29 | $zephir = <<<'EOT' 30 | namespace Code\Loops\ForeachStmt; 31 | 32 | class SimpleForeach 33 | { 34 | public function test() -> void 35 | { 36 | var myArray, myValue, myKey; 37 | 38 | let myArray = ["test", "2"]; 39 | for myValue in myArray { 40 | echo "my stmt"; 41 | } 42 | for myKey, myValue in myArray { 43 | echo "my stmt"; 44 | } 45 | } 46 | 47 | } 48 | EOT; 49 | $this->assertConvertToZephir($php, $zephir); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/Converter/Code/Simple/CastTest.php: -------------------------------------------------------------------------------- 1 | void 34 | { 35 | var maValue; 36 | 37 | let maValue = "1"; 38 | let maValue = (int) maValue; 39 | let maValue = (double) maValue; 40 | let maValue = (string) maValue; 41 | let maValue = (array) maValue; 42 | let maValue = (object) maValue; 43 | let maValue = (bool) maValue; 44 | } 45 | 46 | } 47 | EOT; 48 | $this->assertConvertToZephir($php, $zephir); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tests/Converter/Code/Method/CallUserFuncArrayTest.php: -------------------------------------------------------------------------------- 1 | dispatcher, $method), $arguments); 24 | } 25 | } 26 | EOT; 27 | $zephir = <<<'EOT' 28 | namespace Code\Method; 29 | 30 | class CallUserFuncArray 31 | { 32 | protected dispatcher; 33 | public function simpleTest() 34 | { 35 | var method, arguments, tmpArray679d025e144e01e72d3d2a6e800187cd; 36 | 37 | let method = "test"; 38 | let arguments = []; 39 | let tmpArray679d025e144e01e72d3d2a6e800187cd = [this->dispatcher, method]; 40 | return call_user_func_array(tmpArray679d025e144e01e72d3d2a6e800187cd, arguments); 41 | } 42 | 43 | } 44 | EOT; 45 | $this->assertConvertToZephir($php, $zephir); 46 | } 47 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Php to Zephir 2 | ============= 3 | 4 | [![Build Status](https://travis-ci.org/fezfez/php-to-zephir.svg?branch=master)](https://travis-ci.org/fezfez/php-to-zephir) 5 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/fezfez/php-to-zephir/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/fezfez/php-to-zephir/?branch=master) 6 | [![Code Coverage](https://scrutinizer-ci.com/g/fezfez/php-to-zephir/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/fezfez/php-to-zephir/?branch=master) 7 | 8 | > Convert PHP to Zephir. 9 | 10 | This project is builded on top of nikic/PHP-Parser 11 | 12 | 13 | Install 14 | ======= 15 | 16 | ```bash 17 | composer require fezfez/php-to-zephir 18 | ``` 19 | 20 | 21 | How to use 22 | ==== 23 | 24 | ```bash 25 | vendor/bin/php-to-zephir phpToZephir:convert myDirToConvert 26 | ``` 27 | 28 | It converts all files recursivly to [Zephir](https://github.com/phalcon/zephir) language. 29 | 30 | Issue 31 | ===== 32 | 33 | If you find a bug, please report it by new issue (with tested php code to see error). 34 | 35 | Fatal error :'( 36 | ==== 37 | 38 | If you find a fatal error during converting, add --debug and identify where the fatal error happen. 39 | Then open issue ! 40 | -------------------------------------------------------------------------------- /tests/Converter/Code/ArrayManipulation/Left/ArrayDimLeftAssignArrayDimLetTest.php: -------------------------------------------------------------------------------- 1 | 10, 2 => 11); 20 | 21 | $myArray[$number++] = $myArray[$number++]; 22 | } 23 | } 24 | EOT; 25 | $zephir = <<<'EOT' 26 | namespace Code\Simple; 27 | 28 | class ArrayDim 29 | { 30 | public function testArrayDimLeftAssignArrayDimLet() -> void 31 | { 32 | var number, myArray, tmpNumber1, tmpNumber2; 33 | 34 | let number = 0; 35 | let myArray = [1 : 10, 2 : 11]; 36 | 37 | let number++; 38 | let tmpNumber1 = number; 39 | 40 | 41 | let number++; 42 | let tmpNumber2 = number; 43 | 44 | let myArray[tmpNumber1] = myArray[tmpNumber2]; 45 | } 46 | 47 | } 48 | EOT; 49 | $this->assertConvertToZephir($php, $zephir); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/Converter/Code/ArrayManipulation/ArrayPlusTest.php: -------------------------------------------------------------------------------- 1 | "Closure", "pretty" => "closure"); 20 | } 21 | } 22 | EOT; 23 | $zephir = <<<'EOT' 24 | namespace Code\ArrayManipulation; 25 | 26 | class ArrayPlus 27 | { 28 | public function test() -> void 29 | { 30 | var info; 31 | 32 | let info = ["test"]; 33 | let info = this->array_plus(info, ["type" : "Closure", "pretty" : "closure"]); 34 | } 35 | 36 | private function array_plus(array1, array2) 37 | { 38 | var union, key, value; 39 | let union = array1; 40 | for key, value in array2 { 41 | if false === array_key_exists(key, union) { 42 | let union[key] = value; 43 | } 44 | } 45 | 46 | return union; 47 | } 48 | } 49 | EOT; 50 | $this->assertConvertToZephir($php, $zephir); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/Converter/Code/StrongType/ReturnStmt/DefinedInInterfaceReturnTest.php: -------------------------------------------------------------------------------- 1 | string; 47 | 48 | } 49 | EOT 50 | , 51 | <<<'EOT' 52 | namespace Code\StrongType\ReturnStmt; 53 | 54 | class DefinedInInterfaceReturn implements MyInterface 55 | { 56 | public function test(toto) -> string 57 | { 58 | return toto; 59 | } 60 | 61 | } 62 | EOT 63 | ); 64 | $this->assertConvertToZephir($php, $zephir); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /tests/Converter/Code/Variable/StaticVarTest.php: -------------------------------------------------------------------------------- 1 | void 28 | { 29 | var container; 30 | 31 | 32 | let container = "test"; 33 | } 34 | 35 | } 36 | EOT; 37 | $this->assertConvertToZephir($php, $zephir); 38 | } 39 | 40 | public function testSimple() 41 | { 42 | $php = <<<'EOT' 43 | void 61 | { 62 | var container; 63 | 64 | 65 | } 66 | 67 | } 68 | EOT; 69 | $this->assertConvertToZephir($php, $zephir); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /tests/Converter/Code/Simple/ReturnStmtTest.php: -------------------------------------------------------------------------------- 1 | classExists[$fqcn] = AnnotationRegistry::loadAnnotationClass($fqcn); 19 | return $test = 'fez'; 20 | } 21 | 22 | public function testReturnArray() 23 | { 24 | return ["foo" => "bar"]; 25 | } 26 | } 27 | EOT; 28 | $zephir = <<<'EOT' 29 | namespace Code\Simple; 30 | 31 | class ReturnStmt 32 | { 33 | public function testReturnWithAssign() 34 | { 35 | var test; 36 | 37 | // return $this->classExists[$fqcn] = AnnotationRegistry::loadAnnotationClass($fqcn); 38 | let test = "fez"; 39 | return test; 40 | } 41 | 42 | public function testReturnArray() 43 | { 44 | var tmpArrayf6499d168b352149fb71f58a79c076bd; 45 | 46 | let tmpArrayf6499d168b352149fb71f58a79c076bd = ["foo" : "bar"]; 47 | return tmpArrayf6499d168b352149fb71f58a79c076bd; 48 | } 49 | 50 | } 51 | EOT; 52 | $this->assertConvertToZephir($php, $zephir); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/PhpToZephir/Service/CliFactory.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | namespace PhpToZephir\Service; 12 | 13 | use Symfony\Component\Console\Application; 14 | use Symfony\Component\Console\Helper\QuestionHelper; 15 | use Symfony\Component\Console\Helper\FormatterHelper; 16 | use Symfony\Component\Console\Output\OutputInterface; 17 | use PhpToZephir\Command\ConvertFactory; 18 | 19 | /** 20 | * Create CLI instance. 21 | * 22 | * @author Stéphane Demonchaux 23 | */ 24 | class CliFactory 25 | { 26 | /** 27 | * Create CLI instance. 28 | * 29 | * @return Application 30 | */ 31 | public static function getInstance(OutputInterface $output) 32 | { 33 | $questionHelper = new QuestionHelper(); 34 | $application = new Application('PHP to Zephir Command Line Interface', 'Beta 0.2.1'); 35 | $application->getHelperSet()->set(new FormatterHelper(), 'formatter'); 36 | $application->getHelperSet()->set($questionHelper, 'question'); 37 | 38 | $application->add(ConvertFactory::getInstance($output)); 39 | 40 | return $application; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/Converter/Code/ArrayManipulation/Both/AssignLeftWithArrayDimLeftRightTest.php: -------------------------------------------------------------------------------- 1 | array(2 => 10)); 20 | 21 | $test = $myArray[$number++][$number++]['fezfez'][$number++]; 22 | } 23 | } 24 | EOT; 25 | $zephir = <<<'EOT' 26 | namespace Code\Simple; 27 | 28 | class ArrayDim 29 | { 30 | public function testAssignLeftWithArrayDimLeftRight() -> void 31 | { 32 | var number, myArray, test, tmpNumber1, tmpNumber2, tmpNumber3; 33 | 34 | let number = 0; 35 | let myArray = [1 : [2 : 10]]; 36 | 37 | let number++; 38 | let tmpNumber1 = number; 39 | let number++; 40 | let tmpNumber2 = number; 41 | let number++; 42 | let tmpNumber3 = number; 43 | 44 | let test = myArray[tmpNumber1][tmpNumber2]["fezfez"][tmpNumber3]; 45 | } 46 | 47 | } 48 | EOT; 49 | $this->assertConvertToZephir($php, $zephir, true); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/Converter/Code/Condition/IfStmt/IfWithAssignementArrayDimInCondition/IncrementInArrayDimTest.php: -------------------------------------------------------------------------------- 1 | true); 20 | 21 | if ($averylongvariable = $toto[$i++]) { 22 | echo 'tata'; 23 | } 24 | } 25 | } 26 | EOT; 27 | $zephir = <<<'EOT' 28 | namespace Code\Condition\IfStmt\IfWithAssignementArrayDimInCondition; 29 | 30 | class IncrementInArrayDim 31 | { 32 | public function testIncrementInArrayDim() -> void 33 | { 34 | var i, toto, averylongvariable, tmpI1; 35 | 36 | let i = 0; 37 | let toto = [1 : true]; 38 | 39 | let i++; 40 | let tmpI1 = i; 41 | 42 | let averylongvariable = toto[tmpI1]; 43 | if averylongvariable { 44 | echo "tata"; 45 | } 46 | } 47 | 48 | } 49 | EOT; 50 | $this->assertConvertToZephir($php, $zephir); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/UseUsePrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher = $dispatcher; 33 | $this->logger = $logger; 34 | $this->reservedWordReplacer = $reservedWordReplacer; 35 | } 36 | 37 | public static function getType() 38 | { 39 | return 'pStmt_UseUse'; 40 | } 41 | 42 | public function convert(Stmt\UseUse $node) 43 | { 44 | return $this->dispatcher->p($node->name) 45 | .($node->name->getLast() !== $node->alias ? ' as '.$node->alias : ''); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/Converter/Code/Loops/WhileStmt/SimpleWhileTest.php: -------------------------------------------------------------------------------- 1 | void 39 | { 40 | while (true) { 41 | break; 42 | } 43 | } 44 | 45 | public function whileWithAssign() -> void 46 | { 47 | var pos, input; 48 | 49 | let pos = 0; 50 | let input = "mySuperString"; 51 | let pos = strpos(input, "@", pos); 52 | while (pos !== false) { 53 | echo pos; 54 | let pos = strpos(input, "@", pos); 55 | } 56 | } 57 | 58 | } 59 | EOT; 60 | $this->assertConvertToZephir($php, $zephir); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/PhpToZephir/CodeCollector/DirectoryCodeCollector.php: -------------------------------------------------------------------------------- 1 | directories = $directories; 18 | } 19 | 20 | /** 21 | * @param string $dir 22 | * 23 | * @return \RegexIterator 24 | */ 25 | private function findFiles($dir) 26 | { 27 | $directory = new \RecursiveDirectoryIterator($dir); 28 | $iterator = new \RecursiveIteratorIterator($directory); 29 | $regex = new \RegexIterator($iterator, '/^.+\.php$/i', \RecursiveRegexIterator::GET_MATCH); 30 | 31 | return $regex; 32 | } 33 | 34 | /** 35 | * @return array 36 | */ 37 | public function getCode() 38 | { 39 | $files = array(); 40 | 41 | foreach ($this->directories as $directory) { 42 | foreach ($this->findFiles($directory) as $file) { 43 | if (is_array($file)) { 44 | $file = reset($file); 45 | } 46 | 47 | $files[$file] = file_get_contents($file); 48 | } 49 | } 50 | 51 | return $files; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /tests/Converter/Code/ArrayManipulation/Left/ArrayDimLeftWithScalarAssignScalarTest.php: -------------------------------------------------------------------------------- 1 | array(2 => 10)); 20 | 21 | $myArray[$number++][$number++]['fezfez'][$number++] = $number++; 22 | } 23 | } 24 | EOT; 25 | $zephir = <<<'EOT' 26 | namespace Code\Simple; 27 | 28 | class ArrayDim 29 | { 30 | public function testArrayDimLeftWithScalarAssignScalar() -> void 31 | { 32 | var number, myArray, tmpNumber1, tmpNumber2, tmpNumber3; 33 | 34 | let number = 0; 35 | let myArray = [1 : [2 : 10]]; 36 | 37 | let number++; 38 | let tmpNumber1 = number; 39 | let number++; 40 | let tmpNumber2 = number; 41 | let number++; 42 | let tmpNumber3 = number; 43 | 44 | let number++; 45 | let myArray[tmpNumber1][tmpNumber2]["fezfez"][tmpNumber3] = number; 46 | } 47 | 48 | } 49 | EOT; 50 | $this->assertConvertToZephir($php, $zephir, true); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/Converter/Code/ArrayManipulation/Bug1Test.php: -------------------------------------------------------------------------------- 1 | scopedServices[$this->scopes[$name]])) { 26 | throw new Exception(sprintf('The parent scope "%s" must be active when entering this scope.', $this->scopes[$name])); 27 | } 28 | } 29 | } 30 | EOT; 31 | $zephir = <<<'EOT' 32 | namespace Code\ArrayManipulation; 33 | 34 | class Bug1 35 | { 36 | const SCOPE_CONTAINER = ""; 37 | protected scopes = []; 38 | protected scopedServices = []; 39 | public function test() -> void 40 | { 41 | var name; 42 | 43 | let name = "test"; 44 | if !(isset this->scopedServices[this->scopes[name]]) { 45 | throw new Exception(sprintf("The parent scope \"%s\" must be active when entering this scope.", this->scopes[name])); 46 | } 47 | } 48 | 49 | } 50 | EOT; 51 | $this->assertConvertToZephir($php, $zephir); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/PhpToZephir/CodeValidator.php: -------------------------------------------------------------------------------- 1 | set('namespace', strtolower($namespace)); 32 | $config->set('silent', true); 33 | 34 | if (is_dir('ext')) { 35 | $cleanCommand->execute($config, new ZephirLogger($config)); 36 | } 37 | $generateCommand->execute($config, new ZephirLogger($config)); 38 | } catch (Exception $e) { 39 | chdir($currentDir); 40 | throw new \Exception(sprintf('Error on %s', $e->getMessage())); 41 | } 42 | 43 | chdir($currentDir); 44 | 45 | return true; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/ObjectPropertyPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher = $dispatcher; 33 | $this->logger = $logger; 34 | $this->reservedWordReplacer = $reservedWordReplacer; 35 | } 36 | 37 | public static function getType() 38 | { 39 | return 'pObjectProperty'; 40 | } 41 | 42 | public function convert($node) 43 | { 44 | if ($node instanceof Expr) { 45 | return '{'.$this->dispatcher->p($node).'}'; 46 | } else { 47 | return $this->reservedWordReplacer->replace($node); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/DoPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher = $dispatcher; 32 | $this->logger = $logger; 33 | $this->assignManipulator = $assignManipulator; 34 | } 35 | 36 | public static function getType() 37 | { 38 | return 'pStmt_Do'; 39 | } 40 | 41 | public function convert(Stmt\Do_ $node) 42 | { 43 | $condition = clone $node; 44 | $collected = $this->assignManipulator->collectAssignInCondition($condition->cond); 45 | $node->cond = $this->assignManipulator->transformAssignInConditionTest($node->cond); 46 | 47 | return 'do {'.$this->dispatcher->pStmts($node->stmts).$collected->getCollected()."\n" 48 | .'} while ('.$this->dispatcher->p($node->cond).');'; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tests/Converter/Code/Simple/AnonymeFunctionStmtTest.php: -------------------------------------------------------------------------------- 1 | test('bar'); 25 | 26 | $anonyme("foor"); 27 | } 28 | } 29 | 30 | EOT; 31 | $zephir = array( 32 | <<<'EOT' 33 | namespace Code\Simple; 34 | 35 | class AnonymeFunctionStmt 36 | { 37 | public function test(test) 38 | { 39 | return new AnonymeFunctionStmttestClosureOne(test); 40 | } 41 | 42 | public function testIt() -> void 43 | { 44 | var anonyme; 45 | 46 | let anonyme = this->test("bar"); 47 | {anonyme}("foor"); 48 | } 49 | 50 | } 51 | EOT 52 | , 53 | <<<'EOT' 54 | namespace Code\Simple; 55 | 56 | class AnonymeFunctionStmttestClosureZero 57 | { 58 | private test; 59 | 60 | public function __construct(test) 61 | { 62 | let this->test = test; 63 | 64 | } 65 | 66 | public function __invoke(tutu) 67 | { 68 | echo tutu . this->test; 69 | } 70 | } 71 | 72 | EOT 73 | ); 74 | $this->assertConvertToZephir($php, $zephir); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/DispatcherFactory.php: -------------------------------------------------------------------------------- 1 | offsetSet($className::getType(), $className); 43 | } 44 | 45 | return new Dispatcher( 46 | $classes, 47 | include __DIR__.'/PrecedenceMap.php' 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/VariablePrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher = $dispatcher; 33 | $this->logger = $logger; 34 | $this->reservedWordReplacer = $reservedWordReplacer; 35 | } 36 | 37 | /** 38 | * @return string 39 | */ 40 | public static function getType() 41 | { 42 | return 'pExpr_Variable'; 43 | } 44 | 45 | /** 46 | * @param Expr\Variable $node 47 | * 48 | * @return string 49 | */ 50 | public function convert(Expr\Variable $node) 51 | { 52 | if ($node->name instanceof Expr) { 53 | return '{'.$this->dispatcher->p($node->name).'}'; 54 | } else { 55 | return ''.$this->reservedWordReplacer->replace($node->name); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tests/Converter/Code/ArrayManipulation/DeclareArrayWithAssignInTernaryOperationTest.php: -------------------------------------------------------------------------------- 1 | null, 30 | 'has_constructor' => (null !== $constructor = $this->getConstructor()) && $this->getNumberOfParameters() > 0, 31 | ); 32 | } 33 | } 34 | EOT; 35 | $zephir = <<<'EOT' 36 | namespace Code\Simple; 37 | 38 | class ArrayDim 39 | { 40 | protected function getConstructor() 41 | { 42 | return; 43 | } 44 | 45 | protected function getNumberOfParameters() 46 | { 47 | return 5; 48 | } 49 | 50 | public function declareArrayWithAssignInTernaryOperation() -> void 51 | { 52 | var metadata, constructor; 53 | 54 | let constructor = this->getConstructor(); 55 | let metadata = ["default_property" : null, "has_constructor" : constructor !== null && this->getNumberOfParameters() > 0]; 56 | } 57 | 58 | } 59 | EOT; 60 | $this->assertConvertToZephir($php, $zephir, true); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /tests/Converter/Code/Loops/WhileStmt/ListInWhileTest.php: -------------------------------------------------------------------------------- 1 | void 33 | { 34 | var idMap, params, columnNames, fieldName, value, tmpListFieldNameValue; 35 | 36 | let idMap = [["test", "test2"]]; 37 | let params = []; 38 | let columnNames = []; 39 | let tmpListFieldNameValue = each(idMap); 40 | let fieldName = tmpListFieldNameValue[0]; 41 | let value = tmpListFieldNameValue[1]; 42 | while (tmpListFieldNameValue) { 43 | let params[] = value; 44 | let columnNames[] = fieldName; 45 | let tmpListFieldNameValue = each(idMap); 46 | let fieldName = tmpListFieldNameValue[0]; 47 | let value = tmpListFieldNameValue[1]; 48 | } 49 | } 50 | 51 | } 52 | EOT; 53 | $this->assertConvertToZephir($php, $zephir); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tests/Converter/Code/Condition/SwitchStmt/SwitchWithEvaluateTest.php: -------------------------------------------------------------------------------- 1 | void 43 | { 44 | switch (toto) { 45 | case "{": 46 | echo "array"; 47 | break; 48 | case "]": 49 | echo "bool"; 50 | break; 51 | case "|": 52 | case "-": 53 | case "5": 54 | echo "filesysteme"; 55 | break; 56 | default: 57 | echo "what do you mean ?"; 58 | break; 59 | } 60 | } 61 | 62 | } 63 | EOT; 64 | $this->assertConvertToZephir($php, $zephir); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/StmtsPrinter.php: -------------------------------------------------------------------------------- 1 | pComments($node->getAttribute('comments', array())) 31 | .$this->dispatcher->p($node) 32 | .($node instanceof Expr ? ';' : ''); 33 | } 34 | 35 | if ($indent) { 36 | return preg_replace('~\n(?!$|'.Dispatcher::noIndentToken.')~', "\n ", $result); 37 | } else { 38 | return $result; 39 | } 40 | } 41 | 42 | /** 43 | * @param array $comments 44 | * 45 | * @return string 46 | */ 47 | private function pComments(array $comments) 48 | { 49 | $result = ''; 50 | 51 | foreach ($comments as $comment) { 52 | $result .= $comment->getReformattedText()."\n"; 53 | } 54 | 55 | return $result; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/ReturnPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher = $dispatcher; 33 | $this->logger = $logger; 34 | $this->assignManipulator = $assignManipulator; 35 | } 36 | 37 | /** 38 | * @return string 39 | */ 40 | public static function getType() 41 | { 42 | return 'pStmt_Return'; 43 | } 44 | 45 | /** 46 | * @param Stmt\Return_ $node 47 | * 48 | * @return string 49 | */ 50 | public function convert(Stmt\Return_ $node) 51 | { 52 | $collected = $this->assignManipulator->collectAssignInCondition($node->expr); 53 | $node->expr = $this->assignManipulator->transformAssignInConditionTest($node->expr); 54 | 55 | return $collected->getCollected().'return'.(null !== $node->expr ? ' '.$this->dispatcher->p($node->expr) : '').';'; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/PrecPrinter.php: -------------------------------------------------------------------------------- 1 | getType(); 30 | if ($this->dispatcher->issetPrecedenceMap($type) === true) { 31 | $childPrecedences = $this->dispatcher->getPrecedenceMap($type); 32 | $childPrecedence = $childPrecedences[0]; 33 | if ($childPrecedence > $parentPrecedence 34 | || ($parentPrecedence == $childPrecedence && $parentAssociativity != $childPosition) 35 | ) { 36 | return '('.$this->dispatcher->{'p'.$type}($node).')'; 37 | } 38 | } 39 | 40 | return $this->dispatcher->{'p'.$type}($node); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/PropertyPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher = $dispatcher; 34 | $this->logger = $logger; 35 | $this->reservedWordReplacer = $reservedWordReplacer; 36 | } 37 | /** 38 | * @return string 39 | */ 40 | public static function getType() 41 | { 42 | return 'pStmt_Property'; 43 | } 44 | 45 | /** 46 | * @param Stmt\Property $node 47 | * 48 | * @return string 49 | */ 50 | public function convert(Stmt\Property $node) 51 | { 52 | foreach ($node->props as $key => $prop) { 53 | $prop->name = $this->reservedWordReplacer->replace($prop->name); 54 | $node->props[$key] = $prop; 55 | } 56 | 57 | return $this->dispatcher->pModifiers($node->type).$this->dispatcher->pCommaSeparated($node->props).';'; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Stmt/WhilePrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher = $dispatcher; 33 | $this->logger = $logger; 34 | $this->assignManipulator = $assignManipulator; 35 | } 36 | 37 | /** 38 | * @return string 39 | */ 40 | public static function getType() 41 | { 42 | return 'pStmt_While'; 43 | } 44 | 45 | /** 46 | * @param Stmt\While_ $node 47 | * 48 | * @return string 49 | */ 50 | public function convert(Stmt\While_ $node) 51 | { 52 | $collected = $this->assignManipulator->collectAssignInCondition($node->cond); 53 | $node->cond = $this->assignManipulator->transformAssignInConditionTest($node->cond); 54 | 55 | return $collected->getCollected().'while ('.$this->dispatcher->p($node->cond).') {' 56 | .$this->dispatcher->pStmts($node->stmts)."\n".$collected->getCollected().'}'; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/ClosureUsePrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher = $dispatcher; 33 | $this->logger = $logger; 34 | $this->reservedWordReplacer = $reservedWordReplacer; 35 | } 36 | 37 | public static function getType() 38 | { 39 | return 'pExpr_ClosureUse'; 40 | } 41 | 42 | /** 43 | * @param Expr\ClosureUse $node 44 | * 45 | * @return string 46 | */ 47 | public function convert(Expr\ClosureUse $node) 48 | { 49 | if ($node->byRef) { 50 | $this->logger->logNode( 51 | 'Zephir not support reference parameters for now. Stay tuned for https://github.com/phalcon/zephir/issues/203', 52 | $node, 53 | $this->dispatcher->getMetadata()->getClass() 54 | ); 55 | } 56 | 57 | return $this->reservedWordReplacer->replace($node->var); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /tests/Converter/Code/Condition/IfStmt/InstanceOfTest.php: -------------------------------------------------------------------------------- 1 | void 31 | { 32 | var listener; 33 | 34 | let listener = ""; 35 | if !(listener instanceof WrappedListener) { 36 | echo "tata"; 37 | } 38 | } 39 | 40 | } 41 | EOT; 42 | $this->assertConvertToZephir($php, $zephir); 43 | } 44 | 45 | public function testConvertingPositive() 46 | { 47 | $php = <<<'EOT' 48 | void 69 | { 70 | var listener; 71 | 72 | let listener = ""; 73 | if listener instanceof WrappedListener { 74 | echo "tata"; 75 | } 76 | } 77 | 78 | } 79 | EOT; 80 | $this->assertConvertToZephir($php, $zephir); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /tests/Converter/Code/Concat/ConcatWithCallFuncWithTmpVarTest.php: -------------------------------------------------------------------------------- 1 | void 28 | { 29 | var event, id, test; 30 | 31 | let id = "test"; 32 | let test = "test"; 33 | let event = "test" . sprintf("%s", id) . sprintf("%s", test); 34 | } 35 | 36 | } 37 | EOT; 38 | $this->assertConvertToZephir($php, $zephir); 39 | } 40 | 41 | public function tetConvertingOneConcatWithAssign() 42 | { 43 | $php = <<<'EOT' 44 | void 62 | { 63 | var event, id; 64 | 65 | let id = "test"; 66 | let event = "test" . sprintf("%s", id); 67 | } 68 | 69 | } 70 | EOT; 71 | $this->assertConvertToZephir($php, $zephir); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/MethodCallPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher = $dispatcher; 33 | $this->logger = $logger; 34 | $this->assignManipulator = $assignManipulator; 35 | } 36 | 37 | /** 38 | * @return string 39 | */ 40 | public static function getType() 41 | { 42 | return 'pExpr_MethodCall'; 43 | } 44 | 45 | /** 46 | * @param Expr\MethodCall $node 47 | * 48 | * @return string 49 | */ 50 | public function convert(Expr\MethodCall $node) 51 | { 52 | $collected = $this->assignManipulator->collectAssignInCondition($node->args); 53 | $node->args = $this->assignManipulator->transformAssignInConditionTest($node->args); 54 | 55 | return $collected->getCollected() . 56 | $this->dispatcher->pVarOrNewExpr($node->var).'->'.$this->dispatcher->pObjectProperty($node->name) 57 | .'('.$this->dispatcher->pCommaSeparated($node->args).')'; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/PhpToZephir/NodeFetcher.php: -------------------------------------------------------------------------------- 1 | getSubNodeNames() as $subNodeName) { 20 | $parentClass[] = $this->getParentClass($nodesCollection); 21 | $nodes = $this->fetch($nodesCollection->$subNodeName, $nodes, $parentClass); 22 | } 23 | } elseif (is_array($nodesCollection) === true) { 24 | $nodes = $this->fetch($nodesCollection, $nodes, $parentClass, false); 25 | } 26 | 27 | return $nodes; 28 | } 29 | 30 | private function fetch($nodeToFetch, $nodes, $parentClass, $addSelf = false) 31 | { 32 | if (is_array($nodeToFetch) === false) { 33 | $nodeToFetch = array($nodeToFetch); 34 | } 35 | 36 | foreach ($nodeToFetch as &$node) { 37 | $nodes[] = array('node' => $node, 'parentClass' => $parentClass); 38 | if ($addSelf === true) { 39 | $parentClass[] = $this->getParentClass($node); 40 | } 41 | $nodes = $this->foreachNodes($node, $nodes, $parentClass); 42 | } 43 | 44 | return $nodes; 45 | } 46 | 47 | /** 48 | * @param mixed $node 49 | * @return string 50 | */ 51 | private function getParentClass($node) 52 | { 53 | return is_object($node) ? get_class($node) : ''; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/PhpToZephir/ReservedWordReplacer.php: -------------------------------------------------------------------------------- 1 | 'inlinee', 15 | 'Inline' => 'Inlinee', 16 | 'array' => 'myArray', 17 | 'class' => 'classs', 18 | 'var' => 'varr', 19 | 'bool' => 'booll', 20 | 'namespace' => 'namespacee', 21 | 'const' => 'constt', 22 | 'enum' => 'enumm', 23 | 'interface' => 'interfacee', 24 | 'loop' => 'loopp', 25 | 'for' => 'forr', 26 | 'foreach' => 'foreachh', 27 | 'if' => 'iff', 28 | 'elseif' => 'elseiff', 29 | 'else' => 'elsee', 30 | 'function' => 'functionn', 31 | 'private' => 'privatee', 32 | 'protected' => 'protectedd', 33 | 'public' => 'publicc', 34 | 'boolean' => 'booleann', 35 | 'return' => 'returnn', 36 | 'abstract' => 'abstractt', 37 | 'resource' => 'resourcee', 38 | 'callable' => 'callablee', 39 | 'string' => 'stringg', 40 | 'float' => 'floatt', 41 | 'int' => 'intt', 42 | 'internal' => 'internall', 43 | 'deprecated' => 'deprecatedd' 44 | ); 45 | 46 | foreach ($reservedWord as $word => $replacement) { 47 | if ($string == $word) { 48 | $string = $replacement; 49 | break; 50 | } 51 | } 52 | 53 | if (ctype_upper($string)) { 54 | $string = strtolower($string); 55 | } 56 | 57 | return $string; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /tests/Converter/Code/Oop/AttributeTest.php: -------------------------------------------------------------------------------- 1 | publicAttr; 29 | $test = $this->protectedAttr; 30 | $test = $this->privateAttr; 31 | 32 | $test = self::publicStaticAttr; 33 | $test = self::protectedStaticAttr; 34 | $test = self::privateStaticAttr; 35 | 36 | $test = self::MY_CONST; 37 | } 38 | } 39 | EOT; 40 | $zephir = <<<'EOT' 41 | namespace Code\Oop; 42 | 43 | class Attribute 44 | { 45 | public publicAttr = []; 46 | protected protectedAttr = []; 47 | protected privateAttr = []; 48 | public static publicStaticAttr = []; 49 | protected static protectedStaticAttr = []; 50 | protected static privateStaticAttr = []; 51 | const MY_CONST = ""; 52 | public function test() -> void 53 | { 54 | var test; 55 | 56 | let test = this->publicAttr; 57 | let test = this->protectedAttr; 58 | let test = this->privateAttr; 59 | let test = self::publicStaticAttr; 60 | let test = self::protectedStaticAttr; 61 | let test = self::privateStaticAttr; 62 | let test = self::MY_CONST; 63 | } 64 | 65 | } 66 | EOT; 67 | $this->assertConvertToZephir($php, $zephir); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/Converter/Code/Simple/SimpleAssignTest.php: -------------------------------------------------------------------------------- 1 | void 49 | { 50 | var myString, myNumber, result, superResult; 51 | 52 | let myString = "foo"; 53 | let myString .= "bar"; 54 | let myString = "test"; 55 | let myNumber = 1; 56 | let myNumber += 2; 57 | let myNumber -= 1; 58 | let myNumber *= 2; 59 | let myNumber /= 2; 60 | let myNumber %= 2; 61 | let myNumber++; 62 | let myNumber++; 63 | let myNumber--; 64 | let myNumber--; 65 | let result = 1 + myNumber; 66 | let result = 1 * myNumber; 67 | let result = 1 / myNumber; 68 | let result = 1 % myNumber; 69 | let superResult = result . myNumber; 70 | } 71 | 72 | } 73 | EOT; 74 | $this->assertConvertToZephir($php, $zephir); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/ArrayPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher = $dispatcher; 33 | $this->logger = $logger; 34 | $this->assignManipulator = $assignManipulator; 35 | } 36 | 37 | /** 38 | * @return string 39 | */ 40 | public static function getType() 41 | { 42 | return 'pExpr_Array'; 43 | } 44 | 45 | /** 46 | * @param Expr\Array_ $node 47 | * @param bool $returnAsArray 48 | * 49 | * @return string|array 50 | */ 51 | public function convert(Expr\Array_ $node, $returnAsArray = false) 52 | { 53 | $collected = $this->assignManipulator->collectAssignInCondition($node->items); 54 | $node->items = $this->assignManipulator->transformAssignInConditionTest($node->items); 55 | 56 | $collected->setExpr('['.$this->dispatcher->pCommaSeparated($node->items).']'); 57 | 58 | if ($returnAsArray === true) { 59 | return $collected; 60 | } else { 61 | return $collected->getCollected().$collected->getExpr(); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Printer/Expr/FuncCallPrinter.php: -------------------------------------------------------------------------------- 1 | dispatcher = $dispatcher; 33 | $this->logger = $logger; 34 | $this->assignManipulator = $assignManipulator; 35 | } 36 | /** 37 | * @return string 38 | */ 39 | public static function getType() 40 | { 41 | return 'pExpr_FuncCall'; 42 | } 43 | 44 | /** 45 | * @param Expr\FuncCall $node 46 | * 47 | * @return string 48 | */ 49 | public function convert(Expr\FuncCall $node) 50 | { 51 | $collected = $this->assignManipulator->collectAssignInCondition($node->args); 52 | $node->args = $this->assignManipulator->transformAssignInConditionTest($node->args); 53 | 54 | if ($node->name instanceof Expr\Variable) { 55 | $instanciation = '{'.$this->dispatcher->p($node->name).'}'; 56 | } else { 57 | $instanciation = $this->dispatcher->p($node->name); 58 | } 59 | 60 | return $collected->getCollected() . $instanciation . '('.$this->dispatcher->pCommaSeparated($node->args).')'; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/PhpToZephir/Converter/Manipulator/ClassManipulator.php: -------------------------------------------------------------------------------- 1 | reservedWordReplacer = $reservedWordReplacer; 24 | } 25 | 26 | /** 27 | * @param Node\Name $node 28 | * @param ClassMetadata $metadata 29 | * @param array $classCollected 30 | * 31 | * @return string 32 | */ 33 | public function findRightClass(Node\Name $node, ClassMetadata $metadata, array $classCollected = array()) 34 | { 35 | $class = implode('\\', $node->parts); 36 | $lastPartsClass = array_map(function ($value) { return substr(strrchr($value, '\\'), 1); }, $classCollected); 37 | 38 | $class = $this->reservedWordReplacer->replace($class); 39 | 40 | if (in_array($class, $classCollected)) { 41 | return '\\'.$class; 42 | } elseif (array_key_exists($class, $metadata->getClassesAlias())) { 43 | $alias = $metadata->getClassesAlias(); 44 | 45 | return '\\'.$alias[$class]; 46 | } elseif (false !== $key = array_search($class, $lastPartsClass)) { 47 | return '\\'.$classCollected[$key]; 48 | } elseif (false !== $key = array_search($metadata->getNamespace().'\\'.$class, $classCollected)) { 49 | return '\\'.$classCollected[$key]; 50 | } else { 51 | return $class; 52 | } 53 | } 54 | 55 | public function registerClassImplements(Stmt\Class_ $node) 56 | { 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tests/Converter/Code/Method/AssignInFuncCallTest.php: -------------------------------------------------------------------------------- 1 | void 34 | { 35 | var argument, defId, id; 36 | 37 | let argument = "test"; 38 | let id = argument; 39 | let defId = sprintf("%s", id); 40 | } 41 | 42 | public function getDefinitionId(id) 43 | { 44 | return id; 45 | } 46 | 47 | } 48 | EOT; 49 | $this->assertConvertToZephir($php, $zephir); 50 | } 51 | 52 | public function testSimple() 53 | { 54 | $php = <<<'EOT' 55 | void 79 | { 80 | var argument, id; 81 | 82 | let argument = "test"; 83 | let id = argument; 84 | sprintf("%s", id); 85 | } 86 | 87 | public function getDefinitionId(id) 88 | { 89 | return id; 90 | } 91 | 92 | } 93 | EOT; 94 | $this->assertConvertToZephir($php, $zephir); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /tests/PhpToZephir/Tests/Command/Convert/ExecuteTest.php: -------------------------------------------------------------------------------- 1 | setExpectedException('\InvalidArgumentException', '"not" is not a file or a directory'); 25 | 26 | $sUT->execute(new ArrayInput(array('source' => 'not'), $sUT->getDefinition()), new NullOutput()); 27 | } 28 | 29 | public function testOk() 30 | { 31 | $engine = $this->getMockBuilder('\PhpToZephir\Engine') 32 | ->disableOriginalConstructor() 33 | ->getMock(); 34 | 35 | $fileRender = $this->getMockBuilder('\PhpToZephir\Render\FileRender') 36 | ->disableOriginalConstructor() 37 | ->getMock(); 38 | 39 | $sUT = new Convert( 40 | $engine, 41 | $fileRender, 42 | new NullOutput() 43 | ); 44 | 45 | $engine->expects($this->once()) 46 | ->method('convert') 47 | ->with( 48 | new DirectoryCodeCollector(array(__DIR__)), 49 | new Logger(new NullOutput(), null), 50 | null 51 | ) 52 | ->willReturn(array(array('myReturn'))); 53 | 54 | $fileRender->expects($this->once()) 55 | ->method('render') 56 | ->with(array('myReturn')); 57 | 58 | $sUT->execute(new ArrayInput(array('source' => __DIR__), $sUT->getDefinition()), new NullOutput()); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /tests/Converter/Code/Method/AssignInMethodCallTest.php: -------------------------------------------------------------------------------- 1 | getDefinitionId($id = $argument); 20 | } 21 | 22 | public function getDefinitionId($id) 23 | { 24 | return $id; 25 | } 26 | } 27 | EOT; 28 | $zephir = <<<'EOT' 29 | namespace Code\Method; 30 | 31 | class AssignInMethodCall 32 | { 33 | public function simpleTest() -> void 34 | { 35 | var argument, defId, id; 36 | 37 | let argument = "test"; 38 | let id = argument; 39 | let defId = this->getDefinitionId(id); 40 | } 41 | 42 | public function getDefinitionId(id) 43 | { 44 | return id; 45 | } 46 | 47 | } 48 | EOT; 49 | $this->assertConvertToZephir($php, $zephir); 50 | } 51 | 52 | public function testSimple() 53 | { 54 | $php = <<<'EOT' 55 | getDefinitionId($id = $argument); 65 | } 66 | 67 | public function getDefinitionId($id) 68 | { 69 | return $id; 70 | } 71 | } 72 | EOT; 73 | $zephir = <<<'EOT' 74 | namespace Code\Method; 75 | 76 | class AssignInMethodCall 77 | { 78 | public function simpleTest() -> void 79 | { 80 | var argument, id; 81 | 82 | let argument = "test"; 83 | let id = argument; 84 | this->getDefinitionId(id); 85 | } 86 | 87 | public function getDefinitionId(id) 88 | { 89 | return id; 90 | } 91 | 92 | } 93 | EOT; 94 | $this->assertConvertToZephir($php, $zephir); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /tests/Converter/Code/Method/UnsetTest.php: -------------------------------------------------------------------------------- 1 | void 30 | { 31 | var foo; 32 | 33 | let foo = "simpleTest"; 34 | let foo = null; 35 | 36 | } 37 | 38 | } 39 | EOT; 40 | $this->assertConvertToZephir($php, $zephir); 41 | } 42 | 43 | public function testOnArrayAccess() 44 | { 45 | $php = <<<'EOT' 46 | void 66 | { 67 | var foo; 68 | 69 | let foo = ["simpleTest"]; 70 | unset foo["simpleTest"]; 71 | 72 | } 73 | 74 | } 75 | EOT; 76 | $this->assertConvertToZephir($php, $zephir); 77 | } 78 | 79 | public function testOnPropertyAccess() 80 | { 81 | $php = <<<'EOT' 82 | foo); 92 | } 93 | } 94 | EOT; 95 | $zephir = <<<'EOT' 96 | namespace Code\Method; 97 | 98 | class TestUnset 99 | { 100 | public foo; 101 | public function simpleTest() -> void 102 | { 103 | unset this->foo; 104 | 105 | } 106 | 107 | } 108 | EOT; 109 | $this->assertConvertToZephir($php, $zephir); 110 | } 111 | } 112 | --------------------------------------------------------------------------------