├── .gitattributes ├── .gitignore ├── CSToPHP.sln ├── CommonAssemblyInfo.cs ├── Extensions ├── Lang.Php.Mpdf │ ├── Lang.Php.Mpdf.csproj │ ├── Mpdf.cs │ ├── PageOrientation.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── key.snk ├── Lang.Php.Wp.Compile │ ├── ClassFieldAccessExpressionConverter.cs │ ├── Lang.Php.Wp.Compile.csproj │ ├── MethodCallConverter.cs │ ├── ModuleProcessor.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── app.config │ ├── key.snk │ └── nuget.bat └── Lang.Php.Wp │ ├── AddAction.cs │ ├── AddFilter.cs │ ├── CoreMenuItemsPositions.cs │ ├── Lang.Php.Wp.csproj │ ├── Post.cs │ ├── PostInfo.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── WP_Http.cs │ ├── WellKnownScripts.cs │ ├── Wp.cs │ ├── WpDb.cs │ ├── WpPluginConfig.cs │ ├── WpPost.cs │ ├── WpTxt.cs │ ├── _attributes │ ├── HookAttribute.cs │ └── MainPluginModuleAttribute.cs │ ├── _enums │ ├── BlogInfoFilters.cs │ ├── BlogInfoShows.cs │ ├── Hooks.cs │ ├── PartOfPage.cs │ ├── Permissions.cs │ ├── PostTypes.cs │ ├── Priority.cs │ └── WpTags.cs │ ├── key.snk │ └── nuget.bat ├── LICENSE ├── Lang.Cs.Compiler ├── Common.tt ├── CompileState.cs ├── Compiler.cs ├── DeclarationItemDescription.cs ├── DesignTimeUtils.cs ├── ImmutableClasses.cs ├── ImmutableClasses.tt ├── ImmutableClasses2.cs ├── Lang.Cs.Compiler.csproj ├── MethodUtils.cs ├── ModelExtensions2.cs ├── Properties │ └── AssemblyInfo.cs ├── ReflectionExtension.cs ├── Sandbox │ └── AssemblyWrapper.cs ├── TypesUtil.cs ├── VSProject │ ├── BuildActions.cs │ ├── CompileResult.cs │ ├── Project1.cs │ ├── ProjectCollection.cs │ ├── ProjectItem.cs │ ├── ProjectReference.cs │ └── PropertyGroup.cs ├── Visitors │ ├── CodeVisitors.cs │ ├── CodeVisitors.tt │ ├── ExpressionConverterVisitor.cs │ ├── GenericTypesResolver.cs │ ├── LangParseContext.cs │ ├── LangVisitor.cs │ ├── MethodHeaderInfo.cs │ ├── QualifiedNameVisitor.cs │ ├── TypeVisitor.cs │ └── ValueVisitor.cs ├── _ReflectionExtensions.cs ├── _TextTemplateUtil.cs ├── app.config └── key.snk ├── Lang.Cs2Php ├── ArgumentProcessingContext.cs ├── CompilerEngine.cs ├── ConfigData.cs ├── IConfigData.cs ├── IConfigDataExtension.cs ├── Lang.Cs2Php.csproj ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ └── launchSettings.json ├── app.config └── key.snk ├── Lang.Php.Compiler ├── AppConfigManipulator.cs ├── AssemblySandbox.cs ├── Common.tt ├── Cs2PhpCompiler.cs ├── EmitContext.cs ├── ImmutableClasses.cs ├── ImmutableClasses.tt ├── Lang.Php.Compiler.csproj ├── Lang.Php.Compiler.csproj.DotSettings ├── LangPhpCompilerExtension.cs ├── LangPhpCompilerReflectionExtension.cs ├── OptimizeOptions.cs ├── PathUtil.cs ├── PhpEmitStyle.cs ├── PhpModuleNamespaceManager.cs ├── PhpNamespace.cs ├── PhpSourceCodeEmiter.cs ├── PhpSourceCodeWriter.cs ├── Properties │ └── AssemblyInfo.cs ├── Source │ ├── PhpCodeModuleName.cs │ ├── PhpMethodInvokeValue.cs │ ├── PhpQualifiedName.cs │ ├── PhpSourceBase.cs │ ├── PhpThisExpression.cs │ ├── PhpUnaryOperatorExpression.cs │ ├── _Definitions │ │ ├── PhpClassDefinition.cs │ │ ├── PhpClassFieldDefinition.cs │ │ ├── PhpClassMethodDefinition.cs │ │ ├── PhpCodeModule.cs │ │ └── PhpMethodDefinition.cs │ ├── _Expressions │ │ ├── PhpArrayAccessExpression.cs │ │ ├── PhpArrayCreateExpression.cs │ │ ├── PhpAssignExpression.cs │ │ ├── PhpBinaryOperatorExpression.cs │ │ ├── PhpClassFieldAccessExpression.cs │ │ ├── PhpConditionalExpression.cs │ │ ├── PhpConstValue.cs │ │ ├── PhpDefinedConstExpression.cs │ │ ├── PhpElementAccessExpression.cs │ │ ├── PhpFreeExpression.cs │ │ ├── PhpIncrementDecrementExpression.cs │ │ ├── PhpInstanceFieldAccessExpression.cs │ │ ├── PhpLambdaExpression.cs │ │ ├── PhpMethodArgument.cs │ │ ├── PhpMethodCallExpression.cs │ │ ├── PhpParenthesizedExpression.cs │ │ ├── PhpPropertyAccessExpression.cs │ │ ├── PhpValueBase.cs │ │ └── PhpVariableExpression.cs │ └── _Statements │ │ ├── PhpBreakStatement.cs │ │ ├── PhpCodeBlock.cs │ │ ├── PhpContinueStatement.cs │ │ ├── PhpExpressionStatement.cs │ │ ├── PhpForEachStatement.cs │ │ ├── PhpForStatement.cs │ │ ├── PhpIfStatement.cs │ │ ├── PhpNamespaceStatement.cs │ │ ├── PhpReturnStatement.cs │ │ ├── PhpStatementBase.cs │ │ ├── PhpSwitchLabel.cs │ │ ├── PhpSwitchSection.cs │ │ ├── PhpSwitchStatement.cs │ │ └── PhpWhileStatement.cs ├── Translator │ ├── ClassReplaceInfo.cs │ ├── ExpressionSimplifier.cs │ ├── Node │ │ ├── BasicTranslator_ClassField.cs │ │ ├── BasicTranslator_ClassPropertyAccess.cs │ │ ├── BasicTranslator_Constructor.cs │ │ ├── BasicTranslator_Methods.cs │ │ ├── BasicTranslator_Property.cs │ │ ├── DateTimeTranslator.cs │ │ ├── DotnetMethodCallTranslator.cs │ │ ├── EnumTranslator.cs │ │ ├── FilterTranslator.cs │ │ ├── GraphTranslator.cs │ │ ├── Lang__Php__Html__Methods.cs │ │ ├── Linq │ │ │ └── EnumerableTranslator.cs │ │ ├── MysqlMethods.cs │ │ ├── MysqliTranslator.cs │ │ ├── PhpDirectoryEntryTranslator.cs │ │ ├── ResponseHeaderTranslator.cs │ │ ├── StringBuilderTranslator.cs │ │ ├── StringExtensionsTranslator.cs │ │ └── TimeSpanTranslator.cs │ ├── PhpStatementSimplifier.cs │ ├── PhpStatementTranslatorVisitor.cs │ ├── PhpValueTranslator.cs │ ├── PregTranslator.cs │ ├── TranslationState.cs │ ├── Translator.cs │ └── TranslatorBase.cs ├── Visibility.cs ├── _CodeRequests │ ├── ClassCodeRequest.cs │ ├── GlobalVariableRequest.cs │ ├── LocalVariableRequest.cs │ └── ModuleCodeRequest.cs ├── _TranslationInfo │ ├── AssemblyTranslationInfo.cs │ ├── ClassTranslationInfo.cs │ ├── FieldTranslationInfo.cs │ ├── KnownConstInfo.cs │ ├── MethodTranslationInfo.cs │ ├── NodeTranslatorBound.cs │ ├── NodeTranslatorsContainer.cs │ ├── PropertyTranslationInfo.cs │ ├── TranslationInfo.cs │ └── TranslationMessage.cs ├── _Visitors │ ├── PhpBaseVisitor.cs │ └── PhpBaseVisitor.tt ├── _enum │ ├── EmitStyleCompression.cs │ ├── FieldTranslationDestionations.cs │ ├── MessageLevels.cs │ ├── PhpVariableKind.cs │ ├── ShowBracketsEnum.cs │ └── StatementEmitInfo.cs ├── _interfaces │ ├── ICodeRelated.cs │ ├── ICodeRequest.cs │ ├── IEmitable.cs │ ├── IExternalTranslationContext.cs │ ├── IModuleProcessor.cs │ ├── IPhpClassMember.cs │ ├── IPhpExpressionSimplifier.cs │ ├── IPhpNodeTranslator.cs │ ├── IPhpSimplifier.cs │ ├── IPhpStatement.cs │ └── IPhpValue.cs ├── app.config └── key.snk ├── Lang.Php.Framework ├── Extension.cs ├── Lang.Php.Framework.csproj ├── Properties │ └── AssemblyInfo.cs ├── Replacers │ ├── CharReplacer.cs │ ├── DictionaryReplacer.cs │ ├── DirectReplacers.cs │ ├── DirectReplacers.tt │ ├── IntReplacer.cs │ ├── KeyValuePairReplacer.cs │ ├── ListReplacer.cs │ ├── ObjectReplacer.cs │ ├── StackReplacer.cs │ └── StringReplacer.cs ├── app.config └── key.snk ├── Lang.Php.Test ├── Code │ ├── Includes.cs │ ├── MyCode.cs │ └── SampleEmptyClass.cs ├── Lang.Php.Test.OLD.csproj ├── Lang.Php.Test.csproj ├── Properties │ └── AssemblyInfo.cs ├── app.config └── php │ ├── MyCodePhp_BasicMath1.txt │ ├── MyCodePhp_Collections.txt │ ├── MyCodePhp_CostantsAndVariables.txt │ ├── MyCodePhp_Filters.txt │ ├── MyCodePhp_PregTest.txt │ ├── MyCodePhp_StringConcats.txt │ ├── module-Lang_Php_Test_Code_BusinessClass.txt │ ├── module-Lang_Php_Test_Code_BusinessClassDefinedConst.txt │ ├── module-Lang_Php_Test_Code_BusinessClassGlobalVariable.txt │ ├── module-Lang_Php_Test_Code_IncludeClassFieldAccess.txt │ ├── module-Lang_Php_Test_Code_IncludeClassPropertyAccess.txt │ ├── module-Lang_Php_Test_Code_IncludeInstanceFieldAccess.txt │ ├── module-Lang_Php_Test_Code_IncludeInstancePropertyAccess.txt │ ├── module-Lang_Php_Test_Code_IncludeShouldNotIncludeOther.txt │ ├── module-Lang_Php_Test_Code_MyCode.txt │ ├── module-Lang_Php_Test_Code_SampleEmptyClass.txt │ └── module-other-module-BusinessClassDefinedConst.txt ├── Lang.Php.Utils ├── Lang.Php.Utils.csproj ├── Properties │ └── AssemblyInfo.cs └── key.snk ├── Lang.Php.Webserver ├── App.xaml ├── App.xaml.cs ├── HttpRequest.cs ├── Lang.Php.Webserver.csproj ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Request.cs ├── ServerEngine.cs ├── StateObject.cs └── app.config ├── Lang.Php.XUnitTests ├── AppConfigTest.cs ├── ApplicationDomains.cs ├── Base.cs ├── BasicTests.cs ├── InheritanceTests.cs ├── Lang.Php.XUnitTest.xunit.runner.json ├── Lang.Php.XUnitTests.csproj ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── SandboxTest.cs └── app.config ├── Lang.Php ├── Data │ └── FieldGroupAttribute.cs ├── Falsable.cs ├── Filters │ ├── FilterInput.cs │ ├── FilterInputServer.cs │ ├── FilterVar.cs │ ├── KnownFilters.cs │ ├── ServerVariables.cs │ ├── _flags │ │ ├── IntFlags.cs │ │ ├── IpFlags.cs │ │ └── UrlFlags.cs │ └── _options │ │ ├── EmailOptions.cs │ │ ├── FloatOptions.cs │ │ ├── IntOptions.cs │ │ ├── IpOptions.cs │ │ ├── RegExpOptions.cs │ │ └── UrlOptions.cs ├── GlobalMethods.cs ├── Graph │ ├── Color.cs │ ├── Font.cs │ ├── Image.cs │ ├── ImageInfo.cs │ └── _enums │ │ └── ImageTypes.cs ├── Html.cs ├── HtmlEntitiesFlags.cs ├── IntOrFalse.cs ├── Lang.Php.csproj ├── MbPhpString.cs ├── OutputBuffer.cs ├── OutputCallbackDelegates.cs ├── PhpDummy.cs ├── PhpErrorTable.cs ├── PhpFileStream.cs ├── PhpIni.cs ├── PhpMath.cs ├── PhpString.cs ├── PhpVersions.cs ├── Properties │ └── AssemblyInfo.cs ├── Response.cs ├── Runtime │ ├── HttpResponse.cs │ ├── PhpCodeValue.cs │ ├── PhpStringBuilder.cs │ ├── PhpValues.cs │ ├── RuntimeMySQLiResult.cs │ ├── RuntimeMysqlResult.cs │ └── RuntimePhpDirectory.cs ├── SLFSupport.cs ├── Script.cs ├── _DateTime │ └── UnixTimestamp.cs ├── _Files │ ├── PathInfoResult.cs │ ├── PhpDirectory.cs │ ├── PhpDirectoryEntry.cs │ ├── PhpFile.cs │ ├── PhpFiles.cs │ └── UploadFileInfo.cs ├── _Firebird │ ├── Firebird.cs │ ├── FirebirdResult.cs │ └── IbaseTransactionOptions.cs ├── _MySQLi │ ├── MySQLi.cs │ ├── MySQLiCharsetInfo.cs │ ├── MySQLiFieldInfo.cs │ ├── MySQLiParam.cs │ ├── MySQLiResult.cs │ ├── MySQLiResultMode.cs │ ├── MySQLiStatement.cs │ └── MySQLiWarning.cs ├── _MySql │ ├── MySQL.cs │ ├── MySQLFieldTypes.cs │ ├── MySQLFlags.cs │ ├── MySqlDateTime.cs │ └── MysqlResult.cs ├── _Posix │ ├── Posix.cs │ ├── PosixGroupInfo.cs │ └── PosixUserInfo.cs ├── _Regex │ ├── Preg.cs │ ├── PregMatchResult.cs │ └── PregMatchWithOffset.cs ├── _ResponseHeader │ └── ResponseHeader.cs ├── _Server.cs ├── _attributes │ ├── AsArrayAttribute.cs │ ├── AsDefinedConstAttribute.cs │ ├── AsValueAttribute.cs │ ├── BuiltInAttribute.cs │ ├── DirectCallAttribute.cs │ ├── EnumRenderAttribute.cs │ ├── GlobalVariableAttribute.cs │ ├── IgnoreNamespaceAttribute.cs │ ├── ModuleAttribute.cs │ ├── PageAttribute.cs │ ├── PhpValueMapperAttribute.cs │ ├── RenderValueAttribute.cs │ ├── ReplaceAttribute.cs │ ├── RequireOnceAttribute.cs │ ├── ScriptNameAttribute.cs │ ├── SinceAttribute.cs │ ├── SkipAttribute.cs │ ├── TranslatorAttribute.cs │ ├── UseBinaryExpressionAttribute.cs │ ├── UseOperatorAttribute.cs │ └── _assembly │ │ ├── ConfigModuleAttribute.cs │ │ ├── DefaultTimezoneAttribute.cs │ │ ├── ModuleIncludeConstAttribute.cs │ │ ├── ModulesSubDirAttribute.cs │ │ ├── PhpPackageSourceAttribute.cs │ │ ├── PriovidesTranslatorAttribute.cs │ │ ├── RequiredTranslatorAttribute.cs │ │ ├── ResourcesDirectoryAttribute.cs │ │ └── RootPathAttribute.cs ├── _enums │ ├── Charsets.cs │ ├── ClassMembers.cs │ ├── Css.cs │ ├── CssMediaTypes.cs │ ├── EnumRenderOptions.cs │ ├── Enums.cs │ ├── Enums.tt │ ├── ErrorLevel.cs │ ├── FileStreamOpenModes.cs │ ├── FormEncodings.cs │ ├── FormMethods.cs │ ├── HttpEnums.cs │ ├── HttpEnums.tt │ ├── MethodCallStyles.cs │ ├── PathInfoOptions.cs │ ├── RoundMode.cs │ ├── Timezones.cs │ ├── UnixFileGroupPermissions.cs │ ├── UnixFilePermissions.cs │ └── UnixFilePermissions.tt ├── _exceptions │ ├── MockMethodException.cs │ └── PlatformImplementationException.cs ├── _extensions │ ├── DateTimeExtension.cs │ └── StringExtension.cs ├── app.config └── key.snk ├── README.md ├── _Examples ├── E01_HelloWorld │ ├── E01_HelloWorld.csproj │ ├── Index.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── compile.bat │ └── readme.txt ├── E02_BasicFeaturesExample │ ├── ComplexNumber.cs │ ├── ComplexNumberTest.cs │ ├── E02_BasicFeaturesExample.csproj │ ├── Generics.cs │ ├── Index.cs │ ├── MultiplicationTable.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── SomeFolder │ │ └── ClassInSubfolder.cs │ ├── SwichCaseTest.cs │ ├── compile.bat │ └── readme.txt ├── E03_ReferencedLibrary │ ├── E03_ReferencedLibrary.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── ReadMe.txt │ ├── Test.cs │ └── compile.bat ├── E04_Graphics │ ├── DynamicImage.cs │ ├── E04_Graphics.csproj │ ├── IndexPage.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── ReadMe.txt │ └── compile.bat ├── E05_Firebird │ ├── Demo.cs │ ├── E05_Firebird.csproj │ ├── Person.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── compile.bat ├── E06_Regex │ ├── E06_Regex.csproj │ ├── Index.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── compile.bat └── WP01_BasicFeatures │ ├── Class1.cs │ ├── Properties │ └── AssemblyInfo.cs │ └── WP01_BasicFeatures.csproj └── _ExamplesOut ├── E01_HelloWorld ├── index.php └── readme.txt ├── E02_BasicFeaturesExample ├── SomeFolder │ └── ClassInSubfolder.php ├── class.complex-number.php ├── class.multiplication-table.php ├── complex-number-test.php ├── index.php ├── readme.txt └── swich-case.php ├── E03_ReferencedLibrary ├── E03_ReferencedLibrary_Test.php └── cs2php.php ├── E04_Graphics ├── image.php └── index.php └── E06_Regex └── index.php /CommonAssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: AssemblyCompany("Internet Sukces Piotr Stęclik")] 5 | [assembly: AssemblyProduct("C# to PHP package")] 6 | [assembly: AssemblyCopyright("Copyright © Internet Sukces Piotr Stęclik 2017")] 7 | [assembly: AssemblyTrademark("")] 8 | [assembly: AssemblyCulture("")] 9 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /Extensions/Lang.Php.Mpdf/Lang.Php.Mpdf.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2.1.1 4 | net472 5 | Lang.Php.Mpdf 6 | Lang.Php.Mpdf 7 | Lang.Php.Mpdf 8 | Lang.Php.Mpdf 9 | Simple facade for mPDF library 10 | true 11 | true 12 | false 13 | true 14 | false 15 | true 16 | false 17 | false 18 | false 19 | false 20 | true 21 | 22 | 23 | bin\$(Configuration)\net472\$(ProjectName).xml 24 | 25 | 26 | 27 | CommonAssemblyInfo.cs 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Mpdf/PageOrientation.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Mpdf 2 | { 3 | public enum PageOrientation 4 | { 5 | [RenderValue("'P'")] 6 | Portrait, 7 | [RenderValue("'L'")] 8 | Landscape 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Mpdf/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | using Lang.Php; 8 | 9 | 10 | 11 | // The following GUID is for the ID of the typelib if this project is exposed to COM 12 | [assembly: Guid("fa979abe-9003-464d-a0ae-90e5feff29ea")] 13 | 14 | 15 | 16 | 17 | [assembly: RootPath("/lib/mpdf")] 18 | [assembly: PhpPackageSource("http://mpdf1.com/repos/MPDF57.zip", "MPDF57")] 19 | [assembly: ModuleIncludeConst("MPDF_LIB_PATH")] -------------------------------------------------------------------------------- /Extensions/Lang.Php.Mpdf/key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isukces/cs2php/7c817438b8e0fb004867fe70d20e09c3d3ba038e/Extensions/Lang.Php.Mpdf/key.snk -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp.Compile/ClassFieldAccessExpressionConverter.cs: -------------------------------------------------------------------------------- 1 | using Lang.Php.Compiler; 2 | using Lang.Cs.Compiler; 3 | using Lang.Php.Compiler.Source; 4 | 5 | namespace Lang.Php.Wp.Compile 6 | { 7 | class ClassFieldAccessExpressionConverter : IPhpNodeTranslator 8 | { 9 | 10 | public int GetPriority() 11 | { 12 | return 1; 13 | } 14 | 15 | public IPhpValue TranslateToPhp(IExternalTranslationContext ctx, ClassFieldAccessExpression src) 16 | { 17 | var t = src.Member.DeclaringType; 18 | string n = src.Member.Name; 19 | if (t == typeof(Wp)) 20 | { 21 | if (n == "DoingAutosave") 22 | { 23 | // if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 24 | var a1 = new PhpMethodCallExpression("defined", new PhpConstValue("DOING_AUTOSAVE")); 25 | var a2 = new PhpDefinedConstExpression("DOING_AUTOSAVE", null); 26 | var a3 = new PhpBinaryOperatorExpression("&&", a1, a2); 27 | var a4 = new PhpParenthesizedExpression(a3); 28 | return a4; 29 | } 30 | if (n == "HookSuffix") 31 | { 32 | var a1 = new PhpVariableExpression("hook_suffix", PhpVariableKind.Global); 33 | return a1; 34 | } 35 | } 36 | return null; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp.Compile/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using Lang.Php; 2 | using System.Reflection; 3 | using System.Runtime.InteropServices; 4 | [assembly: Guid("f14561b9-6d7f-4d84-8da2-43abf8a41fdc")] 5 | [assembly: PriovidesTranslator("57940af0-aef9-4c95-936f-9cf2e33a90df")] 6 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp.Compile/key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isukces/cs2php/7c817438b8e0fb004867fe70d20e09c3d3ba038e/Extensions/Lang.Php.Wp.Compile/key.snk -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp.Compile/nuget.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | 4 | 5 | if "%NUGETEXE%" == "" goto a 6 | if "%NUGETREPO%" == "" goto b 7 | 8 | echo NUGETEXE = %NUGETEXE% 9 | echo NUGETREPO = %NUGETREPO% 10 | 11 | %NUGETEXE% pack Lang.Php.Wp.Compile.csproj -IncludeReferencedProjects -Prop Configuration=RELEASE 12 | 13 | 14 | copy *.nupkg %NUGETREPO% 15 | del *.nupkg 16 | goto end 17 | 18 | 19 | 20 | :a 21 | echo ERROR brak zmiennej NUGETEXE 22 | goto end 23 | 24 | :b 25 | echo ERROR brak zmiennej NUGETREPO 26 | goto end 27 | 28 | 29 | :end 30 | pause 31 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp/CoreMenuItemsPositions.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Wp 2 | { 3 | [Skip] 4 | public class CoreMenuItemsPositions 5 | { 6 | [AsValue] 7 | public const int Dashboard = 2; 8 | [AsValue] 9 | public const int Separator_Before_Posts = 4; 10 | [AsValue] 11 | public const int Posts = 5; 12 | [AsValue] 13 | public const int Media = 10; 14 | [AsValue] 15 | public const int Links = 15; 16 | [AsValue] 17 | public const int Pages = 20; 18 | [AsValue] 19 | public const int Comments = 25; 20 | [AsValue] 21 | public const int Separator_Before_Appearance = 59; 22 | [AsValue] 23 | public const int Appearance = 60; 24 | [AsValue] 25 | public const int Plugins = 65; 26 | [AsValue] 27 | public const int Users = 70; 28 | [AsValue] 29 | public const int Tools = 75; 30 | [AsValue] 31 | public const int Settings = 80; 32 | [AsValue] 33 | public const int Separator_Last = 99; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp/Lang.Php.Wp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2.1.1 4 | net472 5 | Lang.Php.Wp 6 | Lang.Php.Wp 7 | WordPress API facade 8 | WordPress API facade 9 | true 10 | true 11 | false 12 | true 13 | false 14 | false 15 | false 16 | false 17 | false 18 | false 19 | True 20 | 21 | 22 | bin\$(Configuration)\net472\$(ProjectName).xml 23 | 24 | 25 | 26 | CommonAssemblyInfo.cs 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp/Post.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Wp 2 | { 3 | [BuiltIn] 4 | public class Post 5 | { 6 | [GlobalVariable("$post")] 7 | public static Post Current; 8 | 9 | public int ID; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp/PostInfo.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Wp 2 | { 3 | [BuiltIn] 4 | public class PostInfo 5 | { 6 | public int ID; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | using Lang.Php; 4 | 5 | [assembly: Guid("57940af0-aef9-4c95-936f-9cf2e33a90df")] 6 | [assembly: RequiredTranslator("Lang.Php.Wp.Compile, Version=1.2.1.1, Culture=neutral, PublicKeyToken=98135ffa69f3e2e6")] -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp/WP_Http.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Lang.Php.Wp 5 | { 6 | [IgnoreNamespace] 7 | [Skip] 8 | [Module("class-http", "ABSPATH", "WPINC")] 9 | // include_once( ABSPATH + WPINC + "/class-http + php" ); 10 | public class WP_Http 11 | { 12 | 13 | public Request_Array request(string url, Dictionary pp) 14 | { 15 | throw new NotSupportedException(); 16 | } 17 | 18 | 19 | [AsArray] 20 | public class Request_Array 21 | { 22 | [ScriptName("response")] 23 | public Response Response; 24 | 25 | [ScriptName("body")] 26 | public string Body; 27 | 28 | [ScriptName("headers")] 29 | public Dictionary Headers; 30 | 31 | [ScriptName("cookies")] 32 | public Dictionary Cookies; 33 | 34 | [ScriptName("filename")] 35 | public string Filename; 36 | 37 | [ScriptName("errors")] 38 | public object[] Errors; 39 | 40 | public Request_Array(Response response) 41 | { 42 | Response = response; 43 | } 44 | } 45 | [AsArray] 46 | public class Response 47 | { 48 | [ScriptName("code")] 49 | public int Code; 50 | 51 | [ScriptName("message")] 52 | public string Message; 53 | 54 | } 55 | [Skip] 56 | public class Request_Object 57 | { 58 | public object errors; 59 | 60 | } 61 | 62 | 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp/WellKnownScripts.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Wp 2 | { 3 | [Skip] 4 | public static class WellKnownScripts 5 | { 6 | #region Fields 7 | 8 | /// 9 | /// comment.php 10 | /// 11 | [AsValue] 12 | public const string Comment = "comment.php"; 13 | /// 14 | /// edit-comments.php 15 | /// 16 | [AsValue] 17 | public const string EditComments = "edit-comments.php"; 18 | /// 19 | /// index.php 20 | /// 21 | [AsValue] 22 | public const string Index = "index.php"; 23 | /// 24 | /// post.php 25 | /// 26 | [AsValue] 27 | public const string Post = "post.php"; 28 | 29 | #endregion Fields 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp/WpDb.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Lang.Php.Wp 5 | { 6 | [BuiltIn] 7 | public class WpDb 8 | { 9 | public List queries; 10 | 11 | 12 | [DirectCall("prepare")] 13 | public string Prepare(string query, params object[] args) 14 | { 15 | throw new NotImplementedException(); 16 | } 17 | 18 | [DirectCall("get_var")] 19 | public Nullable GetVar(string query) where T : struct 20 | { 21 | throw new NotImplementedException(); 22 | } 23 | [DirectCall("get_var")] 24 | public T GetVarClass(string query) where T : class 25 | { 26 | throw new NotImplementedException(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp/WpPluginConfig.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Wp 2 | { 3 | [Skip] 4 | public class WpPluginConfig 5 | { 6 | [AsValue] 7 | public const string PLUGINS_DIR = "/wp-content/plugins/"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp/WpPost.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php.Wp 4 | { 5 | [BuiltIn] 6 | public class WpPost 7 | { 8 | public static PostTypes PostType() 9 | { 10 | throw new NotImplementedException(); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp/WpTxt.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Wp 2 | { 3 | public class WpTxt 4 | { 5 | [AsValue] 6 | public const string SaveChanges = "Save Changes"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp/_attributes/HookAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php.Wp 4 | { 5 | public class HookAttribute:Attribute 6 | { 7 | public HookAttribute(Hooks hook) 8 | { 9 | Hook = hook; 10 | } 11 | public Hooks Hook { get; private set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp/_attributes/MainPluginModuleAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php.Wp 4 | { 5 | public class MainPluginModuleAttribute : Attribute 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp/_enums/BlogInfoFilters.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Wp 2 | { 3 | [EnumRender(EnumRenderOptions.UnderscoreLowercase, false)] 4 | public enum BlogInfoFilters 5 | { 6 | Display, 7 | Raw 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp/_enums/BlogInfoShows.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Wp 2 | { 3 | [EnumRender(EnumRenderOptions.UnderscoreLowercase, false)] 4 | public enum BlogInfoShows 5 | { 6 | Description, 7 | Name, 8 | TemplateDirectory, 9 | Url 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp/_enums/PartOfPage.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Wp 2 | { 3 | public enum PartOfPage 4 | { 5 | normal, 6 | advanced, 7 | side 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp/_enums/Permissions.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Wp 2 | { 3 | public enum Permissions 4 | { 5 | [RenderValue("'edit_pages'")] 6 | EditPages, 7 | [RenderValue("'edit_posts'")] 8 | EditPosts 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp/_enums/PostTypes.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Wp 2 | { 3 | [EnumRender(EnumRenderOptions.UnderscoreLowercase, false)] 4 | public enum PostTypes 5 | { 6 | Post, 7 | Page, 8 | Dashboard, 9 | Link, 10 | Attachment, 11 | CustomPostType 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp/_enums/Priority.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Wp 2 | { 3 | public enum Priority 4 | { 5 | [RenderValue("'high'")] 6 | High, 7 | [RenderValue("'core'")] 8 | Core, 9 | [RenderValue("'default'")] 10 | Default, 11 | [RenderValue("'low'")] 12 | Low 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp/_enums/WpTags.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Wp 2 | { 3 | 4 | [EnumRender(EnumRenderOptions.UnderscoreLowercase, false)] 5 | public enum WpTags 6 | { 7 | TheContent, 8 | TheTitle 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp/key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isukces/cs2php/7c817438b8e0fb004867fe70d20e09c3d3ba038e/Extensions/Lang.Php.Wp/key.snk -------------------------------------------------------------------------------- /Extensions/Lang.Php.Wp/nuget.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | 4 | 5 | if "%NUGETEXE%" == "" goto a 6 | if "%NUGETREPO%" == "" goto b 7 | 8 | echo NUGETEXE = %NUGETEXE% 9 | echo NUGETREPO = %NUGETREPO% 10 | 11 | %NUGETEXE% pack Lang.Php.Wp.csproj -IncludeReferencedProjects -Prop Configuration=RELEASE 12 | 13 | 14 | copy *.nupkg %NUGETREPO% 15 | del *.nupkg 16 | goto end 17 | 18 | 19 | 20 | :a 21 | echo ERROR brak zmiennej NUGETEXE 22 | goto end 23 | 24 | :b 25 | echo ERROR brak zmiennej NUGETREPO 26 | goto end 27 | 28 | 29 | :end 30 | pause 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isukces/cs2php/7c817438b8e0fb004867fe70d20e09c3d3ba038e/LICENSE -------------------------------------------------------------------------------- /Lang.Cs.Compiler/DesignTimeUtils.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Reflection; 3 | 4 | namespace Lang.Cs.Compiler 5 | { 6 | #if DEBUG 7 | 8 | public class DesignTimeUtils 9 | { 10 | 11 | 12 | 13 | 14 | 15 | public static string AAA(MethodInfo mi) 16 | { 17 | var p = mi.GetParameters(); 18 | List o = new List(); 19 | o.Add(mi.IsStatic ? "static" : "instance"); 20 | o.Add(mi.IsSpecialName ? "special" : "normal"); 21 | o.Add(TypesUtil.TypeToString(mi.DeclaringType)); 22 | o.Add(TypesUtil.TypeToString(mi.ReflectedType)); 23 | o.Add(mi.Name); 24 | o.Add(p.Length); 25 | 26 | o.Add(TypesUtil.TypeToString(mi.ReturnType)); 27 | foreach (var i in p) 28 | { 29 | o.Add(i.Name); 30 | o.Add(TypesUtil.TypeToString(i.ParameterType)); 31 | } 32 | return string.Join("\t", o); 33 | } 34 | } 35 | 36 | #endif 37 | } 38 | -------------------------------------------------------------------------------- /Lang.Cs.Compiler/Lang.Cs.Compiler.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2.1.1 4 | net472 5 | Lang.Cs.Compiler 6 | Lang.Cs.Compiler 7 | C# parsing library 8 | C# parsing library 9 | true 10 | true 11 | false 12 | true 13 | false 14 | true 15 | false 16 | false 17 | false 18 | false 19 | True 20 | 21 | 22 | bin\$(Configuration)\net472\$(ProjectName).xml 23 | 24 | 25 | $(DefineConstants);ROSLYN 26 | 27 | 28 | 29 | 30 | 31 | 32 | CommonAssemblyInfo.cs 33 | 34 | 35 | -------------------------------------------------------------------------------- /Lang.Cs.Compiler/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: Guid("c1d61da1-e312-4c34-947c-9a6abb56ab4f")] 5 | -------------------------------------------------------------------------------- /Lang.Cs.Compiler/ReflectionExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Cs.Compiler 4 | { 5 | public static class ReflectionExtension 6 | { 7 | #region Static Methods 8 | 9 | // Public Methods 10 | 11 | public static string IdString(this Type type) 12 | { 13 | var result = type.AssemblyQualifiedName; 14 | if (result != null) return result; 15 | if (type.DeclaringMethod == null) return result; 16 | if (type.DeclaringMethod.ReflectedType != null) 17 | return type.DeclaringMethod.ReflectedType.AssemblyQualifiedName + "/" + type.Name; 18 | return result; 19 | 20 | } 21 | 22 | #endregion Static Methods 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Lang.Cs.Compiler/VSProject/BuildActions.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Cs.Compiler.VSProject 2 | { 3 | public enum BuildActions 4 | { 5 | Other, 6 | Compile, 7 | Content 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Lang.Cs.Compiler/VSProject/ProjectItem.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Cs.Compiler.VSProject 2 | { 3 | public class ProjectItem 4 | { 5 | /// 6 | /// Tworzy instancję obiektu 7 | /// 8 | /// 9 | /// 10 | public ProjectItem(string name, BuildActions buildAction) 11 | { 12 | Name = name; 13 | BuildAction = buildAction; 14 | } 15 | 16 | /// 17 | /// 18 | public string Name 19 | { 20 | get => _name; 21 | set => _name = (value ?? string.Empty).Trim(); 22 | } 23 | 24 | /// 25 | /// 26 | public ProjectItem[] SubItems { get; set; } 27 | 28 | /// 29 | /// 30 | public BuildActions BuildAction { get; set; } 31 | 32 | private string _name = string.Empty; 33 | } 34 | } -------------------------------------------------------------------------------- /Lang.Cs.Compiler/VSProject/ProjectReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Xml.Linq; 4 | 5 | namespace Lang.Cs.Compiler.VSProject 6 | { 7 | public class ProjectReference 8 | { 9 | public static ProjectReference Deserialize(XElement e) 10 | { 11 | /* 12 | {ed717576-b7b9-4775-8236-1855e20e52d5} 13 | Lang.Php 14 | */ 15 | var ns = e.Name.Namespace; 16 | var path = (string)e.Attribute("Include"); 17 | var name = e.Element(ns + "Name")?.Value; 18 | if (string.IsNullOrEmpty(name)) 19 | { 20 | name = path.Split('/', '\\').Last(); 21 | if (name.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase)) 22 | name = name.Substring(0, name.Length - 7); 23 | } 24 | return new ProjectReference 25 | { 26 | _path = path, 27 | _name = name 28 | }; 29 | } 30 | 31 | /// 32 | /// 33 | public string Path 34 | { 35 | get => _path; 36 | set => _path = (value ?? string.Empty).Trim(); 37 | } 38 | 39 | /* 40 | /// 41 | /// 42 | public Guid ProjectGuid { get; set; } 43 | */ 44 | 45 | /// 46 | /// 47 | public string Name 48 | { 49 | get => _name; 50 | set => _name = (value ?? string.Empty).Trim(); 51 | } 52 | 53 | private string _path = string.Empty; 54 | private string _name = string.Empty; 55 | } 56 | } -------------------------------------------------------------------------------- /Lang.Cs.Compiler/Visitors/QualifiedNameVisitor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using Microsoft.CodeAnalysis.CSharp.Syntax; 4 | 5 | namespace Lang.Cs.Compiler.Visitors 6 | { 7 | public class QualifiedNameVisitor : CodeVisitor 8 | { 9 | public class R 10 | { 11 | public string GetNonGeneric() 12 | { 13 | if (IsGeneric) 14 | throw new ArgumentException(); 15 | return BaseName; 16 | } 17 | public string BaseName { get; set; } 18 | public TypeSyntax[] Generics { get; set; } 19 | public bool IsGeneric 20 | { 21 | get 22 | { 23 | return Generics != null && Generics.Any(); 24 | } 25 | } 26 | } 27 | protected override R VisitQualifiedName(QualifiedNameSyntax node) 28 | { 29 | var a = Visit(node.Left); 30 | var b = Visit(node.Right); 31 | if (a.IsGeneric || b.IsGeneric) 32 | throw new NotSupportedException(); 33 | return new R 34 | { 35 | BaseName = a.BaseName + "." + b.BaseName 36 | }; 37 | } 38 | 39 | protected override R VisitIdentifierName(IdentifierNameSyntax node) 40 | { 41 | return new R 42 | { 43 | BaseName = node.Identifier.ValueText 44 | }; 45 | } 46 | protected override R VisitGenericName(GenericNameSyntax node) 47 | { 48 | var bn = node.Identifier.ValueText; 49 | return new R 50 | { 51 | BaseName = bn, 52 | Generics = node.TypeArgumentList.Arguments.ToArray() 53 | }; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Lang.Cs.Compiler/key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isukces/cs2php/7c817438b8e0fb004867fe70d20e09c3d3ba038e/Lang.Cs.Compiler/key.snk -------------------------------------------------------------------------------- /Lang.Cs2Php/ConfigData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Lang.Cs2Php 5 | { 6 | internal class ConfigData : MarshalByRefObject, IConfigData 7 | { 8 | #region Constructors 9 | 10 | public ConfigData() 11 | { 12 | Referenced = new List(); 13 | TranlationHelpers = new List(); 14 | ReferencedPhpLibsLocations = new Dictionary(); 15 | } 16 | 17 | #endregion Constructors 18 | 19 | #region Properties 20 | 21 | // ReSharper disable once UnusedAutoPropertyAccessor.Global 22 | public string Configuration { get; set; } 23 | 24 | public List Referenced { get; private set; } 25 | 26 | public Dictionary ReferencedPhpLibsLocations { get; set; } 27 | 28 | public List TranlationHelpers { get; private set; } 29 | public string CsProject { get; set; } 30 | public string OutDir { get; set; } 31 | public string BinaryOutputDir { get; set; } 32 | 33 | #endregion Properties 34 | } 35 | } -------------------------------------------------------------------------------- /Lang.Cs2Php/IConfigData.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Lang.Cs2Php 4 | { 5 | public interface IConfigData 6 | { 7 | string Configuration { get; set; } 8 | string CsProject { get; set; } 9 | string OutDir { get; set; } 10 | List Referenced { get; } 11 | Dictionary ReferencedPhpLibsLocations { get; } 12 | List TranlationHelpers { get; } 13 | string BinaryOutputDir { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Lang.Cs2Php/IConfigDataExtension.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace Lang.Cs2Php 4 | { 5 | public static class ConfigDataExtension 6 | { 7 | public static void CopyFrom(this CompilerEngine dst, IConfigData src) 8 | { 9 | 10 | dst.Configuration = src.Configuration; 11 | dst.CsProject = src.CsProject; 12 | dst.OutDir = src.OutDir; 13 | dst.Referenced.Clear(); 14 | dst.TranlationHelpers.Clear(); 15 | dst.ReferencedPhpLibsLocations.Clear(); 16 | 17 | // src and dest can be in different application domain 18 | // we need to add item by item 19 | foreach (var q in src.Referenced.ToArray()) 20 | dst.Referenced.Add(q); 21 | foreach (var q in src.TranlationHelpers.ToArray()) 22 | dst.TranlationHelpers.Add(q); 23 | foreach (var a in src.ReferencedPhpLibsLocations) 24 | dst.ReferencedPhpLibsLocations.Add(a.Key, a.Value); 25 | 26 | dst.BinaryOutputDir = src.BinaryOutputDir; 27 | Debug.Assert(dst.Referenced.Count == src.Referenced.Count); 28 | Debug.Assert(dst.TranlationHelpers.Count == src.TranlationHelpers.Count); 29 | Debug.Assert(dst.ReferencedPhpLibsLocations.Count == src.ReferencedPhpLibsLocations.Count); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Lang.Cs2Php/Lang.Cs2Php.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2.1.1 4 | net472 5 | cs2php 6 | Lang.Cs2Php 7 | C# to PHP compiler 8 | C# to PHP compiler 9 | true 10 | true 11 | false 12 | true 13 | false 14 | false 15 | false 16 | false 17 | false 18 | false 19 | True 20 | 21 | Exe 22 | 23 | 24 | 25 | 26 | CommonAssemblyInfo.cs 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Lang.Cs2Php/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | [assembly: Guid("7bbd4622-25f1-4281-a5b6-24707968f063")] 4 | -------------------------------------------------------------------------------- /Lang.Cs2Php/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "Lang.Cs2Php": { 4 | "commandName": "Project", 5 | "commandLineArgs": "c:\\programs\\_CS2PHP\\PUBLIC\\_Examples\\E01_HelloWorld\\E01_HelloWorld.csproj c:\\temp\\hello-world-php" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /Lang.Cs2Php/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Lang.Cs2Php/key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isukces/cs2php/7c817438b8e0fb004867fe70d20e09c3d3ba038e/Lang.Cs2Php/key.snk -------------------------------------------------------------------------------- /Lang.Php.Compiler/ImmutableClasses.tt: -------------------------------------------------------------------------------- 1 | <#@ template debug="false" hostspecific="false" language="C#" #> 2 | <#@ assembly name="System.Core" #> 3 | <#@ import namespace="System.Linq" #> 4 | <#@ import namespace="System.Text" #> 5 | <#@ import namespace="System.Collections.Generic" #> 6 | <#@ output extension=".cs" #> 7 | <#@ include file="Common.tt" #> 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Linq; 11 | using System.Text; 12 | using System.Threading.Tasks; 13 | using System.Reflection; 14 | using Lang.Cs.Compiler; 15 | 16 | namespace Lang.Php.Compiler 17 | { 18 | <# 19 | 20 | MakeClass("FullClassDeclaration","", "string FullName", "ClassDeclaration ClassDeclaration", "NamespaceDeclaration NamespaceDeclaration"); 21 | MakeClass("FullInterfaceDeclaration","", "string FullName", "InterfaceDeclaration ClassDeclaration", "NamespaceDeclaration NamespaceDeclaration"); 22 | #> 23 | } 24 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/Lang.Php.Compiler.csproj.DotSettings: -------------------------------------------------------------------------------- 1 | 2 | True 3 | True 4 | True 5 | True 6 | True -------------------------------------------------------------------------------- /Lang.Php.Compiler/LangPhpCompilerExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using Lang.Php.Compiler.Source; 4 | 5 | namespace Lang.Php.Compiler 6 | { 7 | public static class LangPhpCompilerExtension 8 | { 9 | public static string ExcName(this Type type) 10 | { 11 | return type == null 12 | ? "[EMPTY TYPE]" 13 | : (type.FullName ?? type.Name); 14 | } 15 | 16 | public static string ExcName(this FieldInfo fieldInfo) 17 | { 18 | return fieldInfo == null 19 | ? "[EMPTY FieldInfo]" 20 | : string.Format("{0}.{1}", fieldInfo.Name, fieldInfo.DeclaringType.ExcName()); 21 | } 22 | 23 | public static string ExcName(this MethodInfo fieldInfo) 24 | { 25 | return fieldInfo == null 26 | ? "[EMPTY FieldInfo]" 27 | : string.Format("{0}.{1}", fieldInfo.Name, fieldInfo.DeclaringType.ExcName()); 28 | } 29 | 30 | 31 | public static bool IsEmpty(this PhpCodeModuleName phpCodeModuleName) 32 | { 33 | return phpCodeModuleName == null || phpCodeModuleName.IsEmpty; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/OptimizeOptions.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Compiler 2 | { 3 | public class OptimizeOptions 4 | { 5 | /// 6 | /// 7 | /// 8 | public bool JoinEchoStatements { get; set; } = true; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/PhpSourceCodeEmiter.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Lang.Php.Compiler 4 | { 5 | public class PhpSourceCodeEmiter 6 | { 7 | PhpSourceCodeWriter _code = new PhpSourceCodeWriter(); 8 | 9 | public static string GetAccessModifiers(IPhpClassMember m) 10 | { 11 | var modifiers = new List(); 12 | switch (m.Visibility) 13 | { 14 | case Visibility.Private: 15 | modifiers.Add("private"); 16 | break; 17 | case Visibility.Protected: 18 | modifiers.Add("protected"); 19 | break; 20 | default: 21 | modifiers.Add("public"); 22 | break; 23 | } 24 | if (m.IsStatic) 25 | modifiers.Add("static"); 26 | return string.Join(" ", modifiers); 27 | 28 | } 29 | 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | 5 | 6 | [assembly: Guid("489f63b1-9cdc-4b6e-a9f3-f04ebd882d8c")] 7 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/Source/PhpMethodInvokeValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Lang.Php.Compiler.Source 5 | { 6 | public class PhpMethodInvokeValue : PhpValueBase 7 | { 8 | /// 9 | /// Tworzy instancję obiektu 10 | /// 11 | /// 12 | public PhpMethodInvokeValue(IPhpValue Expression) 13 | { 14 | this.Expression = Expression; 15 | } 16 | 17 | public override IEnumerable GetCodeRequests() 18 | { 19 | return Expression == null ? new ICodeRequest[0] : Expression.GetCodeRequests(); 20 | } 21 | 22 | public override string GetPhpCode(PhpEmitStyle style) 23 | { 24 | if (Expression == null) 25 | throw new Exception("Unable to get code from empty expression"); 26 | var ex = PhpParenthesizedExpression.Strip(Expression); 27 | var a = Expression.GetPhpCode(style); 28 | if (ByRef) 29 | a = "&" + a; 30 | return a; 31 | } 32 | 33 | /// 34 | /// 35 | public IPhpValue Expression { get; set; } 36 | 37 | /// 38 | /// 39 | public bool ByRef { get; set; } 40 | 41 | /// 42 | /// Nazwa własności Expression; 43 | /// 44 | public const string PROPERTYNAME_EXPRESSION = "Expression"; 45 | 46 | /// 47 | /// Nazwa własności ByRef; 48 | /// 49 | public const string PROPERTYNAME_BYREF = "ByRef"; 50 | } 51 | } -------------------------------------------------------------------------------- /Lang.Php.Compiler/Source/PhpThisExpression.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Lang.Php.Compiler.Source 4 | { 5 | public class PhpThisExpression : PhpValueBase 6 | { 7 | public override string GetPhpCode(PhpEmitStyle style) 8 | { 9 | return "$this"; 10 | } 11 | 12 | public override IEnumerable GetCodeRequests() 13 | { 14 | return new ICodeRequest[0]; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/Source/PhpUnaryOperatorExpression.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Lang.Php.Compiler.Source 4 | { 5 | public class PhpUnaryOperatorExpression : PhpValueBase 6 | { 7 | /// 8 | /// Tworzy instancję obiektu 9 | /// 10 | /// 11 | /// 12 | public PhpUnaryOperatorExpression(IPhpValue operand, string _operator) 13 | { 14 | Operand = operand; 15 | Operator = _operator; 16 | } 17 | // Public Methods 18 | 19 | public override IEnumerable GetCodeRequests() 20 | { 21 | return Operand == null ? new ICodeRequest[0] : Operand.GetCodeRequests(); 22 | } 23 | 24 | public override string GetPhpCode(PhpEmitStyle style) 25 | { 26 | return string.Format("{0}{1}", Operator, Operand.GetPhpCode(style)); 27 | } 28 | 29 | 30 | /// 31 | /// Własność jest tylko do odczytu. 32 | /// 33 | public IPhpValue Operand { get; } 34 | 35 | /// 36 | /// Własność jest tylko do odczytu. 37 | /// 38 | public string Operator { get; } = string.Empty; 39 | } 40 | } -------------------------------------------------------------------------------- /Lang.Php.Compiler/Source/_Expressions/PhpArrayAccessExpression.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Lang.Php.Compiler.Source 4 | { 5 | public class PhpArrayAccessExpression : PhpValueBase 6 | { 7 | /// 8 | /// Tworzy instancję obiektu 9 | /// 10 | /// 11 | /// 12 | public PhpArrayAccessExpression(IPhpValue phpArray, IPhpValue index) 13 | { 14 | PhpArray = phpArray; 15 | Index = index; 16 | } 17 | 18 | 19 | public override IEnumerable GetCodeRequests() 20 | { 21 | return PhpStatementBase.GetCodeRequests(PhpArray, Index); 22 | } 23 | 24 | public override string GetPhpCode(PhpEmitStyle style) 25 | { 26 | return string.Format("{0}[{1}]", PhpArray.GetPhpCode(style), Index.GetPhpCode(style)); 27 | } 28 | 29 | /// 30 | /// Własność jest tylko do odczytu. 31 | /// 32 | public IPhpValue PhpArray { get; } 33 | 34 | /// 35 | /// Własność jest tylko do odczytu. 36 | /// 37 | public IPhpValue Index { get; } 38 | } 39 | } -------------------------------------------------------------------------------- /Lang.Php.Compiler/Source/_Expressions/PhpDefinedConstExpression.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Lang.Php.Compiler.Source 5 | { 6 | public class PhpDefinedConstExpression : PhpValueBase 7 | { 8 | /// 9 | /// Tworzy instancję obiektu 10 | /// 11 | /// 12 | /// 13 | public PhpDefinedConstExpression(string definedConstName, PhpCodeModuleName moduleName) 14 | { 15 | if (definedConstName == "PHP_EOL" && moduleName != null) 16 | throw new Exception("PHP_EOL is built in"); 17 | DefinedConstName = definedConstName; 18 | _moduleName = moduleName; 19 | } 20 | 21 | public override IEnumerable GetCodeRequests() 22 | { 23 | if (_moduleName != null) 24 | yield return new ModuleCodeRequest(_moduleName, "defined const " + DefinedConstName); 25 | } 26 | 27 | public override string GetPhpCode(PhpEmitStyle style) 28 | { 29 | return DefinedConstName; 30 | } 31 | 32 | /// 33 | /// Własność jest tylko do odczytu. 34 | /// 35 | public string DefinedConstName { get; } = string.Empty; 36 | 37 | private readonly PhpCodeModuleName _moduleName; 38 | } 39 | } -------------------------------------------------------------------------------- /Lang.Php.Compiler/Source/_Expressions/PhpFreeExpression.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Lang.Php.Compiler.Source 4 | { 5 | public class PhpFreeExpression : PhpValueBase 6 | { 7 | /// 8 | /// Tworzy instancję obiektu 9 | /// 10 | /// 11 | public PhpFreeExpression(string expression) 12 | { 13 | Expression = expression; 14 | } 15 | 16 | public override IEnumerable GetCodeRequests() 17 | { 18 | return new ICodeRequest[0]; 19 | } 20 | 21 | public override string GetPhpCode(PhpEmitStyle style) 22 | { 23 | return _expression; 24 | } 25 | 26 | /// 27 | /// 28 | public string Expression 29 | { 30 | get => _expression; 31 | set => _expression = (value ?? string.Empty).Trim(); 32 | } 33 | 34 | private string _expression = string.Empty; 35 | } 36 | } -------------------------------------------------------------------------------- /Lang.Php.Compiler/Source/_Expressions/PhpIncrementDecrementExpression.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Lang.Php.Compiler.Source 4 | { 5 | public class PhpIncrementDecrementExpression : PhpValueBase 6 | { 7 | // Public Methods 8 | 9 | public override string GetPhpCode(PhpEmitStyle style) 10 | { 11 | var o = Increment ? "++" : "--"; 12 | return string.Format("{0}{1}{2}", 13 | Pre ? o : "", 14 | Operand.GetPhpCode(style), 15 | Pre ? "" : o); 16 | } 17 | 18 | public override IEnumerable GetCodeRequests() 19 | { 20 | return PhpStatementBase.GetCodeRequests(Operand); 21 | } 22 | 23 | /// 24 | /// Tworzy instancję obiektu 25 | /// , 26 | /// 27 | /// 28 | /// 29 | public PhpIncrementDecrementExpression(IPhpValue operand, bool increment, bool pre) 30 | { 31 | Operand = operand; 32 | Increment = increment; 33 | Pre = pre; 34 | } 35 | 36 | 37 | /// 38 | /// , 39 | /// 40 | public IPhpValue Operand { get; set; } 41 | 42 | /// 43 | /// 44 | /// 45 | public bool Increment { get; set; } 46 | 47 | /// 48 | /// 49 | /// 50 | public bool Pre { get; set; } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/Source/_Expressions/PhpLambdaExpression.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Lang.Php.Compiler.Source 4 | { 5 | public class PhpLambdaExpression : ICodeRelated, IPhpValue 6 | { 7 | /// 8 | /// Tworzy instancję obiektu 9 | /// 10 | /// 11 | public PhpLambdaExpression(PhpMethodDefinition methodDefinition) 12 | { 13 | MethodDefinition = methodDefinition; 14 | } 15 | 16 | public IEnumerable GetCodeRequests() 17 | { 18 | return MethodDefinition.GetCodeRequests(); 19 | } 20 | 21 | public string GetPhpCode(PhpEmitStyle style) 22 | { 23 | /* 24 | echo preg_replace_callback('~-([a-z])~', function ($match) { 25 | return strtoupper($match[1]); 26 | }, 'hello-world'); 27 | // outputs helloWorld 28 | */ 29 | var s = PhpEmitStyle.xClone(style); 30 | s.AsIncrementor = true; 31 | var e = new PhpSourceCodeEmiter(); 32 | var wde = new PhpSourceCodeWriter(); 33 | wde.Clear(); 34 | MethodDefinition.Emit(e, wde, s); 35 | var code = wde.GetCode(true).Trim(); 36 | return code; 37 | } 38 | 39 | /// 40 | /// 41 | public PhpMethodDefinition MethodDefinition { get; set; } 42 | } 43 | } -------------------------------------------------------------------------------- /Lang.Php.Compiler/Source/_Expressions/PhpMethodArgument.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Compiler.Source 2 | { 3 | public class PhpMethodArgument 4 | { 5 | // Public Methods 6 | 7 | public string GetPhpCode(PhpEmitStyle s) 8 | { 9 | s = s ?? new PhpEmitStyle(); 10 | var eq = s.Compression == EmitStyleCompression.Beauty ? " = " : "="; 11 | var d = DefaultValue != null ? eq + DefaultValue.GetPhpCode(s) : ""; 12 | return string.Format("${0}{1}", _name, d); 13 | } 14 | 15 | public override string ToString() 16 | { 17 | return GetPhpCode(null); 18 | } 19 | 20 | 21 | /// 22 | /// Nazwa argumentu 23 | /// 24 | public string Name 25 | { 26 | get => _name; 27 | set => _name = (value ?? string.Empty).Trim(); 28 | } 29 | 30 | /// 31 | /// 32 | public IPhpValue DefaultValue { get; set; } 33 | 34 | private string _name = string.Empty; 35 | } 36 | } -------------------------------------------------------------------------------- /Lang.Php.Compiler/Source/_Expressions/PhpParenthesizedExpression.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Lang.Php.Compiler.Source 4 | { 5 | public class PhpParenthesizedExpression : PhpValueBase 6 | { 7 | /// 8 | /// Tworzy instancję obiektu 9 | /// 10 | /// 11 | public PhpParenthesizedExpression(IPhpValue Expression) 12 | { 13 | this.Expression = Expression; 14 | } 15 | // Public Methods 16 | 17 | public static IPhpValue Strip(IPhpValue x) 18 | { 19 | if (x is PhpParenthesizedExpression) 20 | return Strip((x as PhpParenthesizedExpression).Expression); 21 | return x; 22 | } 23 | 24 | // Public Methods 25 | 26 | public override IEnumerable GetCodeRequests() 27 | { 28 | return Expression == null ? new ICodeRequest[0] : Expression.GetCodeRequests(); 29 | } 30 | 31 | public override string GetPhpCode(PhpEmitStyle style) 32 | { 33 | return string.Format("({0})", Expression.GetPhpCode(style)); 34 | } 35 | 36 | 37 | /// 38 | /// Własność jest tylko do odczytu. 39 | /// 40 | public IPhpValue Expression { get; } 41 | } 42 | } -------------------------------------------------------------------------------- /Lang.Php.Compiler/Source/_Expressions/PhpValueBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | // ReSharper disable once CheckNamespace 5 | namespace Lang.Php.Compiler.Source 6 | { 7 | public abstract class PhpValueBase : PhpSourceBase, IPhpValue 8 | { 9 | #region Methods 10 | 11 | // Public Methods 12 | 13 | public abstract IEnumerable GetCodeRequests(); 14 | 15 | public abstract string GetPhpCode(PhpEmitStyle style); 16 | 17 | public virtual IPhpValue Simplify(IPhpExpressionSimplifier s) 18 | { 19 | return this; 20 | } 21 | 22 | public override string ToString() 23 | { 24 | return GetPhpCode(null); 25 | } 26 | // Protected Methods 27 | 28 | protected IPhpValue SimplifyForFieldAcces(IPhpValue src, IPhpExpressionSimplifier s) 29 | { 30 | src = s.Simplify(src); 31 | if (!(src is PhpParenthesizedExpression)) return src; 32 | var inside = (src as PhpParenthesizedExpression).Expression; 33 | if (inside is PhpVariableExpression) 34 | return inside; 35 | if (inside is PhpMethodCallExpression) 36 | return (inside as PhpMethodCallExpression).IsConstructorCall ? src : inside; 37 | if (inside is PhpBinaryOperatorExpression || inside is PhpConditionalExpression) 38 | return src; 39 | throw new NotSupportedException(); 40 | } 41 | 42 | protected IPhpValue StripBracketsAndSimplify(IPhpValue value, IPhpExpressionSimplifier s) 43 | { 44 | value = PhpParenthesizedExpression.Strip(value); 45 | value = s.Simplify(value); 46 | return value; 47 | } 48 | 49 | #endregion Methods 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/Source/_Statements/PhpBreakStatement.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Lang.Php.Compiler.Source 4 | { 5 | public class PhpBreakStatement : PhpStatementBase 6 | { 7 | public override void Emit(PhpSourceCodeEmiter emiter, PhpSourceCodeWriter writer, PhpEmitStyle style) 8 | { 9 | writer.WriteLn("break;"); 10 | } 11 | 12 | public override IEnumerable GetCodeRequests() 13 | { 14 | return new ICodeRequest[0]; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/Source/_Statements/PhpContinueStatement.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Lang.Php.Compiler.Source 4 | { 5 | public class PhpContinueStatement : PhpStatementBase 6 | { 7 | #region Methods 8 | 9 | // Public Methods 10 | 11 | public override void Emit(PhpSourceCodeEmiter emiter, PhpSourceCodeWriter writer, PhpEmitStyle style) 12 | { 13 | var s = style == null ? EmitStyleCompression.Beauty : style.Compression; 14 | if (s == EmitStyleCompression.NearCrypto) 15 | writer.Write("continue;"); 16 | else 17 | writer.WriteLn("continue;"); 18 | } 19 | 20 | public override IEnumerable GetCodeRequests() 21 | { 22 | return new ICodeRequest[0]; 23 | } 24 | 25 | #endregion Methods 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/Source/_Statements/PhpReturnStatement.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Lang.Php.Compiler.Source 4 | { 5 | public class PhpReturnStatement : PhpStatementBase 6 | { 7 | /// 8 | /// Tworzy instancję obiektu 9 | /// 10 | /// 11 | public PhpReturnStatement(IPhpValue returnValue) 12 | { 13 | ReturnValue = returnValue; 14 | } 15 | // Public Methods 16 | 17 | public override void Emit(PhpSourceCodeEmiter emiter, PhpSourceCodeWriter writer, PhpEmitStyle style) 18 | { 19 | if (ReturnValue == null) 20 | writer.WriteLn("return;"); 21 | else 22 | writer.WriteLnF("return {0};", ReturnValue.GetPhpCode(style)); 23 | } 24 | 25 | public override IEnumerable GetCodeRequests() 26 | { 27 | return GetCodeRequests(ReturnValue); 28 | } 29 | 30 | public override IPhpStatement Simplify(IPhpSimplifier s) 31 | { 32 | if (ReturnValue == null) 33 | return this; 34 | var newReturnValue = s.Simplify(ReturnValue); 35 | return ReturnValue == newReturnValue ? this : new PhpReturnStatement(newReturnValue); 36 | } 37 | 38 | /// 39 | /// Własność jest tylko do odczytu. 40 | /// 41 | public IPhpValue ReturnValue { get; } 42 | } 43 | } -------------------------------------------------------------------------------- /Lang.Php.Compiler/Source/_Statements/PhpSwitchLabel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Lang.Php.Compiler.Source 4 | { 5 | public class PhpSwitchLabel : ICodeRelated 6 | { 7 | /// 8 | /// Tworzy instancję obiektu 9 | /// 10 | public PhpSwitchLabel() 11 | { 12 | } 13 | 14 | /// 15 | /// Tworzy instancję obiektu 16 | /// 17 | /// 18 | public PhpSwitchLabel(IPhpValue value) 19 | { 20 | Value = value; 21 | } 22 | // Public Methods 23 | 24 | public IEnumerable GetCodeRequests() 25 | { 26 | if (Value != null) 27 | return Value.GetCodeRequests(); 28 | return new ICodeRequest[0]; 29 | } 30 | 31 | public PhpSwitchLabel Simplify(IPhpSimplifier s, out bool wasChanged) 32 | { 33 | wasChanged = false; 34 | if (IsDefault) 35 | return this; 36 | var e1 = s.Simplify(Value); 37 | wasChanged = !PhpSourceBase.EqualCode(e1, Value); 38 | if (wasChanged) 39 | return new PhpSwitchLabel(e1); 40 | return this; 41 | } 42 | 43 | 44 | /// 45 | /// 46 | public IPhpValue Value { get; set; } 47 | 48 | /// 49 | /// 50 | public bool IsDefault { get; set; } 51 | } 52 | } -------------------------------------------------------------------------------- /Lang.Php.Compiler/Source/_Statements/PhpSwitchSection.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Lang.Php.Compiler.Source 4 | { 5 | public class PhpSwitchSection : ICodeRelated 6 | { 7 | public IEnumerable GetCodeRequests() 8 | { 9 | var result = new List(); 10 | if (Labels != null) 11 | foreach (var _label in Labels) 12 | result.AddRange(_label.GetCodeRequests()); 13 | if (Statement != null) 14 | result.AddRange(Statement.GetCodeRequests()); 15 | return result; 16 | } 17 | 18 | public PhpSwitchSection Simplify(IPhpSimplifier s, out bool wasChanged) 19 | { 20 | wasChanged = false; 21 | var nLabels = new List(); 22 | foreach (var lab in Labels) 23 | { 24 | bool labelWasChanged; 25 | nLabels.Add(lab.Simplify(s, out labelWasChanged)); 26 | if (labelWasChanged) wasChanged = true; 27 | } 28 | 29 | var nStatement = s.Simplify(Statement); 30 | if (!PhpSourceBase.EqualCode(nStatement, Statement)) 31 | wasChanged = true; 32 | if (!wasChanged) 33 | return this; 34 | return new PhpSwitchSection 35 | { 36 | Labels = nLabels.ToArray(), 37 | Statement = nStatement 38 | }; 39 | } 40 | 41 | /// 42 | /// 43 | public PhpSwitchLabel[] Labels { get; set; } 44 | 45 | /// 46 | /// 47 | public IPhpStatement Statement { get; set; } 48 | } 49 | } -------------------------------------------------------------------------------- /Lang.Php.Compiler/Source/_Statements/PhpWhileStatement.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Lang.Php.Compiler.Source 4 | { 5 | public class PhpWhileStatement : PhpStatementBase 6 | { 7 | /// 8 | /// Tworzy instancję obiektu 9 | /// 10 | /// 11 | /// 12 | public PhpWhileStatement(IPhpValue condition, IPhpStatement statement) 13 | { 14 | Condition = condition; 15 | Statement = statement; 16 | } 17 | 18 | // Public Methods 19 | 20 | public override void Emit(PhpSourceCodeEmiter emiter, PhpSourceCodeWriter writer, PhpEmitStyle style) 21 | { 22 | style = style ?? new PhpEmitStyle(); 23 | var header = string.Format("while({0})", Condition.GetPhpCode(style)); 24 | EmitHeaderStatement(emiter, writer, style, header, Statement); 25 | } 26 | 27 | public override IEnumerable GetCodeRequests() 28 | { 29 | return GetCodeRequests(Condition, Statement); 30 | } 31 | 32 | public override IPhpStatement Simplify(IPhpSimplifier s) 33 | { 34 | var newCondition = s.Simplify(Condition); 35 | var newStatement = s.Simplify(Statement); 36 | if (newCondition == Condition && newStatement == Statement) 37 | return this; 38 | return new PhpWhileStatement(newCondition, newStatement); 39 | } 40 | 41 | /// 42 | /// 43 | public IPhpValue Condition { get; set; } 44 | 45 | /// 46 | /// 47 | public IPhpStatement Statement { get; set; } 48 | } 49 | } -------------------------------------------------------------------------------- /Lang.Php.Compiler/Translator/Node/BasicTranslator_ClassField.cs: -------------------------------------------------------------------------------- 1 | using Lang.Cs.Compiler; 2 | using Lang.Php.Compiler.Source; 3 | using System.Collections.Generic; 4 | 5 | namespace Lang.Php.Compiler.Translator.Node 6 | { 7 | class BasicTranslator_ClassField : IPhpNodeTranslator 8 | { 9 | #region Methods 10 | 11 | // Public Methods 12 | 13 | public int GetPriority() 14 | { 15 | return 9; 16 | } 17 | 18 | public IPhpValue TranslateToPhp(IExternalTranslationContext ctx, ClassFieldAccessExpression src) 19 | { 20 | var s = TranslatorBase.GetCompareName(src.Member); 21 | if (cache == null) 22 | cache = new Dictionary() 23 | { 24 | { "System.String::Empty", new PhpConstValue("")}, 25 | { "System.Math::PI", new PhpDefinedConstExpression("M_PI", null)}, 26 | { "System.Math::E", new PhpDefinedConstExpression("M_E", null)}, 27 | { "System.Int32::MaxValue", new PhpConstValue(int.MaxValue) }, 28 | }; 29 | 30 | // Math.E 31 | IPhpValue o; 32 | if (cache.TryGetValue(s, out o)) 33 | return o; 34 | return null; 35 | } 36 | 37 | #endregion Methods 38 | 39 | #region Fields 40 | 41 | Dictionary cache; 42 | 43 | #endregion Fields 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/Translator/Node/BasicTranslator_Methods.cs: -------------------------------------------------------------------------------- 1 | using Lang.Cs.Compiler; 2 | using Lang.Php.Compiler.Source; 3 | using System.Collections.Generic; 4 | 5 | namespace Lang.Php.Compiler.Translator.Node 6 | { 7 | public class BasicTranslator_Methods : IPhpNodeTranslator 8 | { 9 | public IPhpValue TranslateToPhp(IExternalTranslationContext ctx, CsharpMethodCallExpression src) 10 | { 11 | var dt = src.MethodInfo.DeclaringType; 12 | if (dt.IsGenericType) 13 | dt = dt.GetGenericTypeDefinition(); 14 | if (dt == typeof(Stack<>)) 15 | { 16 | var fn = src.MethodInfo.ToString(); 17 | if (fn == "System.String Peek()") 18 | { 19 | var to = ctx.TranslateValue(src.TargetObject); 20 | var cnt = new PhpMethodCallExpression("count", to); 21 | var cnt_1 = new PhpBinaryOperatorExpression("-", cnt, new PhpConstValue(1)); 22 | var ar = new PhpArrayAccessExpression(to, cnt_1); 23 | return ar; 24 | } 25 | return null; 26 | } 27 | return null; 28 | } 29 | 30 | public int GetPriority() 31 | { 32 | return 2; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/Translator/Node/EnumTranslator.cs: -------------------------------------------------------------------------------- 1 | using Lang.Cs.Compiler; 2 | using System; 3 | 4 | namespace Lang.Php.Compiler.Translator.Node 5 | { 6 | public class EnumTranslator : IPhpNodeTranslator 7 | { 8 | public IPhpValue TranslateToPhp(IExternalTranslationContext ctx, CsharpMethodCallExpression src) 9 | { 10 | if (src.MethodInfo.DeclaringType != typeof(Enum)) 11 | return null; 12 | var fn = src.MethodInfo.ToString(); 13 | if (fn == "System.Object Parse(System.Type, System.String)") 14 | { 15 | var a = src.Arguments[1].MyValue; 16 | var b = ctx.TranslateValue(a); 17 | return b; 18 | } 19 | throw new NotImplementedException(); 20 | } 21 | 22 | public int GetPriority() 23 | { 24 | return 1; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/Translator/Node/GraphTranslator.cs: -------------------------------------------------------------------------------- 1 | using Lang.Cs.Compiler; 2 | using Lang.Php.Compiler.Source; 3 | using System; 4 | using Lang.Php.Graph; 5 | 6 | 7 | namespace Lang.Php.Compiler.Translator.Node 8 | { 9 | public class GraphTranslator : IPhpNodeTranslator 10 | { 11 | public IPhpValue TranslateToPhp(IExternalTranslationContext ctx, ClassFieldAccessExpression src) 12 | { 13 | if (src.Member.DeclaringType == typeof(Font)) 14 | { 15 | var name = src.Member.Name; 16 | if (name =="Font1" || name =="Font2" || name =="Font3" || name =="Font4" || name =="Font5" ) { 17 | var size = int.Parse(name.Substring(4)); 18 | return new PhpConstValue(size); 19 | } 20 | throw new NotImplementedException(); 21 | } 22 | return null; 23 | } 24 | 25 | public int GetPriority() 26 | { 27 | return 1; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/Translator/Node/Linq/EnumerableTranslator.cs: -------------------------------------------------------------------------------- 1 | using Lang.Cs.Compiler; 2 | using System; 3 | using System.Linq; 4 | 5 | namespace Lang.Php.Compiler.Translator.Node.Linq 6 | { 7 | class EnumerableTranslator : IPhpNodeTranslator 8 | { 9 | public IPhpValue TranslateToPhp(IExternalTranslationContext ctx, CsharpMethodCallExpression src) 10 | { 11 | if (src.MethodInfo.DeclaringType == typeof(Enumerable)) 12 | { 13 | var fn = src.MethodInfo.ToString(); 14 | if (fn == "System.Collections.Generic.List`1[System.String] ToList[String](System.Collections.Generic.IEnumerable`1[System.String])") 15 | { 16 | var v = ctx.TranslateValue(src.Arguments[0].MyValue); 17 | return v; // po prostu argument 18 | } 19 | if (fn == "System.Linq.IOrderedEnumerable`1[System.Collections.Generic.IEnumerable`1[System.String]] OrderBy[IEnumerable`1,Func`2](System.Collections.Generic.IEnumerable`1[System.Collections.Generic.IEnumerable`1[System.String]], System.Func`2[System.Collections.Generic.IEnumerable`1[System.String],System.Func`2[System.String,System.String]])") 20 | { 21 | var v = ctx.TranslateValue(src.Arguments[1].MyValue); 22 | // var vv = new Lang.Php.ph 23 | return v; // po prostu argument 24 | } 25 | throw new NotImplementedException(); 26 | } 27 | return null; 28 | } 29 | 30 | public int GetPriority() 31 | { 32 | return 1; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/Translator/Node/MysqlMethods.cs: -------------------------------------------------------------------------------- 1 | using Lang.Cs.Compiler; 2 | 3 | namespace Lang.Php.Compiler.Translator.Node 4 | { 5 | class MysqlMethods : IPhpNodeTranslator 6 | { 7 | #region Methods 8 | 9 | // Public Methods 10 | 11 | public int GetPriority() 12 | { 13 | return 1; 14 | } 15 | 16 | public IPhpValue TranslateToPhp(IExternalTranslationContext ctx, CsharpMethodCallExpression src) 17 | { 18 | return null; 19 | } 20 | 21 | #endregion Methods 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/Translator/Node/PhpDirectoryEntryTranslator.cs: -------------------------------------------------------------------------------- 1 | using Lang.Cs.Compiler; 2 | 3 | namespace Lang.Php.Compiler.Translator.Node 4 | { 5 | public class PhpDirectoryEntryTranslator : IPhpNodeTranslator 6 | { 7 | public IPhpValue TranslateToPhp(IExternalTranslationContext ctx, CallConstructor src) 8 | { 9 | if (src.Info.DeclaringType == typeof(PhpDirectoryEntry)) 10 | { 11 | var a = ctx.TranslateValue(src.Arguments[0].MyValue); 12 | return a; 13 | } 14 | return null; 15 | } 16 | 17 | public int GetPriority() 18 | { 19 | return 1; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/Translator/Node/StringExtensionsTranslator.cs: -------------------------------------------------------------------------------- 1 | using Lang.Cs.Compiler; 2 | using System.Linq; 3 | using Lang.Php.Compiler.Source; 4 | 5 | namespace Lang.Php.Compiler.Translator.Node 6 | { 7 | public class StringExtensionsTranslator : IPhpNodeTranslator 8 | { 9 | public IPhpValue TranslateToPhp(IExternalTranslationContext ctx, CsharpMethodCallExpression src) 10 | { 11 | if (src.MethodInfo.DeclaringType != typeof (StringExtension)) return null; 12 | if (src.MethodInfo.Name != "PhpExplodeList") return null; 13 | var a = src.Arguments 14 | .Select(ctx.TranslateValue) 15 | .Cast() 16 | .ToArray(); 17 | 18 | 19 | 20 | var list = new PhpMethodCallExpression("list"); 21 | list.Arguments.AddRange(a.Skip(2)); 22 | foreach (var i in list.Arguments) 23 | i.ByRef = false; 24 | 25 | 26 | var explode = new PhpMethodCallExpression("explode"); 27 | explode.Arguments.Add(a[1]); 28 | explode.Arguments.Add(a[0]); 29 | 30 | var aa = new PhpAssignExpression(list, explode); 31 | return aa; 32 | 33 | 34 | // throw new NotSupportedException(); 35 | // throw new NotSupportedException(); 36 | } 37 | 38 | public int GetPriority() 39 | { 40 | return 2; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/Translator/Node/TimeSpanTranslator.cs: -------------------------------------------------------------------------------- 1 | using Lang.Cs.Compiler; 2 | using System; 3 | using Lang.Php.Compiler.Source; 4 | 5 | namespace Lang.Php.Compiler.Translator.Node 6 | { 7 | public class TimeSpanTranslator : IPhpNodeTranslator 8 | { 9 | public IPhpValue TranslateToPhp(IExternalTranslationContext ctx, CsharpInstancePropertyAccessExpression src) 10 | { 11 | if (src.Member.DeclaringType == typeof(TimeSpan)) 12 | { 13 | var to = ctx.TranslateValue(src.TargetObject); 14 | if (src.Member.Name == "TotalDays") { 15 | var aa = new PhpInstanceFieldAccessExpression("days", to, null); 16 | return aa; 17 | } 18 | throw new NotSupportedException(); 19 | } 20 | return null; 21 | } 22 | 23 | public int GetPriority() 24 | { 25 | return 1; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/Visibility.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Compiler 2 | { 3 | public enum Visibility 4 | { 5 | Public, 6 | Protected, 7 | Private 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/_CodeRequests/ClassCodeRequest.cs: -------------------------------------------------------------------------------- 1 | using Lang.Php.Compiler.Source; 2 | 3 | 4 | namespace Lang.Php.Compiler 5 | { 6 | public class ClassCodeRequest : ICodeRequest 7 | { 8 | /// 9 | /// Tworzy instancję obiektu 10 | /// 11 | /// 12 | public ClassCodeRequest(PhpQualifiedName className) 13 | { 14 | ClassName = className; 15 | } 16 | 17 | 18 | /// 19 | /// Zwraca tekstową reprezentację obiektu 20 | /// 21 | /// Tekstowa reprezentacja obiektu 22 | public override string ToString() 23 | { 24 | return "ClassCodeRequest ##PhpClassName##"; 25 | } 26 | 27 | /// 28 | /// 29 | public PhpQualifiedName ClassName { get; set; } 30 | } 31 | } -------------------------------------------------------------------------------- /Lang.Php.Compiler/_CodeRequests/GlobalVariableRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php.Compiler 4 | { 5 | 6 | public class GlobalVariableRequest : ICodeRequest 7 | { 8 | public override string ToString() 9 | { 10 | return string.Format("GlobalVariableRequest {0}", _variableName); 11 | } 12 | 13 | 14 | /// 15 | /// Tworzy instancję obiektu 16 | /// nazwa zmiennej globalnej 17 | /// 18 | public GlobalVariableRequest(string variableName) 19 | { 20 | VariableName = variableName; 21 | } 22 | 23 | /// 24 | /// nazwa zmiennej globalnej 25 | /// 26 | public string VariableName 27 | { 28 | get => _variableName; 29 | private set => _variableName = (value ?? String.Empty).Trim(); 30 | } 31 | private string _variableName = string.Empty; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/_CodeRequests/LocalVariableRequest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php.Compiler 4 | { 5 | public class LocalVariableRequest : ICodeRequest 6 | { 7 | /// 8 | /// Tworzy instancję obiektu 9 | /// nazwa zmiennej globalnej 10 | /// czy zmienna jest deklarowana jako argument funkcji 11 | /// akcja, która musi być wykonana przy zmianie nazwy zmiennej 12 | /// 13 | public LocalVariableRequest(string variableName, bool isArgument, Action changeNameAction) 14 | { 15 | VariableName = variableName; 16 | IsArgument = isArgument; 17 | ChangeNameAction = changeNameAction; 18 | } 19 | 20 | public override string ToString() 21 | { 22 | return string.Format("LocalVariableRequest {0}", _variableName); 23 | } 24 | 25 | /// 26 | /// nazwa zmiennej globalnej 27 | /// 28 | public string VariableName 29 | { 30 | get => _variableName; 31 | private set => _variableName = (value ?? string.Empty).Trim(); 32 | } 33 | 34 | /// 35 | /// czy zmienna jest deklarowana jako argument funkcji 36 | /// 37 | public bool IsArgument { get; set; } 38 | 39 | /// 40 | /// akcja, która musi być wykonana przy zmianie nazwy zmiennej 41 | /// 42 | public Action ChangeNameAction { get; set; } 43 | 44 | private string _variableName = string.Empty; 45 | } 46 | } -------------------------------------------------------------------------------- /Lang.Php.Compiler/_CodeRequests/ModuleCodeRequest.cs: -------------------------------------------------------------------------------- 1 | using Lang.Php.Compiler.Source; 2 | 3 | namespace Lang.Php.Compiler 4 | { 5 | public class ModuleCodeRequest : ICodeRequest 6 | { 7 | /// 8 | /// Tworzy instancję obiektu 9 | /// 10 | /// Why this Module is requested 11 | /// 12 | public ModuleCodeRequest(PhpCodeModuleName moduleName, string why) 13 | { 14 | ModuleName = moduleName; 15 | Why = why; 16 | } 17 | 18 | 19 | /// 20 | /// Zwraca tekstową reprezentację obiektu 21 | /// 22 | /// Tekstowa reprezentacja obiektu 23 | public override string ToString() 24 | { 25 | return string.Format("{0}", ModuleName); 26 | } 27 | 28 | /// 29 | /// Własność jest tylko do odczytu. 30 | /// 31 | public PhpCodeModuleName ModuleName { get; } 32 | 33 | /// 34 | /// Why this Module is requested; własność jest tylko do odczytu. 35 | /// 36 | public string Why { get; } = string.Empty; 37 | } 38 | } -------------------------------------------------------------------------------- /Lang.Php.Compiler/_TranslationInfo/KnownConstInfo.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Compiler 2 | { 3 | public class KnownConstInfo 4 | { 5 | public KnownConstInfo(string name, object value, bool useFixedValue) 6 | { 7 | if (!name.StartsWith("\\")) 8 | name = "\\" + name; 9 | Name = name; 10 | Value = value; 11 | UseFixedValue = useFixedValue; 12 | } 13 | 14 | /// 15 | /// Name of defined const 16 | /// 17 | public string Name { get; private set; } 18 | 19 | public object Value { get; set; } 20 | 21 | /// 22 | /// if true- const is not defined in cs2php.php and fixed value is used instead of const name 23 | /// if false- constant is defined in cs2php.php and it is used in expressions 24 | /// 25 | public bool UseFixedValue { get; private set; } 26 | } 27 | } -------------------------------------------------------------------------------- /Lang.Php.Compiler/_TranslationInfo/MethodTranslationInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace Lang.Php.Compiler 5 | { 6 | public class MethodTranslationInfo 7 | { 8 | public static MethodTranslationInfo FromMethodInfo(MethodBase methodInfo, 9 | ClassTranslationInfo classTranslationInfo) 10 | { 11 | var result = new MethodTranslationInfo 12 | { 13 | ScriptName = methodInfo.Name, 14 | ClassTi = classTranslationInfo 15 | }; 16 | var scriptNameAttribute = methodInfo.GetCustomAttribute(); 17 | if (scriptNameAttribute != null) 18 | result.ScriptName = scriptNameAttribute.Name.Trim(); 19 | if (string.IsNullOrEmpty(result.ScriptName)) 20 | throw new Exception("Method name is empty"); 21 | return result; 22 | } 23 | 24 | /// 25 | /// Własność jest tylko do odczytu. 26 | /// 27 | public string ScriptName { get; private set; } = string.Empty; 28 | 29 | /// 30 | /// Własność jest tylko do odczytu. 31 | /// 32 | public ClassTranslationInfo ClassTi { get; private set; } 33 | } 34 | } -------------------------------------------------------------------------------- /Lang.Php.Compiler/_TranslationInfo/NodeTranslatorsContainer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Lang.Cs.Compiler; 5 | 6 | // ReSharper disable once CheckNamespace 7 | namespace Lang.Php.Compiler 8 | { 9 | /// 10 | /// Przechowuje kolekcje translatorów dla różnych typów gałęzi 11 | /// 12 | public class NodeTranslatorsContainer 13 | { 14 | private static int? GetNodeTranslatorBoundPriority(NodeTranslatorBound i) 15 | { 16 | // use this named method insead of lambda for performace reasons 17 | return i.Priority; 18 | } 19 | // Public Methods 20 | 21 | public void Add(Type t, NodeTranslatorBound b) 22 | { 23 | List x; 24 | if (!_items.TryGetValue(t, out x)) 25 | _items[t] = x = new List(); 26 | x.Add(b); 27 | } 28 | 29 | public IPhpValue Translate(IExternalTranslationContext ctx, T node) where T : IValue 30 | { 31 | List x; 32 | if (!_items.TryGetValue(typeof(T), out x)) 33 | return null; 34 | var hh = x.OrderBy(GetNodeTranslatorBoundPriority).ToArray(); 35 | // ReSharper disable once LoopCanBeConvertedToQuery 36 | foreach (var i in hh) 37 | { 38 | var y = i.Translate(ctx, node); 39 | if (y != null) 40 | return y; 41 | } 42 | 43 | return null; 44 | } 45 | 46 | private readonly Dictionary> _items = 47 | new Dictionary>(); 48 | } 49 | } -------------------------------------------------------------------------------- /Lang.Php.Compiler/_TranslationInfo/TranslationMessage.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Compiler 2 | { 3 | public class TranslationMessage 4 | { 5 | public TranslationMessage(string text, MessageLevels level) 6 | { 7 | Text = text; 8 | Level = level; 9 | } 10 | public string Text { get; private set; } 11 | public MessageLevels Level { get; private set; } 12 | 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/_enum/EmitStyleCompression.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Compiler 2 | { 3 | public enum EmitStyleCompression 4 | { 5 | Beauty, 6 | Compact, 7 | NearCrypto 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/_enum/FieldTranslationDestionations.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Compiler 2 | { 3 | public enum FieldTranslationDestionations 4 | { 5 | NormalField, 6 | DefinedConst, 7 | GlobalVariable, 8 | JustValue, 9 | ClassConst 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/_enum/MessageLevels.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Compiler 2 | { 3 | public enum MessageLevels 4 | { 5 | Info, 6 | Warning, 7 | Error 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/_enum/PhpVariableKind.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Compiler 2 | { 3 | public enum PhpVariableKind 4 | { 5 | Local, 6 | LocalArgument, 7 | Global 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/_enum/ShowBracketsEnum.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Compiler 2 | { 3 | public enum ShowBracketsEnum 4 | { 5 | Always, 6 | IfManyItems, 7 | IfManyItems_OR_IfStatement, 8 | Never 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/_enum/StatementEmitInfo.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Compiler 2 | { 3 | public enum StatementEmitInfo 4 | { 5 | NormalSingleStatement, 6 | Empty, 7 | ManyItemsOrPlainHtml 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/_interfaces/ICodeRelated.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | // ReSharper disable once CheckNamespace 4 | namespace Lang.Php.Compiler 5 | { 6 | 7 | /// 8 | /// Interfejs obiektu, który może żądać dostępu do innych obiektów, np. include modułu 9 | /// 10 | public interface ICodeRelated 11 | { 12 | /// 13 | /// Zwraca listę żądań o dostęp do innych elementów kodu 14 | /// 15 | /// 16 | IEnumerable GetCodeRequests(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/_interfaces/ICodeRequest.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Compiler 2 | { 3 | public interface ICodeRequest 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/_interfaces/IEmitable.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Compiler 2 | { 3 | public interface IEmitable 4 | { 5 | void Emit(PhpSourceCodeEmiter emiter, PhpSourceCodeWriter writer, PhpEmitStyle style); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/_interfaces/IExternalTranslationContext.cs: -------------------------------------------------------------------------------- 1 | using Lang.Cs.Compiler; 2 | using Lang.Php.Compiler.Translator; 3 | using System; 4 | 5 | namespace Lang.Php.Compiler 6 | { 7 | public interface IExternalTranslationContext 8 | { 9 | IPhpValue TranslateValue(IValue srcValue); 10 | TranslationInfo GetTranslationInfo(); 11 | 12 | ClassReplaceInfo FindOneClassReplacer(Type srcType); 13 | 14 | Version PhpVersion { get; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/_interfaces/IModuleProcessor.cs: -------------------------------------------------------------------------------- 1 | using Lang.Php.Compiler.Source; 2 | 3 | namespace Lang.Php.Compiler 4 | { 5 | public interface IModuleProcessor 6 | { 7 | void BeforeEmit(PhpCodeModule module, TranslationInfo info); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/_interfaces/IPhpClassMember.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Compiler 2 | { 3 | public interface IPhpClassMember 4 | { 5 | Visibility Visibility { get; } 6 | bool IsStatic { get; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/_interfaces/IPhpExpressionSimplifier.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Compiler 2 | { 3 | public interface IPhpExpressionSimplifier 4 | { 5 | IPhpValue Simplify(IPhpValue src); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/_interfaces/IPhpNodeTranslator.cs: -------------------------------------------------------------------------------- 1 | using Lang.Cs.Compiler; 2 | 3 | namespace Lang.Php.Compiler 4 | { 5 | public interface IPhpNodeTranslator where T : IValue 6 | { 7 | 8 | IPhpValue TranslateToPhp(IExternalTranslationContext ctx, T src); 9 | int GetPriority(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/_interfaces/IPhpSimplifier.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Compiler 2 | { 3 | public interface IPhpSimplifier:IPhpExpressionSimplifier 4 | { 5 | 6 | IPhpStatement Simplify(IPhpStatement src); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/_interfaces/IPhpStatement.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable once CheckNamespace 2 | namespace Lang.Php.Compiler 3 | { 4 | public interface IPhpStatement : ICodeRelated, IEmitable 5 | { 6 | StatementEmitInfo GetStatementEmitInfo(PhpEmitStyle style); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/_interfaces/IPhpValue.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Compiler 2 | { 3 | public interface IPhpValue : ICodeRelated 4 | { 5 | string GetPhpCode(PhpEmitStyle style); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Lang.Php.Compiler/key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isukces/cs2php/7c817438b8e0fb004867fe70d20e09c3d3ba038e/Lang.Php.Compiler/key.snk -------------------------------------------------------------------------------- /Lang.Php.Framework/Extension.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Framework 2 | { 3 | public static class Extension 4 | { 5 | 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Lang.Php.Framework/Lang.Php.Framework.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2.1.1 4 | net472 5 | Lang.Php.Framework 6 | Lang.Php.Framework 7 | .NET mapped classes 8 | .NET mapped classes 9 | true 10 | true 11 | false 12 | true 13 | false 14 | false 15 | false 16 | false 17 | false 18 | false 19 | True 20 | 21 | 22 | bin\$(Configuration)\net472\$(ProjectName).xml 23 | 24 | 25 | 26 | CommonAssemblyInfo.cs 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Lang.Php.Framework/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: AssemblyDescription(".NET mapped classes")] 5 | [assembly: Guid("68b245db-ae2b-44a6-a4c8-76c275a1b468")] 6 | -------------------------------------------------------------------------------- /Lang.Php.Framework/Replacers/CharReplacer.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Framework.Replacers 2 | { 3 | [Replace(typeof(char))] 4 | class CharReplacer 5 | { 6 | [DirectCall("", "this")] 7 | public override string ToString() 8 | { 9 | throw new MockMethodException(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Lang.Php.Framework/Replacers/IntReplacer.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Framework.Replacers 2 | { 3 | [Replace(typeof(int))] 4 | class IntReplacer 5 | { 6 | [DirectCall("", "0")] 7 | public static int Parse(string s) 8 | { 9 | return int.Parse(s); 10 | } 11 | 12 | [DirectCall("","this")] 13 | public override string ToString() 14 | { 15 | throw new MockMethodException(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Lang.Php.Framework/Replacers/KeyValuePairReplacer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Lang.Php.Framework.Replacers 4 | { 5 | 6 | [Replace(typeof(KeyValuePair<,>))] 7 | class KeyValuePairReplacer 8 | { 9 | 10 | //// [UseTranslator("Lang.Php.Compiler.Translator.AdvancedTranslator", "__KeyValue__PseudoTranslate")] 11 | //public TKey Key { get; set; } 12 | //// [UseTranslator("Lang.Php.Compiler.Translator.AdvancedTranslator", "__KeyValue__PseudoTranslate")] 13 | //public TValue Value { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Lang.Php.Framework/Replacers/ListReplacer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Lang.Php.Framework.Replacers 4 | { 5 | [Replace(typeof(List<>))] 6 | [Replace(typeof(IList<>))] 7 | [Replace(typeof(ICollection<>))] 8 | class ListReplacer 9 | { 10 | 11 | [DirectCall("array_push", "this,0")] 12 | public void Add(TValue item) 13 | { 14 | //int array_push ( array &$array , mixed $value1 [, mixed $... ] ) 15 | throw new MockMethodException(); 16 | } 17 | 18 | [DirectCall("count", "this")] 19 | public int Count 20 | { 21 | get 22 | { 23 | throw new MockMethodException(); 24 | } 25 | } 26 | 27 | //[Translator] 28 | //public static object __Translate(IExternalTranslationContext ctx, object src1) 29 | //{ 30 | // CallConstructor src = src1 as CallConstructor; 31 | // if (src == null) return null; 32 | // if (src.Arguments.Length != 0) 33 | // throw new NotSupportedException(); 34 | // var g = new PhpArrayCreateExpression(); 35 | // return g; 36 | //} 37 | 38 | [DirectCall("", "this")] 39 | public TValue[] ToArray() 40 | { 41 | throw new MockMethodException(); 42 | } 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Lang.Php.Framework/Replacers/ObjectReplacer.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Framework.Replacers 2 | { 3 | 4 | [Replace(typeof(object))] 5 | class ObjectReplacer 6 | { 7 | [DirectCall("", "this")] 8 | public override string ToString() 9 | { 10 | throw new MockMethodException(); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Lang.Php.Framework/Replacers/StackReplacer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Lang.Php.Framework.Replacers 4 | { 5 | [Replace(typeof(Stack<>))] 6 | public class StackReplacer 7 | { 8 | [DirectCall("count", "this")] 9 | public int Count 10 | { 11 | get; 12 | set; 13 | } 14 | 15 | [DirectCall("array_push", "this,0")] 16 | public void Push(T item) 17 | { 18 | // int array_push ( array &$array , mixed $value1 [, mixed $... ] ) 19 | } 20 | 21 | [DirectCall("NOT_SUPPORTED", "this")] 22 | public string Peek() 23 | { 24 | return ""; 25 | } 26 | 27 | [DirectCall("array_pop", "this")] 28 | public string Pop() 29 | { 30 | return ""; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Lang.Php.Framework/key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isukces/cs2php/7c817438b8e0fb004867fe70d20e09c3d3ba038e/Lang.Php.Framework/key.snk -------------------------------------------------------------------------------- /Lang.Php.Test/Code/SampleEmptyClass.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Test.Code 2 | { 3 | [IgnoreNamespace] 4 | public class SampleEmptyClass 5 | { 6 | public string InstanceField1; 7 | 8 | [ScriptName("instanceField2")] 9 | public string InstanceField2; 10 | 11 | public static int ClassField1; 12 | [ScriptName("classField2")] 13 | public static int ClassField2; 14 | 15 | [GlobalVariable] 16 | public static int ClassField3AsGlobalVariable; 17 | [GlobalVariable] 18 | [ScriptName("classField4")] 19 | [Module("settings.php")] 20 | public static int ClassField4AsGlobalVariable; 21 | 22 | 23 | public const string Const1 = "1"; 24 | [AsDefinedConst] 25 | public const string Const2 = "2"; 26 | [AsValue] 27 | public const string Const3 = "3"; 28 | 29 | [ScriptName("xConst4")] 30 | public const string Const4 = "4"; 31 | [ScriptName("xConst5")] 32 | [AsDefinedConst] 33 | public const string Const5 = "5"; 34 | 35 | [ScriptName("xConst6")] 36 | [AsValue] 37 | public const string Const6 = "6"; 38 | 39 | public void Test1() 40 | { 41 | var co = Const1; 42 | co = Const2; 43 | co = Const3; 44 | co = Const4; 45 | co = Const5; 46 | co = Const6; 47 | var i = InstanceField1; 48 | i = InstanceField2; 49 | 50 | var c = ClassField1; 51 | c = ClassField2; 52 | c = ClassField3AsGlobalVariable; 53 | c = ClassField4AsGlobalVariable; 54 | 55 | ClassField1 = 1; 56 | ClassField2 = 2; 57 | ClassField3AsGlobalVariable = 3; 58 | ClassField4AsGlobalVariable = 4; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Lang.Php.Test/Lang.Php.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2.1.1 4 | net472 5 | Lang.Php.Test 6 | Lang.Php.Test 7 | Lang.Php.Test 8 | Lang.Php.Test 9 | true 10 | true 11 | false 12 | true 13 | false 14 | false 15 | false 16 | false 17 | false 18 | false 19 | false 20 | 21 | 22 | bin\$(Configuration)\net472\$(ProjectName).xml 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Lang.Php.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: Guid("F18A71C2-DE6A-4DDD-83FD-A1808688DFDA")] -------------------------------------------------------------------------------- /Lang.Php.Test/php/MyCodePhp_BasicMath1.txt: -------------------------------------------------------------------------------- 1 | public static function BasicMath1() { 2 | $a = 1; 3 | $b = 2; 4 | $d = ($a + $b) / M_PI; 5 | } -------------------------------------------------------------------------------- /Lang.Php.Test/php/MyCodePhp_Collections.txt: -------------------------------------------------------------------------------- 1 | public static function Collections() { 2 | $list = array(); 3 | foreach($list as $i) 4 | echo $i; 5 | $count = count($list); 6 | $dict = array(); 7 | foreach($dict as $i__Key => $i__Value) 8 | echo $i__Key . ' ' . $i__Value; 9 | foreach(array_values($dict) as $i) 10 | echo $i; 11 | foreach(array_keys($dict) as $i) 12 | echo $i; 13 | $count = count($dict); 14 | $stack = array(); 15 | array_push($stack, 'X'); 16 | array_push($stack, 'Y'); 17 | $s1 = $stack[count($stack) - 1]; 18 | $s2 = array_pop($stack); 19 | $count = count($stack); 20 | } -------------------------------------------------------------------------------- /Lang.Php.Test/php/MyCodePhp_CostantsAndVariables.txt: -------------------------------------------------------------------------------- 1 | public static function CostantsAndVariables() { 2 | $a = null; 3 | $b = 18; 4 | $c = 1.2; 5 | $pi = M_PI; 6 | $h = 'Some text backslash\\ quote" single\' dollar$'; 7 | $jacob = '\\anything'; 8 | $x = 'test {h}'; 9 | } -------------------------------------------------------------------------------- /Lang.Php.Test/php/MyCodePhp_Filters.txt: -------------------------------------------------------------------------------- 1 | public static function Filters() { 2 | global $_GET, $_POST; 3 | $a = filter_var($_GET['ipAddress'], FILTER_VALIDATE_IP); 4 | $b = filter_var($_GET['ipAddress'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6); 5 | $defaultValue = array('default' => '1.2.3.4'); 6 | $c1 = filter_var($_GET['ipAddress'], FILTER_VALIDATE_IP, array('options' => $defaultValue, 'flags' => FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6)); 7 | $c = filter_var($_GET['ipAddress'], FILTER_VALIDATE_IP, array('options' => array('default' => '1.2.3.4'), 'flags' => FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6)); 8 | $d = filter_var($_POST['aaa'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); 9 | $e = filter_var($_POST['aaa'], FILTER_VALIDATE_BOOLEAN, array('default' => false)); 10 | $clientIp = filter_input(INPUT_SERVER, 'HTTP_CLIENT_IP', FILTER_VALIDATE_IP); 11 | $other = filter_input(INPUT_GET, 'Somename', FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); 12 | } -------------------------------------------------------------------------------- /Lang.Php.Test/php/MyCodePhp_PregTest.txt: -------------------------------------------------------------------------------- 1 | public static function PregTest() { 2 | $a = preg_match('/hello/i', 'a Hello x', $matches, 2); 3 | $b = preg_match('/hello/i', 'a Hello x'); 4 | $c = preg_match('/hello/i', 'ó Hello world', $matchWithOffsets, PREG_OFFSET_CAPTURE); 5 | echo 'We have ' . $matchWithOffsets[0][0] . ' at ' . $matchWithOffsets[0][1]; 6 | } -------------------------------------------------------------------------------- /Lang.Php.Test/php/MyCodePhp_StringConcats.txt: -------------------------------------------------------------------------------- 1 | public static function StringConcats() { 2 | $x = 3; 3 | $a = 'ab'; 4 | $b = 'a' . ($x / 2 < 10 ? 'b' : 'c'); 5 | $c = 'a' . ($x / 2 < 10 ? 'b' : 'c') . 'd'; 6 | } -------------------------------------------------------------------------------- /Lang.Php.Test/php/module-Lang_Php_Test_Code_BusinessClass.txt: -------------------------------------------------------------------------------- 1 | /* 2 | Generated with CS2PHP 3 | */ 4 | class BusinessClass { 5 | public static $ClassProperty; 6 | public static $ClassField; 7 | public $InstanceProperty; 8 | public $InstanceField; 9 | } -------------------------------------------------------------------------------- /Lang.Php.Test/php/module-Lang_Php_Test_Code_BusinessClassDefinedConst.txt: -------------------------------------------------------------------------------- 1 | /* 2 | Generated with CS2PHP 3 | */ 4 | if (!defined('ClassFieldDefinedConst')) 5 | define('ClassFieldDefinedConst', 3); -------------------------------------------------------------------------------- /Lang.Php.Test/php/module-Lang_Php_Test_Code_BusinessClassGlobalVariable.txt: -------------------------------------------------------------------------------- 1 | /* 2 | Generated with CS2PHP 3 | */ 4 | $ClassFieldGlobalVariable = 3; -------------------------------------------------------------------------------- /Lang.Php.Test/php/module-Lang_Php_Test_Code_IncludeClassFieldAccess.txt: -------------------------------------------------------------------------------- 1 | /* 2 | Generated with CS2PHP 3 | */ 4 | require_once(dirname(__FILE__) . '/Lang_Php_Test_Code_BusinessClassDefinedConst.php'); 5 | require_once(dirname(__FILE__) . '/other-module-BusinessClassDefinedConst.php'); 6 | require_once(dirname(__FILE__) . '/Lang_Php_Test_Code_BusinessClass.php'); 7 | class IncludeClassFieldAccess { 8 | public function X() { 9 | global $ClassFieldGlobalVariable; 10 | $a = BusinessClass::$ClassField; 11 | $b1 = ClassFieldDefinedConst; 12 | $b2 = ClassFieldDefinedConstInOtherModule; 13 | $c = $ClassFieldGlobalVariable; 14 | } 15 | } -------------------------------------------------------------------------------- /Lang.Php.Test/php/module-Lang_Php_Test_Code_IncludeClassPropertyAccess.txt: -------------------------------------------------------------------------------- 1 | /* 2 | Generated with CS2PHP 3 | */ 4 | require_once(dirname(__FILE__) . '/Lang_Php_Test_Code_BusinessClass.php'); 5 | class IncludeClassPropertyAccess { 6 | public function X() { 7 | $a = BusinessClass::$ClassProperty; 8 | } 9 | } -------------------------------------------------------------------------------- /Lang.Php.Test/php/module-Lang_Php_Test_Code_IncludeInstanceFieldAccess.txt: -------------------------------------------------------------------------------- 1 | /* 2 | Generated with CS2PHP 3 | */ 4 | require_once(dirname(__FILE__) . '/Lang_Php_Test_Code_BusinessClass.php'); 5 | class IncludeInstanceFieldAccess { 6 | public function X() { 7 | $a = new BusinessClass()->InstanceField; 8 | } 9 | } -------------------------------------------------------------------------------- /Lang.Php.Test/php/module-Lang_Php_Test_Code_IncludeInstancePropertyAccess.txt: -------------------------------------------------------------------------------- 1 | /* 2 | Generated with CS2PHP 3 | */ 4 | class IncludeInstancePropertyAccess { 5 | public function X() { 6 | $a = new BusinessClass()->InstanceProperty; 7 | } 8 | } -------------------------------------------------------------------------------- /Lang.Php.Test/php/module-Lang_Php_Test_Code_IncludeShouldNotIncludeOther.txt: -------------------------------------------------------------------------------- 1 | /* 2 | Generated with CS2PHP 3 | */ 4 | class IncludeShouldNotIncludeOther { 5 | public function X() { 6 | $a = PHP_EOL; 7 | } 8 | } -------------------------------------------------------------------------------- /Lang.Php.Test/php/module-Lang_Php_Test_Code_SampleEmptyClass.txt: -------------------------------------------------------------------------------- 1 | /* 2 | Generated with CS2PHP 3 | */ 4 | if (!defined('Const2')) 5 | define('Const2', '2'); 6 | if (!defined('xConst5')) 7 | define('xConst5', '5'); 8 | class SampleEmptyClass { 9 | const Const1 = '1'; 10 | const xConst4 = '4'; 11 | public static $ClassField1; 12 | public static $classField2; 13 | public $InstanceField1; 14 | public $instanceField2; 15 | public function Test1() { 16 | global $ClassField3AsGlobalVariable, $classField4; 17 | $co = self::Const1; 18 | $co = Const2; 19 | $co = '3'; 20 | $co = self::xConst4; 21 | $co = xConst5; 22 | $co = '6'; 23 | $i = $this->InstanceField1; 24 | $i = $this->instanceField2; 25 | $c = self::$ClassField1; 26 | $c = self::$classField2; 27 | $c = $ClassField3AsGlobalVariable; 28 | $c = $classField4; 29 | self::$ClassField1 = 1; 30 | self::$classField2 = 2; 31 | $ClassField3AsGlobalVariable = 3; 32 | $classField4 = 4; 33 | } 34 | } -------------------------------------------------------------------------------- /Lang.Php.Test/php/module-other-module-BusinessClassDefinedConst.txt: -------------------------------------------------------------------------------- 1 | /* 2 | Generated with CS2PHP 3 | */ 4 | if (!defined('ClassFieldDefinedConstInOtherModule')) 5 | define('ClassFieldDefinedConstInOtherModule', 3); -------------------------------------------------------------------------------- /Lang.Php.Utils/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Lang.Php.Utils")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Lang.Php.Utils")] 13 | [assembly: AssemblyCopyright("Copyright © 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("a85ca927-e81f-4758-b63a-e03649fc0035")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | 38 | 39 | [assembly: Lang.Php.ModuleIncludeConst("$LANG_PHP_UTILS_PATH")] 40 | -------------------------------------------------------------------------------- /Lang.Php.Utils/key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isukces/cs2php/7c817438b8e0fb004867fe70d20e09c3d3ba038e/Lang.Php.Utils/key.snk -------------------------------------------------------------------------------- /Lang.Php.Webserver/App.xaml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Lang.Php.Webserver/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace Lang.Php.Webserver 4 | { 5 | /// 6 | /// Interaction logic for App.xaml 7 | /// 8 | public partial class App : Application 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Lang.Php.Webserver/MainWindow.xaml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Lang.Php.Webserver/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Windows; 5 | using Path = System.IO.Path; 6 | 7 | namespace Lang.Php.Webserver 8 | { 9 | /// 10 | /// Interaction logic for MainWindow.xaml 11 | /// 12 | public partial class MainWindow : Window 13 | { 14 | public MainWindow() 15 | { 16 | InitializeComponent(); 17 | { 18 | HttpRequest r = HttpRequest.Parse(HttpRequest.Example); 19 | } 20 | { 21 | ServerEngine e = ServerEngine.Instance; 22 | e.DocumentRoot = Path.Combine( 23 | Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), 24 | "cs2php", 25 | "webserver"); 26 | 27 | e.OnLog += e_OnLog; 28 | string[] args = Environment.GetCommandLineArgs(); 29 | foreach (var i in args.Skip(1)) 30 | e.Load(i); 31 | e.ListenPort = 11000; 32 | e.StartListening(); 33 | } 34 | } 35 | 36 | List loglines = new List(); 37 | void e_OnLog(object sender, ServerEngine.OnLogEventArgs e) 38 | { 39 | loglines.Add(e.Text); 40 | if (loglines.Count > 100) 41 | loglines.RemoveAt(0); 42 | string t = string.Join("\r\n", loglines.AsEnumerable().Reverse()); 43 | 44 | Dispatcher.Invoke( 45 | () => log.Text = t 46 | ); 47 | 48 | } 49 | 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Lang.Php.Webserver/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Lang.Php.Webserver.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.1.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Lang.Php.Webserver/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Lang.Php.Webserver/Request.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Webserver 2 | { 3 | [Skip] 4 | public class Request 5 | { 6 | public static HttpRequest RuntimeRequest; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Lang.Php.Webserver/StateObject.cs: -------------------------------------------------------------------------------- 1 | using System.Net.Sockets; 2 | using System.Text; 3 | 4 | namespace Lang.Php.Webserver 5 | { 6 | class StateObject 7 | { 8 | // Client socket. 9 | public Socket workSocket = null; 10 | // Size of receive buffer. 11 | public const int BufferSize = 1024; 12 | // Receive buffer. 13 | public byte[] buffer = new byte[BufferSize]; 14 | // Received data string. 15 | public StringBuilder sb = new StringBuilder(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Lang.Php.XUnitTests/AppConfigTest.cs: -------------------------------------------------------------------------------- 1 | using Lang.Php.Compiler; 2 | using Xunit; 3 | 4 | namespace Lang.Php.XUnitTests 5 | { 6 | public class AppConfigTest 7 | { 8 | [Fact] 9 | public static void Basic() 10 | { 11 | using (var x = new AppConfigManipulator()) 12 | { 13 | 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Lang.Php.XUnitTests/InheritanceTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Lang.Php.Compiler; 5 | using Xunit; 6 | 7 | namespace Lang.Php.XUnitTests 8 | { 9 | public class InheritanceTests 10 | { 11 | private class SampleIPhpStatement : IPhpStatement 12 | { 13 | public IEnumerable GetCodeRequests() 14 | { 15 | throw new NotImplementedException(); 16 | } 17 | 18 | public void Emit(PhpSourceCodeEmiter emiter, PhpSourceCodeWriter writer, PhpEmitStyle style) 19 | { 20 | throw new NotImplementedException(); 21 | } 22 | 23 | public StatementEmitInfo GetStatementEmitInfo(PhpEmitStyle style) 24 | { 25 | throw new NotImplementedException(); 26 | } 27 | } 28 | 29 | [Fact] 30 | public static void TestICodeRelated() 31 | { 32 | var a = new SampleIPhpStatement(); 33 | Assert.True(a is ICodeRelated); 34 | 35 | var types = from assembly in AppDomain.CurrentDomain.GetAssemblies() 36 | from type in assembly.GetTypes() 37 | select type; 38 | foreach (var type in types) 39 | { 40 | var g = type.GetInterfaces(); 41 | if (g.FirstOrDefault(q => q == typeof (IPhpStatement)) != null) 42 | { 43 | if (g.FirstOrDefault(q => q == typeof(ICodeRelated)) == null) 44 | { 45 | throw new Exception(string.Format("type {0} implements IPhpStatement but not ICodeRequest", type)); 46 | } 47 | } 48 | } 49 | 50 | 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Lang.Php.XUnitTests/Lang.Php.XUnitTest.xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "appDomain": "denied", 3 | "diagnosticMessages": true, 4 | "methodDisplay": "method" 5 | } -------------------------------------------------------------------------------- /Lang.Php.XUnitTests/Program.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.XUnitTests 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | new BasicTests().CSharpProject(); 8 | new BasicTests().Compile(); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Lang.Php.XUnitTests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: Guid("4e0e1823-9044-49cb-aad6-dde7510d4b75")] 5 | -------------------------------------------------------------------------------- /Lang.Php/Data/FieldGroupAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php.Data 4 | { 5 | 6 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)] 7 | public class FieldGroupAttribute : Attribute 8 | { 9 | public FieldGroupAttribute(string GroupName) 10 | { 11 | this.GroupName = GroupName; 12 | } 13 | public string GroupName { get; private set; } 14 | 15 | /// 16 | /// Suggested field name for autoincrement fieldor property 17 | /// 18 | public const string AUTOINCREMENT = "autoincrement"; 19 | /// 20 | /// Suggested field name for immutable field or property 21 | /// 22 | public const string IMMUTABLE = "immutable"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Lang.Php/Filters/FilterVar.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php.Filters 4 | { 5 | public class FilterVar 6 | { 7 | public static bool? ValidateBoolean(object value) 8 | { 9 | throw new NotImplementedException(); 10 | } 11 | public static bool ValidateBoolean(object value, bool defaultValue) 12 | { 13 | throw new NotImplementedException(); 14 | } 15 | 16 | 17 | public static string ValidateIp(object value, IpFlags flags = 0, IpOptions options = null) 18 | { 19 | throw new NotImplementedException(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Lang.Php/Filters/KnownFilters.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Filters 2 | { 3 | [EnumRender(EnumRenderOptions.UnderscoreUppercase, true)] 4 | public enum KnownFilters 5 | { 6 | FilterValidateBoolean, 7 | FilterValidateEmail, 8 | FilterValidateFloat, 9 | FilterValidateInt, 10 | FilterValidateIp, 11 | FilterValidateRegexp, 12 | FilterValidateUrl 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Lang.Php/Filters/_flags/IntFlags.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php.Filters 4 | { 5 | [Flags] 6 | public enum IntFlags 7 | { 8 | /// 9 | /// Regards inputs starting with a zero (0) as octal numbers. 10 | /// This only allows the succeeding digits to be 0-7. 11 | /// 12 | [RenderValue("FILTER_FLAG_ALLOW_OCTAL")] 13 | AllowOctal, 14 | 15 | /// 16 | /// Regards inputs starting with 0x or 0X as hexadecimal numbers. 17 | /// This only allows succeeding characters to be a-fA-F0-9. 18 | /// 19 | [RenderValue("FILTER_FLAG_ALLOW_HEX")] 20 | AllowHex 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Lang.Php/Filters/_flags/IpFlags.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php.Filters 4 | { 5 | [Flags] 6 | public enum IpFlags 7 | { 8 | /// 9 | /// Allows the IP address to be in IPv4 format. 10 | /// 11 | [RenderValue("FILTER_FLAG_IPV4")] 12 | IpV4, 13 | 14 | /// 15 | /// Allows the IP address to be in IPv6 format. 16 | /// 17 | [RenderValue("FILTER_FLAG_IPV6")] 18 | IpV6, 19 | 20 | /// 21 | /// Fails validation for the following private IPv4 ranges: 22 | /// 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. 23 | /// Fails validation for the IPv6 addresses starting with FD or FC. 24 | /// 25 | [RenderValue("FILTER_FLAG_NO_PRIV_RANGE")] 26 | NoPrivRange, 27 | 28 | /// 29 | /// Fails validation for the following reserved IPv4 ranges: 30 | /// 0.0.0.0/8, 169.254.0.0/16, 192.0.2.0/24 and 224.0.0.0/4. 31 | /// This flag does not apply to IPv6 addresses. 32 | /// 33 | [RenderValue("FILTER_FLAG_NO_RES_RANGE")] 34 | NoResRange 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Lang.Php/Filters/_flags/UrlFlags.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php.Filters 4 | { 5 | [Flags] 6 | public enum UrlFlags 7 | { 8 | [RenderValue("FILTER_FLAG_PATH_REQUIRED")] 9 | PathRequired, 10 | [RenderValue("FILTER_FLAG_QUERY_REQUIRED")] 11 | QueryRequired 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Lang.Php/Filters/_options/EmailOptions.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Filters 2 | { 3 | 4 | [AsArray] 5 | public class EmailOptions 6 | { 7 | [ScriptName("default")] 8 | public string Default; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Lang.Php/Filters/_options/FloatOptions.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Filters 2 | { 3 | [AsArray] 4 | public class FloatOptions 5 | { 6 | [ScriptName("default")] 7 | public double Default; 8 | [ScriptName("decimal")] 9 | public string DecimalSeparator; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Lang.Php/Filters/_options/IntOptions.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Filters 2 | { 3 | [AsArray] 4 | public class IntOptions 5 | { 6 | [ScriptName("default")] 7 | public int Default; 8 | [ScriptName("min_range")] 9 | public int MinRange; 10 | [ScriptName("max_range")] 11 | public int MaxRange; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Lang.Php/Filters/_options/IpOptions.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Filters 2 | { 3 | [AsArray] 4 | public class IpOptions 5 | { 6 | [ScriptName("default")] 7 | public string Default; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Lang.Php/Filters/_options/RegExpOptions.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Filters 2 | { 3 | [AsArray] 4 | public class RegExpOptions 5 | { 6 | [ScriptName("default")] 7 | public string Default; 8 | [ScriptName("regexp")] 9 | public string Regexp; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Lang.Php/Filters/_options/UrlOptions.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Filters 2 | { 3 | [AsArray] 4 | public class UrlOptions 5 | { 6 | [ScriptName("default")] 7 | public string Default; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Lang.Php/GlobalMethods.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php 2 | { 3 | [Skip] 4 | class GlobalMethods 5 | { 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Lang.Php/Graph/Color.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Graph 2 | { 3 | [Skip] 4 | public class Color 5 | { 6 | [UseBinaryExpression("!==", "false", "$0")] 7 | public static bool IsValid(Color image) 8 | { 9 | return image != null; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Lang.Php/Graph/Font.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Graph 2 | { 3 | [Skip] 4 | public class Font 5 | { 6 | public static Font Font1; 7 | public static Font Font2; 8 | public static Font Font3; 9 | public static Font Font4; 10 | public static Font Font5; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Lang.Php/Graph/ImageInfo.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Graph 2 | { 3 | [AsArray] 4 | public class ImageInfo 5 | { 6 | /* 7 | array (size=7) 8 | 0 => int 3456 9 | 1 => int 2592 10 | 2 => int 2 11 | 3 => string 'width="3456" height="2592"' (length=26) 12 | 'bits' => int 8 13 | 'channels' => int 3 14 | 'mime' => string 'image/jpeg' (length=10) 15 | */ 16 | [ScriptName("0")] 17 | public int Width; 18 | [ScriptName("1")] 19 | public int Height; 20 | [ScriptName("2")] 21 | public ImageTypes ImageType; 22 | 23 | /// 24 | /// i.e. 'width="3456" height="2592"' 25 | /// 26 | [ScriptName("3")] 27 | public string HtmlWidthHeight; 28 | 29 | [ScriptName("bits")] 30 | public int Bits; 31 | [ScriptName("channels")] 32 | public int Channels; 33 | /// 34 | /// i.e. 'image/jpeg' 35 | /// 36 | [ScriptName("mime")] 37 | public string Mime; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Lang.Php/Graph/_enums/ImageTypes.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Graph 2 | { 3 | public enum ImageTypes 4 | { 5 | [RenderValue("0")] 6 | Unknown = 0, 7 | [RenderValue("IMG_GIF")] 8 | Gif = 1, 9 | [RenderValue("IMG_JPG")] 10 | Jpeg = 2, 11 | [RenderValue("IMAGETYPE_PNG")] 12 | Png = 3, 13 | [RenderValue("IMAGETYPE_SWF")] 14 | Swf = 4, 15 | [RenderValue("IMAGETYPE_PSD")] 16 | Psd = 5, 17 | [RenderValue("IMAGETYPE_BMP")] 18 | Bmp = 6, 19 | [RenderValue("IMAGETYPE_TIFF_II")] 20 | Tiff_Ii = 7, 21 | [RenderValue("IMAGETYPE_TIFF_MM")] 22 | Tiff_Mm = 8, 23 | [RenderValue("IMAGETYPE_JPC")] 24 | Jpc = 9, 25 | [RenderValue("IMAGETYPE_JP2")] 26 | Jp2 = 10, 27 | [RenderValue("IMAGETYPE_JPX")] 28 | Jpx = 11, 29 | [RenderValue("IMAGETYPE_JB2")] 30 | Jb2 = 12, 31 | [RenderValue("IMAGETYPE_SWC")] 32 | Swc = 13, 33 | [RenderValue("IMAGETYPE_IFF")] 34 | Iff = 14, 35 | [RenderValue("IMAGETYPE_WBMP")] 36 | Wbmp = 15, 37 | [RenderValue("IMAGETYPE_XBM")] 38 | Xbm = 16, 39 | [RenderValue("IMAGETYPE_ICO")] 40 | Ico = 17, 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Lang.Php/MbPhpString.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php 2 | { 3 | public class MbPhpString 4 | { 5 | #region Methods 6 | 7 | // Public Methods 8 | 9 | /// 10 | /// Returns str with all alphabetic characters converted to lowercase., PHP Manual 11 | /// 12 | /// The string being lowercased. 13 | /// 14 | [DirectCall("mb_strtolower")] 15 | public static string ToLower(string str) 16 | { 17 | return str.ToLower(); 18 | } 19 | 20 | /// 21 | /// Returns str with all alphabetic characters converted to lowercase., PHP Manual 22 | /// 23 | /// The string being lowercased. 24 | /// The encoding parameter is the character encoding. If it is omitted, the internal character encoding value will be used. 25 | /// 26 | [DirectCall("mb_strtolower")] 27 | public static string ToLower(string str, string encoding) 28 | { 29 | return str.ToLower(); 30 | } 31 | 32 | 33 | 34 | [DirectCall("mb_strlen")] 35 | public static int Len(string str, string encoding) 36 | { 37 | return str.Length; 38 | } 39 | 40 | 41 | [DirectCall("mb_strlen")] 42 | public static int Len(string str) 43 | { 44 | return str.Length; 45 | } 46 | #endregion Methods 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Lang.Php/OutputBuffer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | public static class OutputBuffer 6 | { 7 | [DirectCall("ob_get_clean")] 8 | public static string GetClean() 9 | { 10 | throw new NotImplementedException(); 11 | } 12 | 13 | [DirectCall("ob_end_clean")] 14 | public static string EndClean() 15 | { 16 | throw new NotImplementedException(); 17 | } 18 | [DirectCall("ob_end_flush")] 19 | public static string EndFlush() 20 | { 21 | throw new NotImplementedException(); 22 | } 23 | 24 | [DirectCall("ob_start")] 25 | public static void Start() 26 | { 27 | // bool ob_start ([ callable $output_callback = NULL [, int $chunk_size = 0 [, int $flags = PHP_OUTPUT_HANDLER_STDFLAGS ]]] ) 28 | } 29 | 30 | [DirectCall("ob_start")] 31 | public static void Start(Func callback) 32 | { 33 | // bool ob_start ([ callable $output_callback = NULL [, int $chunk_size = 0 [, int $flags = PHP_OUTPUT_HANDLER_STDFLAGS ]]] ) 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Lang.Php/OutputCallbackDelegates.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php 2 | { 3 | public delegate string OutputCallbackDelegate1(string buffer); 4 | public delegate string OutputCallbackDelegate2(string buffer, int phase); 5 | } 6 | -------------------------------------------------------------------------------- /Lang.Php/PhpErrorTable.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php 2 | { 3 | public class PhpErrorTable 4 | { 5 | 6 | // pu 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Lang.Php/PhpFileStream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | [Skip] 6 | public partial class PhpFileStream 7 | { 8 | 9 | 10 | /// 11 | /// int fwrite ( resource $handle , string $string [, int $length ] ) 12 | /// 13 | [DirectCall("fwrite", "this,0")] 14 | public void Write(string txt) 15 | { 16 | throw new NotImplementedException(); 17 | } 18 | 19 | /// 20 | /// string fread ( resource $handle , int $length ) 21 | /// 22 | [DirectCall("fread", "this,0")] 23 | public string Read(int length) 24 | { 25 | throw new NotImplementedException(); 26 | } 27 | 28 | /// 29 | /// string fread ( resource $handle , int $length ) 30 | /// 31 | [DirectCall("fclose", "this")] 32 | public void Close() 33 | { 34 | 35 | } 36 | 37 | /// 38 | /// resource fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] ) 39 | /// 40 | /// 41 | [DirectCall("fopen")] 42 | public static PhpFileStream Open(string filename, FileStreamOpenModes mode, bool use_include_path = false) 43 | { 44 | throw new NotImplementedException(); 45 | } 46 | 47 | 48 | 49 | public const string BINARY = "b"; 50 | 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Lang.Php/PhpIni.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Lang.Php 4 | { 5 | public static class PhpIni 6 | { 7 | public const int MYSQL_DEFAULT_PORT = 3306; 8 | static PhpIni() 9 | { 10 | Values = new Dictionary() 11 | { 12 | {"mysqli.default_host", "localhost" }, 13 | {"mysqli.default_port", "3306" }, 14 | {"mysqli.default_user", "root"}, 15 | {"mysqli.default_pw", ""}, 16 | {"mysqli.default_socket",""} 17 | }; 18 | } 19 | public static Dictionary Values 20 | { 21 | get; 22 | set; 23 | } 24 | public static bool TryGetValue(string name, out string value) 25 | { 26 | return Values.TryGetValue(name, out value); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Lang.Php/PhpMath.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php 2 | { 3 | 4 | public partial class PhpMath 5 | { 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Lang.Php/PhpString.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php 2 | { 3 | 4 | public class PhpString 5 | { 6 | #region Static Methods 7 | 8 | // Public Methods 9 | 10 | /// 11 | /// string implode ( array $pieces ) 12 | /// 13 | /// 14 | /// 15 | /// 16 | [DirectCall("implode")] 17 | [Since("4.3.0")] 18 | public static string Implode(string[] pieces) 19 | { 20 | return string.Join("", pieces); 21 | } 22 | 23 | /// 24 | /// string implode ( string $glue , array $pieces ) 25 | /// 26 | /// 27 | /// 28 | /// 29 | [DirectCall("implode")] 30 | public static string Implode(string glue, string[] pieces) 31 | { 32 | return string.Join(glue, pieces); 33 | } 34 | 35 | #endregion Static Methods 36 | 37 | ///// 38 | ///// array mb_split ( string $pattern , string $string [, int $limit = -1 ] ) 39 | ///// 40 | ///// 41 | ///// 42 | //[Since("4.2.0")] 43 | //[DirectCall("???")] 44 | //private string[] Split(params char[] separator) 45 | //{ 46 | // throw new MockMethodException(); 47 | //} 48 | //[DirectCall("mb_substr", "this,0")] 49 | //public string Substring(int startIndex) 50 | //{ 51 | // throw new NotSupportedException(); 52 | //} 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Lang.Php/PhpVersions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | public static class PhpVersions 6 | { 7 | public static readonly Version PHP_5_2_9 = new Version(5, 2, 9); 8 | public static readonly Version PHP_5_3_0 = new Version(5, 3, 0); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Lang.Php/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: Guid("381AF981-ECF4-4E8C-AF6A-63ABF5935573")] 5 | 6 | -------------------------------------------------------------------------------- /Lang.Php/Runtime/PhpStringBuilder.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Text; 3 | 4 | namespace Lang.Php.Runtime 5 | { 6 | public class PhpStringBuilder 7 | { 8 | StringBuilder s = new StringBuilder(); 9 | public override string ToString() 10 | { 11 | return s.ToString(); 12 | } 13 | public void Add(object o) 14 | { 15 | s.Append(PhpValues.ToPhpCodeValue(o)); 16 | } 17 | public void AddFormat(string f, params object[] o) 18 | { 19 | var oo = o.Select(i => PhpValues.ToPhpCodeValue(i)).ToArray(); 20 | s.AppendFormat(f, oo); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Lang.Php/SLFSupport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | public class SLFSupport 6 | { 7 | public static String Concat(Object[] x) 8 | { 9 | string r = ""; 10 | foreach (var i in x) 11 | r += i.ToString(); 12 | return r; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Lang.Php/_DateTime/UnixTimestamp.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable once CheckNamespace 2 | namespace Lang.Php 3 | { 4 | [Skip] 5 | public sealed class UnixTimestamp 6 | { 7 | #region Methods 8 | 9 | // Public Methods 10 | 11 | [DirectCall(null, "this")] 12 | public override string ToString() 13 | { 14 | return base.ToString(); 15 | } 16 | 17 | [DirectCall("date", "0,this")] 18 | public string ToString(string format) 19 | { 20 | return base.ToString(); 21 | } 22 | 23 | #endregion Methods 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Lang.Php/_Files/PathInfoResult.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php 2 | { 3 | [Skip] 4 | [AsArray] 5 | public class PathInfoResult 6 | { 7 | [ScriptName("dirname")] 8 | public string Dirname { get; set; } 9 | [ScriptName("basename")] 10 | public string Basename { get; set; } 11 | [ScriptName("extension")] 12 | public string Extension { get; set; } 13 | [ScriptName("filename")] 14 | [Since("5.2.0")] 15 | public string Filename { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Lang.Php/_Files/PhpDirectory.cs: -------------------------------------------------------------------------------- 1 | using Lang.Php.Runtime; 2 | using System; 3 | 4 | // ReSharper disable once CheckNamespace 5 | namespace Lang.Php 6 | { 7 | 8 | [Skip] 9 | public class PhpDirectory 10 | { 11 | [UseBinaryExpression("!==", "this", "false")] 12 | public virtual bool IsOk 13 | { 14 | get 15 | { 16 | throw new NotSupportedException(); 17 | // return _ok; 18 | } 19 | } 20 | 21 | protected PhpDirectory() 22 | { 23 | 24 | } 25 | [DirectCall("mkdir")] 26 | public static PhpDirectory Make(string dirName) 27 | { 28 | return new RuntimePhpDirectory(dirName); 29 | } 30 | 31 | [DirectCall("mkdir")] 32 | public static PhpDirectory Make(string dirName, UnixFilePermissions perm) 33 | { 34 | return new RuntimePhpDirectory(dirName); 35 | } 36 | 37 | [DirectCall("readdir", "0,this", 0)] 38 | public virtual bool ReadDir(out PhpDirectoryEntry file) 39 | { 40 | throw new MockMethodException(); 41 | // readdir 42 | } 43 | 44 | [DirectCall("closedir", "this")] 45 | public void Close() 46 | { 47 | 48 | } 49 | 50 | [DirectCall("opendir", "0")] 51 | public static PhpDirectory Open(string dirName) 52 | { 53 | throw new NotImplementedException(); 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /Lang.Php/_Firebird/FirebirdResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | public class FirebirdResult 6 | { 7 | 8 | [DirectCall("ibase_fetch_assoc", "this,0", 1)] 9 | public virtual bool FetchAssoc(out T row) 10 | { 11 | throw new NotSupportedException(); 12 | } 13 | 14 | /// 15 | /// bool ibase_free_result ( resource $result_identifier ) 16 | /// 17 | [DirectCall("ibase_free_result", "this")] 18 | public void FreeResult() 19 | { 20 | // bool ibase_free_result ( resource $result_identifier ) 21 | // _phpLevelDisposed = true; 22 | } 23 | 24 | [UseBinaryExpression("!==", "this", "false")] 25 | public bool IsOk 26 | { 27 | get 28 | { 29 | throw new NotImplementedException(); 30 | // return _ok; 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Lang.Php/_Firebird/IbaseTransactionOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | [Flags] 6 | public enum IbaseTransactionOptions 7 | { 8 | [RenderValue("IBASE_READ")] 9 | Read, 10 | [RenderValue("IBASE_WRITE")] 11 | Write, 12 | [RenderValue("IBASE_COMMITTED")] 13 | Committed, 14 | [RenderValue("IBASE_CONSISTENCY")] 15 | Consistency, 16 | [RenderValue("IBASE_CONCURRENCY")] 17 | Concurrency, 18 | [RenderValue("IBASE_REC_VERSION")] 19 | RecVersion, 20 | [RenderValue("IBASE_REC_NO_VERSION")] 21 | RecNoVersion, 22 | [RenderValue("IBASE_WAIT")] 23 | Wait, 24 | [RenderValue("IBASE_NOWAIT")] 25 | Nowait 26 | } 27 | } -------------------------------------------------------------------------------- /Lang.Php/_MySQLi/MySQLiParam.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php 2 | { 3 | [Skip] 4 | public class MySQLiParam 5 | { 6 | [DirectCall("this")] 7 | public T Value { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Lang.Php/_MySQLi/MySQLiResultMode.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php 2 | { 3 | public enum MySQLiResultMode 4 | { 5 | [RenderValue("MYSQLI_USE_RESULT")] 6 | UseResult, 7 | [RenderValue("MYSQLI_STORE_RESULT")] 8 | StoreResult 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Lang.Php/_MySQLi/MySQLiWarning.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php 2 | { 3 | [Skip] 4 | [ScriptName("\\mysqli_warning")] 5 | public class MySQLiWarning 6 | { 7 | #region Methods 8 | 9 | // Public Methods 10 | 11 | [DirectCall("->next")] 12 | public void Next() 13 | { 14 | 15 | } 16 | 17 | #endregion Methods 18 | 19 | #region Properties 20 | 21 | [DirectCall("->$errno")] 22 | public object Eerrno { get; set; } 23 | 24 | [DirectCall("->$message")] 25 | public string message { get; set; } 26 | 27 | [DirectCall("->$sqlstate")] 28 | public object SqlState { get; set; } 29 | 30 | #endregion Properties 31 | 32 | /* Properties 33 | public $message ; 34 | public $sqlstate ; 35 | public $errno ; 36 | Methods 37 | public __construct ( void ) 38 | public void next ( void ) 39 | */ 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Lang.Php/_MySql/MySQLFieldTypes.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php 2 | { 3 | [EnumRender(EnumRenderOptions.UnderscoreUppercase, true)] 4 | public enum MySQLFieldTypes 5 | { 6 | //numerics 7 | //------------- 8 | Bit = 16, 9 | Tinyint = 1, 10 | Bool = 1, 11 | Smallint = 2, 12 | Mediumint = 9, 13 | Integer = 3, 14 | Bigint = 8, 15 | Serial = 8, 16 | Float = 4, 17 | Double = 5, 18 | Decimal = 246, 19 | Numeric = 246, 20 | Fixed = 246, 21 | // dates 22 | // ------------ 23 | Date = 10, 24 | Datetime = 12, 25 | Timestamp = 7, 26 | Time = 11, 27 | Year = 13, 28 | 29 | //Strings & Binary 30 | // ------------ 31 | Char = 254, 32 | Varchar = 253, 33 | Enum = 254, 34 | Set = 254, 35 | Binary = 254, 36 | Varbinary = 253, 37 | Tinyblob = 252, 38 | Blob = 252, 39 | Mediumblob = 252, 40 | Tinytext = 252, 41 | Text = 252, 42 | Mediumtext = 252, 43 | Longtext = 252 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Lang.Php/_MySql/MySQLFlags.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | [Flags] 6 | public enum MySQLFlags 7 | { 8 | [RenderValue("NOT_NULL_FLAG")] 9 | NotNull = 1, 10 | [RenderValue("PRI_KEY_FLAG")] 11 | PrimaryKey = 2, 12 | [RenderValue("UNIQUE_KEY_FLAG")] 13 | UniqueKey = 4, 14 | [RenderValue("BLOB_FLAG")] 15 | Blob = 16, 16 | [RenderValue("UNSIGNED_FLAG")] 17 | Unsigned = 32, 18 | [RenderValue("ZEROFILL_FLAG")] 19 | Zerofill = 64, 20 | [RenderValue("BINARY_FLAG")] 21 | Binary = 128, 22 | [RenderValue("ENUM_FLAG")] 23 | Enum = 256, 24 | [RenderValue("AUTO_INCREMENT_FLAG")] 25 | AutoIncrement = 512, 26 | [RenderValue("TIMESTAMP_FLAG")] 27 | Timestamp = 1024, 28 | [RenderValue("SET_FLAG")] 29 | Set = 2048, 30 | [RenderValue("NUM_FLAG")] 31 | Num = 32768, 32 | [RenderValue("PART_KEY_FLAG")] 33 | PartialKey = 16384, 34 | [RenderValue("GROUP_FLAG")] 35 | Group = 32768, 36 | [RenderValue("UNIQUE_FLAG")] 37 | Unique = 65536 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Lang.Php/_MySql/MySqlDateTime.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | [Skip] 6 | public class MySqlDateTime 7 | { 8 | public string Value { get; set; } 9 | public MySqlDateTime(string dt) 10 | { 11 | Value = dt; 12 | } 13 | 14 | [ScriptName("A")] 15 | [DirectCall(null,"0")] 16 | public static implicit operator string(MySqlDateTime src) 17 | { 18 | return src.Value; 19 | } 20 | [ScriptName("B")] 21 | [DirectCall(null, "0")] 22 | public static implicit operator MySqlDateTime(string src) 23 | { 24 | return new MySqlDateTime(src); 25 | } 26 | 27 | [DirectCall("strtotime")] 28 | public static implicit operator DateTime(MySqlDateTime src) 29 | { 30 | // yyyy-mm-dd 31 | var y = int.Parse(src.Value.Substring(0, 4)); 32 | var m = int.Parse(src.Value.Substring(5, 2)); 33 | var d = int.Parse(src.Value.Substring(8, 2)); 34 | return new DateTime(y, m, d); 35 | //return (DateTime)g; 36 | } 37 | 38 | [DirectCall("jakas_funkcja_ktorej_jeszcze_nie_mam")] 39 | public static implicit operator MySqlDateTime(DateTime src) 40 | { 41 | throw new NotSupportedException(); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Lang.Php/_Posix/Posix.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | // ReSharper disable once CheckNamespace 4 | namespace Lang.Php 5 | { 6 | public static class Posix 7 | { 8 | #region Static Methods 9 | 10 | // Public Methods 11 | 12 | [DirectCall("posix_getgrgid")] 13 | public static Falsable GetGroupById(int groupId) 14 | { 15 | return new PosixGroupInfo 16 | { 17 | GroupId = groupId 18 | }; 19 | } 20 | 21 | [DirectCall("posix_getgrnam")] 22 | public static Falsable GetGroupByName(string name) 23 | { 24 | return new PosixGroupInfo 25 | { 26 | Name = name 27 | }; 28 | } 29 | 30 | /// 31 | /// Returns an array of information about the user referenced by the given user ID. 32 | /// 33 | /// 34 | [DirectCall("posix_getpwuid")] 35 | public static Falsable GetUserById(int uid) 36 | { 37 | throw new NotImplementedException(); 38 | } 39 | 40 | /// 41 | /// Returns an array of information about the given user. 42 | /// 43 | /// An alphanumeric username. 44 | [DirectCall("posix_getpwnam")] 45 | public static Falsable GetUserByName(string username) 46 | { 47 | throw new NotImplementedException(); 48 | } 49 | 50 | #endregion Static Methods 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Lang.Php/_Posix/PosixGroupInfo.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable once CheckNamespace 2 | namespace Lang.Php 3 | { 4 | [AsArray] 5 | public class PosixGroupInfo 6 | { 7 | /// 8 | /// The name element contains the name of the group. This is a short, usually less than 16 character "handle" of the group, not the real, full name. 9 | /// 10 | [ScriptName("name")] 11 | public string Name { get; set; } 12 | 13 | /// 14 | /// The passwd element contains the group's password in an encrypted format. Often, for example on a system employing "shadow" passwords, an asterisk is returned instead. 15 | /// 16 | [ScriptName("passwd")] 17 | public string Password { get; set; } 18 | 19 | /// 20 | /// Group ID, should be the same as the gid parameter used when calling the function, and hence redundant. 21 | /// 22 | [ScriptName("gid")] 23 | public int GroupId { get; set; } 24 | 25 | /// 26 | /// This consists of an array of string's for all the members in the group. 27 | /// 28 | [ScriptName("members")] 29 | public string[] Members { get; set; } 30 | } 31 | } -------------------------------------------------------------------------------- /Lang.Php/_Regex/Preg.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text.RegularExpressions; 4 | 5 | namespace Lang.Php 6 | { 7 | public static class Preg 8 | { 9 | public static PregMatchResult Match(string pattern, string subject) 10 | { 11 | var delimiter = pattern[0]; 12 | var i = pattern.LastIndexOf(delimiter); 13 | var pattern1 = pattern.Substring(1, i - 1); 14 | var options = pattern.Substring(i + 1); 15 | if (options != "") 16 | throw new NotImplementedException(); 17 | var re = new Regex(pattern1); 18 | return re.IsMatch(subject) ? PregMatchResult.Success : PregMatchResult.Fail; 19 | // string pattern , string subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] 20 | } 21 | 22 | public static PregMatchResult Match(string pattern, string subject, out Dictionary matches, int offset = 0) 23 | { 24 | throw new NotImplementedException(); 25 | } 26 | 27 | public static PregMatchResult MatchWithOffset(string pattern, string subject, out Dictionary matches, int offset = 0) 28 | { 29 | throw new NotImplementedException(); 30 | } 31 | 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Lang.Php/_Regex/PregMatchResult.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php 2 | { 3 | public struct PregMatchResult 4 | { 5 | private PregMatchResult(int value) 6 | { 7 | _value = value; 8 | } 9 | 10 | 11 | internal static PregMatchResult Error 12 | { 13 | get { return new PregMatchResult(-1); } 14 | } 15 | 16 | internal static PregMatchResult Fail 17 | { 18 | get { return new PregMatchResult(0); } 19 | } 20 | 21 | internal static PregMatchResult Success 22 | { 23 | get { return new PregMatchResult(1); } 24 | } 25 | 26 | 27 | [UseBinaryExpression("===", "this", "false")] 28 | public bool IsError 29 | { 30 | get { return _value == -1; } 31 | } 32 | 33 | [UseBinaryExpression("==", "this", "0")] 34 | public bool IsFail 35 | { 36 | get { return _value == 0; } 37 | } 38 | 39 | [UseBinaryExpression("==", "this", "1")] 40 | public bool IsSuccess 41 | { 42 | get { return _value == 1; } 43 | } 44 | 45 | private readonly int _value; 46 | } 47 | } -------------------------------------------------------------------------------- /Lang.Php/_Regex/PregMatchWithOffset.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php 2 | { 3 | [AsArray] 4 | public class PregMatchWithOffset 5 | { 6 | [ScriptName("1")] 7 | public int Offset; 8 | 9 | [ScriptName("0")] 10 | public int Value; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Lang.Php/_ResponseHeader/ResponseHeader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | public class ResponseHeader 6 | { 7 | #region Static Methods 8 | 9 | // Public Methods 10 | 11 | public static void ContentType(string type, bool replace = false) 12 | { 13 | throw new MockMethodException(); 14 | } 15 | 16 | // public static void CacheControl() 17 | public static void Expires(DateTime dt) 18 | { 19 | throw new MockMethodException(); 20 | } 21 | 22 | public static void Head(string key, string value) 23 | { 24 | 25 | } 26 | 27 | public static void LastModified(DateTime dt) 28 | { 29 | throw new MockMethodException(); 30 | } 31 | 32 | public static void Pragma(HttpPragma pragma) 33 | { 34 | throw new MockMethodException(); 35 | } 36 | 37 | #endregion Static Methods 38 | 39 | // header("Content-Transfer-Encoding: binary"); 40 | //header("Cache-Control: public, must-revalidate, max-age=0"); 41 | // header("Pragma: public"); 42 | // var now = DateTime.Now; 43 | // header("Expires: " + now.AddDays(2.5).AddHours(2).PhpFormat(DateTimeFormats.HttpHeader)); 44 | // header("Last-Modified: " + now.PhpFormat(DateTimeFormats.HttpHeader)); 45 | // header("Content-Type: application/force-download"); 46 | // header("Content-Type: application/octet-stream", false); 47 | // header("Content-Type: application/download", false); 48 | // header("Content-Type: application/pdf", false); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Lang.Php/_attributes/AsArrayAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | [AttributeUsage(AttributeTargets.Class)] 6 | public class AsArrayAttribute : Attribute 7 | { 8 | public AsArrayAttribute() 9 | { 10 | 11 | } 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Lang.Php/_attributes/AsDefinedConstAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | public class AsDefinedConstAttribute : Attribute 6 | { 7 | /// 8 | /// Tworzy instancję obiektu 9 | /// 10 | public AsDefinedConstAttribute() 11 | { 12 | } 13 | 14 | /// 15 | /// Tworzy instancję obiektu 16 | /// 17 | /// 18 | public AsDefinedConstAttribute(string definedConstName) 19 | { 20 | DefinedConstName = definedConstName; 21 | } 22 | 23 | 24 | /// 25 | /// Własność jest tylko do odczytu. 26 | /// 27 | public string DefinedConstName { get; } = string.Empty; 28 | } 29 | } -------------------------------------------------------------------------------- /Lang.Php/_attributes/AsValueAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | /// 6 | /// Atrybut określa, że stała nie będzie nigdzie deklarowana, a wszystkie jej wystąpienia zostaną zastąpione watościami 7 | /// 8 | /// Własność glue dla przykładu 9 | /// const string CONST = "Some tekst" 10 | /// x = "Mój tekst" + CONST; 11 | /// jeśli glue = false 12 | /// $x = 'Mój tekst' . 'Some tekst' 13 | /// jeśli glue = true 14 | /// $x = 'Mój tekstSome tekst' 15 | /// 16 | /// 17 | public class AsValueAttribute : Attribute 18 | { 19 | /// 20 | /// Tworzy instancję obiektu 21 | /// 22 | public AsValueAttribute() 23 | { 24 | } 25 | 26 | /// 27 | /// Tworzy instancję obiektu 28 | /// 29 | /// Czy można sklejać wartości stałej z pozostałym tekstem (jeśli stała tekstowa występuje w 30 | /// wyrażeniu z innym tekstem) 31 | /// 32 | /// 33 | public AsValueAttribute(bool glue) 34 | { 35 | Glue = glue; 36 | } 37 | 38 | 39 | /// 40 | /// Czy można sklejać wartości stałej z pozostałym tekstem (jeśli stała tekstowa występuje w wyrażeniu z innym tekstem) 41 | /// 42 | public bool Glue { get; set; } 43 | } 44 | } -------------------------------------------------------------------------------- /Lang.Php/_attributes/BuiltInAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] 6 | public class BuiltInAttribute : Attribute 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Lang.Php/_attributes/EnumRenderAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | public class EnumRenderAttribute : Attribute 6 | { 7 | public EnumRenderAttribute(EnumRenderOptions o, bool DefinedConst) 8 | { 9 | Option = o; 10 | this.DefinedConst = DefinedConst; 11 | } 12 | public EnumRenderOptions Option { get; private set; } 13 | public bool DefinedConst { get; private set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Lang.Php/_attributes/GlobalVariableAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | public class GlobalVariableAttribute : Attribute 6 | { 7 | /// 8 | /// Tworzy instancję obiektu 9 | /// 10 | public GlobalVariableAttribute() 11 | { 12 | } 13 | 14 | /// 15 | /// Tworzy instancję obiektu 16 | /// 17 | /// 18 | public GlobalVariableAttribute(string globalVariableName) 19 | { 20 | GlobalVariableName = globalVariableName; 21 | } 22 | 23 | 24 | /// 25 | /// Własność jest tylko do odczytu. 26 | /// 27 | public string GlobalVariableName { get; } = string.Empty; 28 | } 29 | } -------------------------------------------------------------------------------- /Lang.Php/_attributes/IgnoreNamespaceAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | public class IgnoreNamespaceAttribute : Attribute 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Lang.Php/_attributes/ModuleAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | [AttributeUsage(AttributeTargets.All)] 6 | public class ModuleAttribute : Attribute 7 | { 8 | /// 9 | /// Tworzy instancję obiektu 10 | /// Module short name i.e "hello-page" or "mynamespace/hello-class" 11 | /// 12 | /// 13 | public ModuleAttribute(string moduleShortName, params string[] includePathPrefix) 14 | { 15 | ModuleShortName = moduleShortName; 16 | IncludePathPrefix = includePathPrefix; 17 | } 18 | 19 | 20 | /// 21 | /// Tworzy instancję obiektu 22 | /// Module short name i.e "hello-page" or "mynamespace/hello-class" 23 | /// 24 | public ModuleAttribute(string moduleShortName) 25 | { 26 | ModuleShortName = moduleShortName; 27 | } 28 | 29 | /// 30 | /// Module short name i.e "hello-page" or "mynamespace/hello-class"; własność jest tylko do odczytu. 31 | /// 32 | public string ModuleShortName { get; } = string.Empty; 33 | 34 | /// 35 | /// Własność jest tylko do odczytu. 36 | /// 37 | public string[] IncludePathPrefix { get; } 38 | } 39 | } -------------------------------------------------------------------------------- /Lang.Php/_attributes/PageAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | [AttributeUsage(AttributeTargets.Class)] 6 | public class PageAttribute : Attribute 7 | { 8 | public PageAttribute() 9 | { 10 | 11 | } 12 | public PageAttribute(string ModuleShortName) 13 | { 14 | this.ModuleShortName = ModuleShortName; 15 | } 16 | public string ModuleShortName { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Lang.Php/_attributes/PhpValueMapperAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | /// 6 | /// Allows PHP compiler to find class that implements IMethodMapper and can be used for PHP values mapping 7 | /// Class cannot be abstract 8 | /// 9 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] 10 | public class PhpValueMapperAttribute : Attribute 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Lang.Php/_attributes/RenderValueAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | public class RenderValueAttribute : Attribute 6 | { 7 | /// 8 | /// 9 | /// 10 | /// Name in script 11 | public RenderValueAttribute(string name) 12 | { 13 | Name = name; 14 | } 15 | /// 16 | /// Name in script 17 | /// 18 | public string Name { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Lang.Php/_attributes/ReplaceAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] 6 | public class ReplaceAttribute : Attribute 7 | { 8 | /// 9 | /// Tworzy instancję obiektu 10 | /// 11 | /// 12 | public ReplaceAttribute(Type replacedType) 13 | { 14 | ReplacedType = replacedType; 15 | } 16 | 17 | /// 18 | /// Własność jest tylko do odczytu. 19 | /// 20 | public Type ReplacedType { get; } 21 | } 22 | } -------------------------------------------------------------------------------- /Lang.Php/_attributes/RequireOnceAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] 6 | public class RequireOnceAttribute : Attribute 7 | { 8 | public RequireOnceAttribute(string f) 9 | { 10 | Filename = f; 11 | } 12 | public string Filename { get; private set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Lang.Php/_attributes/SkipAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | public class SkipAttribute : Attribute 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Lang.Php/_attributes/TranslatorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | [Obsolete] 6 | public class TranslatorAttribute:Attribute 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Lang.Php/_attributes/UseBinaryExpressionAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | /// 6 | /// Sugeruje zastąpienie (np. własności instancyjnej) operatorem (np.===) 7 | /// 8 | public class UseBinaryExpressionAttribute : Attribute 9 | { 10 | /// 11 | /// Tworzy instancję obiektu 12 | /// 13 | /// 14 | /// 15 | /// 16 | public UseBinaryExpressionAttribute(string _operator, string left, string right) 17 | { 18 | Operator = _operator; 19 | Left = left; 20 | Right = right; 21 | } 22 | 23 | /// 24 | /// Własność jest tylko do odczytu. 25 | /// 26 | public string Operator { get; } = string.Empty; 27 | 28 | /// 29 | /// Własność jest tylko do odczytu. 30 | /// 31 | public string Left { get; } = string.Empty; 32 | 33 | /// 34 | /// Własność jest tylko do odczytu. 35 | /// 36 | public string Right { get; } = string.Empty; 37 | } 38 | } -------------------------------------------------------------------------------- /Lang.Php/_attributes/_assembly/ConfigModuleAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | 6 | /// 7 | /// ConfigModuleAttribute decorates assembly with name of module thath contains cs2php related configuration. 8 | /// Module name 'cs2php' (filename cs2php.php) is taken if ConfigModuleAttribute is ommited. 9 | /// 10 | /// 11 | /// Cs2php config module contains i.e. definition of global variables or defined constants with path(s) to other module(s). 12 | /// 13 | [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)] 14 | public class ConfigModuleAttribute : Attribute 15 | { 16 | /// 17 | /// Creates instance of attribute 18 | /// 19 | /// Name of module that contains cs2php related configuration 20 | public ConfigModuleAttribute(string name) 21 | { 22 | Name = name; 23 | } 24 | public const string DEFAULT = "cs2php"; 25 | /// 26 | /// Name of module that contains cs2php related configuration 27 | /// 28 | public string Name { get; private set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Lang.Php/_attributes/_assembly/DefaultTimezoneAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | 6 | [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)] 7 | public class DefaultTimezoneAttribute : Attribute 8 | { 9 | public DefaultTimezoneAttribute(Timezones Timezone) 10 | { 11 | this.Timezone = Timezone; 12 | } 13 | public Timezones Timezone { get; private set; } 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Lang.Php/_attributes/_assembly/ModuleIncludeConstAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | /// 6 | /// Atrybut dołączany do assemby, który wskazuje jaka stała PHP określa ścieżkę bazową dla biblioteki 7 | /// może być np. MY_LIB_PATH (define) lub $MyLibPath (global var) 8 | /// 9 | [AttributeUsage(AttributeTargets.Assembly)] 10 | public class ModuleIncludeConstAttribute : Attribute 11 | { 12 | /// 13 | /// Tworzy instancję obiektu 14 | /// Module filename 15 | /// 16 | public ModuleIncludeConstAttribute(string constOrVarName) 17 | { 18 | ConstOrVarName = constOrVarName; 19 | } 20 | 21 | 22 | /// 23 | /// Module filename; własność jest tylko do odczytu. 24 | /// 25 | public string ConstOrVarName { get; } = string.Empty; 26 | } 27 | } -------------------------------------------------------------------------------- /Lang.Php/_attributes/_assembly/PhpPackageSourceAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | 6 | /// 7 | /// PhpPackageSourceAttribute is used to decorate assembly with information about location of 8 | /// php compiled library that should be downloaded and used instead of cs2php translated code. 9 | /// Usefull with facade only .NET libraries i.e. mPDF 10 | /// 11 | [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)] 12 | public class PhpPackageSourceAttribute : Attribute 13 | { 14 | #region Constructors 15 | 16 | public PhpPackageSourceAttribute(string sourceUri) 17 | { 18 | SourceUri = sourceUri; 19 | } 20 | 21 | public PhpPackageSourceAttribute(string sourceUri, string stripArchivePath) 22 | { 23 | SourceUri = sourceUri; 24 | StripArchivePath = stripArchivePath; 25 | } 26 | 27 | #endregion Constructors 28 | 29 | #region Properties 30 | 31 | public string SourceUri { get; private set; } 32 | 33 | public string StripArchivePath { get; private set; } 34 | 35 | #endregion Properties 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Lang.Php/_attributes/_assembly/PriovidesTranslatorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | public class PriovidesTranslatorAttribute : Attribute 6 | { 7 | public PriovidesTranslatorAttribute(string TranslatorForAssembly) 8 | { 9 | this.TranslatorForAssembly = Guid.Parse(TranslatorForAssembly); 10 | } 11 | public Guid TranslatorForAssembly { get; private set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Lang.Php/_attributes/_assembly/RequiredTranslatorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | // ReSharper disable once CheckNamespace 5 | namespace Lang.Php 6 | { 7 | [Serializable] 8 | [AttributeUsage(AttributeTargets.Assembly)] 9 | [Guid("1FA81F36-8B6D-483C-8407-88C4197F4FFC")] 10 | public class RequiredTranslatorAttribute : Attribute 11 | { 12 | #region Constructors 13 | 14 | /// 15 | /// Tworzy atrybut oznaczający, że dołączana biblioteka wymaga helpera to cs2php 16 | /// 17 | /// Sugerowana nazwa translatora 18 | public RequiredTranslatorAttribute(string suggested) 19 | { 20 | Suggested = suggested; 21 | } 22 | 23 | #endregion Constructors 24 | 25 | #region Properties 26 | 27 | public string Suggested { get; private set; } 28 | 29 | #endregion Properties 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Lang.Php/_attributes/_assembly/ResourcesDirectoryAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)] 6 | public class ResourcesDirectoryAttribute : Attribute 7 | { 8 | #region Constructors 9 | 10 | public ResourcesDirectoryAttribute(string Source) 11 | { 12 | this.Source = Source; 13 | Destination = ""; 14 | } 15 | 16 | public ResourcesDirectoryAttribute(string Source, string Destination) 17 | { 18 | this.Source = Source; 19 | this.Destination = Destination; 20 | } 21 | 22 | #endregion Constructors 23 | 24 | #region Properties 25 | 26 | /// 27 | /// Where to place resources 28 | /// 29 | public string Destination { get; private set; } 30 | 31 | /// 32 | /// Where to search resources 33 | /// 34 | public string Source { get; private set; } 35 | 36 | #endregion Properties 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Lang.Php/_attributes/_assembly/RootPathAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | /// 6 | /// RootPathAttribute is used to decorate assembly with default path where assembly 7 | /// output (php files and resources) will be stored. 8 | /// 9 | [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)] 10 | public class RootPathAttribute : Attribute 11 | { 12 | public RootPathAttribute(string path) 13 | { 14 | Path = path; 15 | } 16 | public string Path { get; private set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Lang.Php/_enums/ClassMembers.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php 2 | { 3 | public enum ClassMembers 4 | { 5 | Method, 6 | Field 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Lang.Php/_enums/Css.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php 2 | { 3 | [EnumRender(EnumRenderOptions.MinusLowercase, false)] 4 | public enum Css 5 | { 6 | Color, 7 | BackgroundColor, 8 | FontSize, 9 | FontFamily, 10 | Width, 11 | TextAlign, 12 | Margin, 13 | Padding, 14 | Border, 15 | VerticalAlign 16 | // border:5px solid red; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Lang.Php/_enums/EnumRenderOptions.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php 2 | { 3 | public enum EnumRenderOptions 4 | { 5 | TheSameString, 6 | UnderscoreLowercase, 7 | UnderscoreUppercase, 8 | MinusLowercase, 9 | Numbers, 10 | OctalNumbers 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Lang.Php/_enums/FormEncodings.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php 2 | { 3 | public enum FormEncodings 4 | { 5 | /// 6 | /// multipart/form-data 7 | /// 8 | [RenderValue("'multipart/form-data'")] 9 | MultipartFromData 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Lang.Php/_enums/FormMethods.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php 2 | { 3 | [EnumRender(EnumRenderOptions.UnderscoreLowercase, false)] 4 | public enum FormMethods 5 | { 6 | Post, 7 | Get 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Lang.Php/_enums/HttpEnums.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Lang.Php 7 | { 8 | public enum HttpPragma 9 | { 10 | [RenderValue("'no-cache'")] 11 | NoCache, 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Lang.Php/_enums/HttpEnums.tt: -------------------------------------------------------------------------------- 1 | <#@ template debug="false" hostspecific="false" language="C#" #> 2 | <#@ assembly name="System.Core" #> 3 | <#@ import namespace="System.Linq" #> 4 | <#@ import namespace="System.Text" #> 5 | <#@ import namespace="System.Collections.Generic" #> 6 | <#@ output extension=".cs" #> 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | using System.Text; 11 | 12 | namespace Lang.Php 13 | { 14 | public enum HttpPragma 15 | { 16 | <# 17 | X("NoCache", "no-cache"); 18 | #> 19 | } 20 | } 21 | <#+ 22 | void X(string Cs, string php = null, bool direct = false) { 23 | if (Cs.Contains(" ")) { 24 | var t = Cs.Split(' '); 25 | foreach(var cs1 in t) 26 | X(cs1); 27 | return; 28 | } 29 | if (string.IsNullOrEmpty(php)) 30 | php = Cs.Substring(0,1).ToLower() + Cs.Substring(1); 31 | if (!direct) { 32 | php="'" + php.Replace("\\","\\\\").Replace("\"", "\\\"") + "'"; 33 | } 34 | Write(" [RenderValue(\""+php+"\")]\r\n"); 35 | Write(" "+Cs+",\r\n"); 36 | } 37 | 38 | void Y(string Cs) { 39 | if (Cs.Contains(" ")) { 40 | var t = Cs.Split(' '); 41 | foreach(var cs1 in t) 42 | Y(cs1); 43 | return; 44 | } 45 | Write(" "+Cs+",\r\n"); 46 | 47 | } 48 | #> -------------------------------------------------------------------------------- /Lang.Php/_enums/MethodCallStyles.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php 2 | { 3 | public enum MethodCallStyles 4 | { 5 | Procedural, 6 | Instance, 7 | Static 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Lang.Php/_enums/PathInfoOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | [Flags] 6 | public enum PathInfoOptions 7 | { 8 | [RenderValue("PATHINFO_DIRNAME")] 9 | Dirname = 1, 10 | [RenderValue("PATHINFO_BASENAME")] 11 | Basename = 2, 12 | [RenderValue("PATHINFO_EXTENSION")] 13 | Extension = 4, 14 | [RenderValue("PATHINFO_FILENAME")] 15 | Filename = 8, 16 | 17 | [RenderValue("PATHINFO_DIRNAME | PATHINFO_BASENAME | PATHINFO_EXTENSION | PATHINFO_FILENAME")] 18 | All = 1+2+4+8 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Lang.Php/_enums/RoundMode.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php 2 | { 3 | 4 | [Since("5.3.0")] 5 | public enum RoundMode 6 | { 7 | 8 | /// 9 | /// Round halves up 10 | /// 11 | [RenderValue("PHP_ROUND_HALF_UP")] 12 | Up = 1, 13 | 14 | /// 15 | /// Round halves down 16 | /// 17 | [RenderValue("PHP_ROUND_HALF_DOWN")] 18 | Down = 2, 19 | 20 | /// 21 | /// ound halves to even numbers 22 | /// 23 | [RenderValue("PHP_ROUND_HALF_EVEN")] 24 | 25 | Even = 3, 26 | /// 27 | /// Round halves to odd numbers 28 | /// 29 | [RenderValue("PHP_ROUND_HALF_ODD")] 30 | Odd = 4 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Lang.Php/_enums/UnixFileGroupPermissions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | [Flags] 6 | [EnumRender(EnumRenderOptions.OctalNumbers, false)] 7 | public enum UnixFileGroupPermissions 8 | { 9 | Read = 1, 10 | Write = 2, 11 | Exec = 4, 12 | All = 7 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Lang.Php/_exceptions/MockMethodException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | [Serializable] 6 | public class MockMethodException : Exception 7 | { 8 | public MockMethodException() : 9 | base("This is only mock method and it provides no functionality at runtime") 10 | { 11 | 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Lang.Php/_exceptions/PlatformImplementationException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | [Serializable] 6 | public class PlatformImplementationException : Exception 7 | { 8 | public PlatformImplementationException(Type t, string method, string msg) 9 | : base(string.Format("Platform implementation exception in {0}.{1}:\r\n{2}", t.FullName, method, msg)) 10 | { 11 | 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Lang.Php/_extensions/DateTimeExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php 4 | { 5 | [Skip] 6 | public static class DateTimeExtension 7 | { 8 | [DirectCall("date_format")] 9 | public static string PhpFormat(this DateTime x, DateTimeFormats format) 10 | { 11 | throw new NotSupportedException(); 12 | } 13 | [DirectCall("date_format")] 14 | public static string PhpFormat(this DateTime x, string format) 15 | { 16 | throw new NotSupportedException(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Lang.Php/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Lang.Php/key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isukces/cs2php/7c817438b8e0fb004867fe70d20e09c3d3ba038e/Lang.Php/key.snk -------------------------------------------------------------------------------- /_Examples/E01_HelloWorld/Index.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Examples.HelloWorld 2 | { 3 | 4 | [Page("index")] 5 | public class Index : PhpDummy 6 | { 7 | public static void PhpMain() 8 | { 9 | echo("Hello world!"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /_Examples/E01_HelloWorld/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | 5 | 6 | // The following GUID is for the ID of the typelib if this project is exposed to COM 7 | [assembly: Guid("9355e81d-ae83-4084-9039-aded4c99b4dd")] 8 | 9 | -------------------------------------------------------------------------------- /_Examples/E01_HelloWorld/compile.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set CS2PHP=..\..\Lang.Cs2Php\bin\Release\net472\cs2php.exe 3 | %CS2PHP% E01_HelloWorld.csproj ..\..\_ExamplesOut\E01_HelloWorld 4 | 5 | 6 | -------------------------------------------------------------------------------- /_Examples/E01_HelloWorld/readme.txt: -------------------------------------------------------------------------------- 1 | Step by step instruction: 2 | 1. Compile solution with "Release" option 3 | 2. run "compile.bat" in the same directory as "E01_HelloWorld.csproj" file 4 | 3. Check result files in \_ExamplesOut\E01_HelloWorld folder -------------------------------------------------------------------------------- /_Examples/E02_BasicFeaturesExample/ComplexNumberTest.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Examples.BasicFeaturesExample 2 | { 3 | [Page("complex-number-test")] 4 | public class ComplexNumberTest 5 | { 6 | public static void PhpMain() 7 | { 8 | var a = new ComplexNumber(3, 2); 9 | ComplexNumber b = 12; 10 | var c = a * b; 11 | var d = a + b; 12 | 13 | var e = (a + 17) * 3; 14 | var m1 = new ComplexNumber(3, 2) * new ComplexNumber(4, 5); 15 | var m2 = new ComplexNumber(3, 2) * 5; 16 | 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /_Examples/E02_BasicFeaturesExample/Generics.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Lang.Php.Examples.BasicFeaturesExample 4 | { 5 | [Module("generics")] 6 | public class Generics 7 | { 8 | 9 | public static void CallIssue2() 10 | { 11 | DateTime a = Issue2(); 12 | var b = Issue2(); 13 | } 14 | 15 | public static T Issue2() where T : new() 16 | { 17 | return new T(); 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /_Examples/E02_BasicFeaturesExample/Index.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Examples.BasicFeaturesExample 2 | { 3 | 4 | [Page("index")] 5 | class Index : PhpDummy 6 | { 7 | [ScriptName("h")] 8 | public static void Header(string title) 9 | { 10 | Response.Echo(Doctypes.XHTML_Transitional); 11 | echo(PHP_EOL); 12 | Html.EchoTagOpen(Tags.Html); 13 | echo(PHP_EOL); 14 | Html.EchoTagOpen(Tags.Head); 15 | echo(PHP_EOL); 16 | { 17 | // put here your html tags 18 | Html.EchoTagBound(Tags.Title, htmlentities(title)); 19 | echo(PHP_EOL); 20 | } 21 | Html.EchoTagClose(Tags.Head); 22 | echo(PHP_EOL); 23 | Html.EchoTagOpen(Tags.Body); 24 | echo(PHP_EOL); 25 | } 26 | [ScriptName("f")] 27 | public static void Footer() 28 | { 29 | Html.EchoTagClose(Tags.Body); 30 | Html.EchoTagClose(Tags.Html); 31 | } 32 | public static void PhpMain() 33 | { 34 | Header("Welcome to CS2PHP"); 35 | echo("You can use echo just like in PHP"); 36 | Html.EchoTagBound(Tags.P, "Or use some helpers."); 37 | MultiplicationTable.ShowMultiplicationTable(10, 12); 38 | Footer(); 39 | } 40 | 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /_Examples/E02_BasicFeaturesExample/MultiplicationTable.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Examples.BasicFeaturesExample 2 | { 3 | 4 | [Module("class.multiplication-table")] 5 | public class MultiplicationTable : PhpDummy 6 | { 7 | [ScriptName("show_multiplication_table")] 8 | public static void ShowMultiplicationTable(int maxCol, int maxRow) 9 | { 10 | echo("\r\n"); 11 | for (int rowIdx = 1; rowIdx <= maxRow; rowIdx++) 12 | { 13 | echo("\r\n"); 14 | for (int ColIdx = 1; ColIdx <= maxCol; ColIdx++) 15 | { 16 | echo(""); 17 | Response.Echo(rowIdx * ColIdx); 18 | echo("\r\n"); 19 | } 20 | echo("\r\n"); 21 | } 22 | echo("\r\n"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /_Examples/E02_BasicFeaturesExample/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: Guid("edf2db09-c370-4edc-a0e6-95f7824c4754")] 5 | 6 | -------------------------------------------------------------------------------- /_Examples/E02_BasicFeaturesExample/SomeFolder/ClassInSubfolder.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Examples.BasicFeaturesExample.SomeFolder 2 | { 3 | 4 | [Module("SomeFolder/ClassInSubfolder")] 5 | public class ClassInSubfolder 6 | { 7 | public static void Hello() 8 | { 9 | PhpDummy.echo("ClassInSubfolder hello"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /_Examples/E02_BasicFeaturesExample/SwichCaseTest.cs: -------------------------------------------------------------------------------- 1 | namespace Lang.Php.Examples.BasicFeaturesExample 2 | { 3 | [Page("swich-case")] 4 | class SwichCaseTest : PhpDummy 5 | { 6 | public static void PhpMain() 7 | { 8 | int a = 2 * 3; 9 | switch (a) 10 | { 11 | case 1: 12 | case 2: 13 | case 3: 14 | echo("Something wrong"); 15 | break; 16 | case 6: 17 | echo("Everything is OK."); 18 | break; 19 | default: 20 | echo("Something really wrong"); 21 | break; 22 | 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /_Examples/E02_BasicFeaturesExample/compile.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set CS2PHP=..\..\Lang.Cs2Php\bin\Release\net472\cs2php.exe 3 | set PROJ=E02_BasicFeaturesExample 4 | %CS2PHP% %PROJ%.csproj ..\..\_ExamplesOut\%PROJ% 5 | 6 | 7 | -------------------------------------------------------------------------------- /_Examples/E02_BasicFeaturesExample/readme.txt: -------------------------------------------------------------------------------- 1 | Step by step instruction: 2 | 1. Compile solution with "Release" option 3 | 2. run "compile.bat" in the same directory as "E02_BasicFeaturesExample.csproj" file 4 | 3. Check result files in \_ExamplesOut\E02_BasicFeaturesExample folder -------------------------------------------------------------------------------- /_Examples/E03_ReferencedLibrary/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: Guid("6fed97bd-c008-407b-b866-60a574ccfa0b")] 5 | -------------------------------------------------------------------------------- /_Examples/E03_ReferencedLibrary/Test.cs: -------------------------------------------------------------------------------- 1 | using Lang.Php.Mpdf; 2 | 3 | namespace E03_ReferencedLibrary 4 | { 5 | public class Test 6 | { 7 | const double BASE_SIZE = 9; 8 | const string FONT = "dejavusans"; 9 | const double MARGIN = 10; 10 | const double MARGIN_HEADER = 9; 11 | 12 | 13 | public void PhpMain() 14 | { 15 | var mpdf = new Mpdf("", "A4", 16 | BASE_SIZE, FONT, 17 | MARGIN, MARGIN, MARGIN, MARGIN, MARGIN_HEADER, MARGIN_HEADER, PageOrientation.Portrait); 18 | mpdf.author = "Mr Compiler"; 19 | mpdf.title = "PDF title"; 20 | mpdf.subject = "PDF subject"; 21 | 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /_Examples/E03_ReferencedLibrary/compile.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set CS2PHP=..\..\Lang.Cs2Php\bin\Release\net472\cs2php.exe 3 | set OUTMAIN=..\..\_ExamplesOut\E03_ReferencedLibrary 4 | set OUTLIB=..\..\_ExamplesOut\CommonLib 5 | 6 | echo ---------- COMPILE Referenced library 7 | %CS2PHP% ..\..\Extensions\Lang.Php.Mpdf\Lang.Php.Mpdf.csproj %OUTLIB% 8 | 9 | echo ---------- COMPILE Main program 10 | %CS2PHP% E03_ReferencedLibrary.csproj %OUTMAIN% -lib Lang.Php.Mpdf=%OUTLIB% 11 | rem -r ..\..\Extensions\Lang.Php.Mpdf\bin\Release\Lang.Php.Mpdf.dll 12 | 13 | 14 | -------------------------------------------------------------------------------- /_Examples/E04_Graphics/IndexPage.cs: -------------------------------------------------------------------------------- 1 | using Lang.Php; 2 | 3 | namespace E04_Graphics 4 | { 5 | [Page("index")] 6 | public class IndexPage : PhpDummy 7 | { 8 | public static void PhpMain() 9 | { 10 | echo(Doctypes.XHTML_Transitional + PHP_EOL); 11 | Html.EchoTagOpen(Tags.Html); 12 | { 13 | Html.EchoTagOpen(Tags.Head); 14 | { 15 | Html.EchoTagBound(Tags.Title, "Dynamic image"); 16 | } 17 | Html.EchoTagClose(Tags.Head); 18 | } 19 | { 20 | Html.EchoTagOpen(Tags.Body); 21 | { 22 | var examples = new int[] { -1, 10, 50, 100 }; 23 | foreach (var i in examples) 24 | { 25 | var type = i < 0 ? "png" : "jpg"; 26 | if (i < 0) 27 | Html.EchoTagBound(Tags.P, "PNG"); 28 | else 29 | Html.EchoTagBound(Tags.P, "JPG, compression " + i); 30 | echo(PHP_EOL); 31 | Html.EchoTagBound(Tags.P, 32 | Html.TagSingle(Tags.Img, 33 | Attr.Src, "image.php?format=" + type + (i > 0 ? "&compression=" + i : ""), 34 | Attr.Alt, "Demo " + (i > 0 ? "jpg" : "png") + " image" 35 | ) 36 | ); 37 | echo(PHP_EOL); 38 | } 39 | } 40 | Html.EchoTagClose(Tags.Body); 41 | echo(PHP_EOL); 42 | } 43 | Html.EchoTagClose(Tags.Html); 44 | echo(PHP_EOL); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /_Examples/E04_Graphics/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | 5 | [assembly: Guid("0815d9ed-8313-4770-8780-a000b6d09243")] 6 | -------------------------------------------------------------------------------- /_Examples/E04_Graphics/ReadMe.txt: -------------------------------------------------------------------------------- 1 | How to use this example? 2 | ======================== 3 | 1. Make sure that CS2PHP solution is compiled in RELEASE mode. 4 | We need following file Lang.Cs2Php\bin\Release\net472\cs2php.exe 5 | 2. Run compile.bat 6 | 3. Look into _ExamplesOut\E04_Graphics 7 | 8 | What is in example? 9 | ============= 10 | Example shows how to create image dynamically and embed it within web page. 11 | -------------------------------------------------------------------------------- /_Examples/E04_Graphics/compile.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set CS2PHP=..\..\Lang.Cs2Php\bin\Release\net472\cs2php.exe 3 | set PROJ=E04_Graphics 4 | %CS2PHP% %PROJ%.csproj ..\..\_ExamplesOut\%PROJ% 5 | 6 | 7 | -------------------------------------------------------------------------------- /_Examples/E05_Firebird/Person.cs: -------------------------------------------------------------------------------- 1 | using Lang.Php; 2 | 3 | namespace E05_Firebird 4 | { 5 | [AsArray] 6 | [Skip] 7 | class Person 8 | { 9 | [AsValue] 10 | public const string FieldNames = FnId + "," + FnFirstName + "," + FnLastName; 11 | 12 | [AsValue] 13 | public const string FnId = "ID"; 14 | [AsValue] 15 | public const string FnFirstName = "FIRSTNAME"; 16 | [AsValue] 17 | public const string FnLastName = "LASTNAME"; 18 | [ScriptName(FnId)] 19 | public int Id { get; set; } 20 | 21 | [ScriptName(FnFirstName)] 22 | public string FirstName { get; set; } 23 | [ScriptName(FnLastName)] 24 | public string LastnNme { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /_Examples/E05_Firebird/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: Guid("17a39d61-70d3-4cba-be6f-b8bdfda543c7")] 5 | -------------------------------------------------------------------------------- /_Examples/E05_Firebird/compile.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set CS2PHP=..\..\Lang.Cs2Php\bin\Release\net472\cs2php.exe 3 | set PROJ=E05_Firebird 4 | %CS2PHP% %PROJ%.csproj ..\..\_ExamplesOut\%PROJ% 5 | 6 | 7 | -------------------------------------------------------------------------------- /_Examples/E06_Regex/E06_Regex.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.2.1.1 4 | net472 5 | E06_Regex 6 | E06_Regex 7 | E06_Regex 8 | Lang.Php.Examples.Regex 9 | true 10 | true 11 | false 12 | true 13 | false 14 | true 15 | false 16 | false 17 | false 18 | false 19 | false 20 | 21 | 22 | bin\$(Configuration)\net472\$(ProjectName).xml 23 | 24 | 25 | $(DefineConstants);ROSLYN 26 | 27 | 28 | 29 | CommonAssemblyInfo.cs 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /_Examples/E06_Regex/Index.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Lang.Php; 3 | 4 | namespace E06_Regex 5 | { 6 | [Page("index")] 7 | [IgnoreNamespace] 8 | public class Index : PhpDummy 9 | { 10 | public static void PhpMain() 11 | { 12 | PhpStyle(); 13 | WithOffset(); 14 | } 15 | 16 | private static void WithOffset() 17 | { 18 | Dictionary matchWithOffsets; 19 | Dictionary matches; 20 | var a = Preg.Match("/hello/i", "a Hello x", out matches, 2); 21 | var b = Preg.Match("/hello/i", "a Hello x"); 22 | var c = Preg.MatchWithOffset("/hello/i", "ó Hello world", out matchWithOffsets); 23 | echo("We have " + matchWithOffsets[0].Value + " at " + matchWithOffsets[0].Offset); 24 | } 25 | 26 | private static void PhpStyle() 27 | { 28 | Dictionary matches; 29 | var a = preg_match("/hello/i", "Hello world", out matches); 30 | if (a.IsError) 31 | echo("preg_match: Error"); 32 | else if (a.IsSuccess) 33 | echo("preg_match: Match"); 34 | else 35 | echo("preg_match: Don't match"); 36 | 37 | var_dump(matches); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /_Examples/E06_Regex/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | 5 | [assembly: Guid("caaad3a9-92e9-4a2c-8626-2fc7ae5c0b42")] 6 | -------------------------------------------------------------------------------- /_Examples/E06_Regex/compile.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set CS2PHP=..\..\Lang.Cs2Php\bin\Release\net472\cs2php.exe 3 | %CS2PHP% E06_Regex.csproj ..\..\_ExamplesOut\E06_Regex 4 | 5 | 6 | -------------------------------------------------------------------------------- /_Examples/WP01_BasicFeatures/Class1.cs: -------------------------------------------------------------------------------- 1 | namespace WP01_BasicFeatures 2 | { 3 | public class Class1 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /_Examples/WP01_BasicFeatures/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: Guid("583eeb91-7651-46e7-86b6-21f5126943b8")] 5 | -------------------------------------------------------------------------------- /_ExamplesOut/E01_HelloWorld/index.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /_ExamplesOut/E01_HelloWorld/readme.txt: -------------------------------------------------------------------------------- 1 | Step by step instruction: 2 | 1. Compile solution with "Release" option 3 | 2. run "compile.bat" in the same directory as "E01_HelloWorld.csproj" file 4 | 3. Check result files in \_ExamplesOut\E01_HelloWorld folder -------------------------------------------------------------------------------- /_ExamplesOut/E02_BasicFeaturesExample/SomeFolder/ClassInSubfolder.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /_ExamplesOut/E02_BasicFeaturesExample/class.complex-number.php: -------------------------------------------------------------------------------- 1 | Real = $real; 11 | $this->Imaginary = $imaginary; 12 | } 13 | public static function minus($a, $b) { 14 | return new self($a->Real - $b->Real, $a->Imaginary - $b->Imaginary); 15 | } 16 | public static function plus($a, $b) { 17 | return new self($a->Real + $b->Real, $a->Imaginary + $b->Imaginary); 18 | } 19 | public static function op_Implicit($x) { 20 | return new self($x, 0); 21 | } 22 | public static function mul1($a, $b) { 23 | return new self($a->Real * $b->Real - $a->Imaginary * $b->Imaginary, $a->Real * $b->Imaginary + $a->Imaginary * $b->Real); 24 | } 25 | public static function mul2($a, $b) { 26 | return new self($a->Real * $b, $a->Imaginary * $b); 27 | } 28 | public static function op_Division($a, $b) { 29 | $tmp = $b->Real * $b->Real + $b->Imaginary * $b->Imaginary; 30 | $re = $a->Real * $b->Real + $a->Imaginary * $b->Imaginary; 31 | $im = $a->Imaginary * $b->Real - $a->Real * $b->Imaginary; 32 | return new self($re / $tmp, $im / $tmp); 33 | } 34 | } 35 | } 36 | ?> -------------------------------------------------------------------------------- /_ExamplesOut/E02_BasicFeaturesExample/class.multiplication-table.php: -------------------------------------------------------------------------------- 1 | ' . PHP_EOL; 9 | for($rowIdx = 1; $rowIdx <= $maxRow; $rowIdx++) 10 | { 11 | echo '' . PHP_EOL; 12 | for($ColIdx = 1; $ColIdx <= $maxCol; $ColIdx++) 13 | echo '' . ($rowIdx * $ColIdx) . '' . PHP_EOL; 14 | echo '' . PHP_EOL; 15 | } 16 | echo '' . PHP_EOL; 17 | } 18 | } 19 | } 20 | ?> -------------------------------------------------------------------------------- /_ExamplesOut/E02_BasicFeaturesExample/complex-number-test.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /_ExamplesOut/E02_BasicFeaturesExample/index.php: -------------------------------------------------------------------------------- 1 | ' . (PHP_EOL) . '' . (PHP_EOL) . '' . (PHP_EOL) . '' . htmlentities($title) . '' . (PHP_EOL) . '' . (PHP_EOL) . '' . (PHP_EOL); 12 | } 13 | public static function f() { 14 | echo ''; 15 | } 16 | public static function PhpMain() { 17 | self::h('Welcome to CS2PHP'); 18 | echo 'You can use echo just like in PHPOr use some helpers.'; 19 | MultiplicationTable::show_multiplication_table(10, 12); 20 | self::f(); 21 | } 22 | } 23 | } 24 | namespace { 25 | \Lang\Php\Examples\BasicFeaturesExample\Index::PhpMain(); 26 | } 27 | ?> -------------------------------------------------------------------------------- /_ExamplesOut/E02_BasicFeaturesExample/readme.txt: -------------------------------------------------------------------------------- 1 | Step by step instruction: 2 | 1. Compile solution with "Release" option 3 | 2. run "compile.bat" in the same directory as "E02_BasicFeaturesExample.csproj" file 4 | 3. Check result files in \_ExamplesOut\E02_BasicFeaturesExample folder -------------------------------------------------------------------------------- /_ExamplesOut/E02_BasicFeaturesExample/swich-case.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /_ExamplesOut/E03_ReferencedLibrary/E03_ReferencedLibrary_Test.php: -------------------------------------------------------------------------------- 1 | author = 'Mr Compiler'; 17 | $mpdf->title = 'PDF title'; 18 | $mpdf->subject = 'PDF subject'; 19 | } 20 | } 21 | ?> -------------------------------------------------------------------------------- /_ExamplesOut/E03_ReferencedLibrary/cs2php.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /_ExamplesOut/E04_Graphics/index.php: -------------------------------------------------------------------------------- 1 | ' . PHP_EOL; 9 | echo 'Dynamic image'; 10 | $examples = array(-1, 10, 50, 100); 11 | foreach($examples as $i) 12 | { 13 | $type = $i < 0 ? 'png' : 'jpg'; 14 | if ($i < 0) 15 | echo 'PNG'; 16 | else 17 | echo 'JPG, compression ' . $i . ''; 18 | echo "\r\n 0 ? '&compression=' . $i : '') . '" alt="Demo ' . ($i > 0 ? 'jpg' : 'png') . ' image" />' . PHP_EOL; 19 | } 20 | echo '' . PHP_EOL; 21 | echo '' . PHP_EOL; 22 | } 23 | } 24 | IndexPage::PhpMain(); 25 | ?> -------------------------------------------------------------------------------- /_ExamplesOut/E06_Regex/index.php: -------------------------------------------------------------------------------- 1 | --------------------------------------------------------------------------------
You can use echo just like in PHP
Or use some helpers.
PNG
JPG, compression ' . $i . '
0 ? '&compression=' . $i : '') . '" alt="Demo ' . ($i > 0 ? 'jpg' : 'png') . ' image" />