diff --git a/lazarus/lib/x86_64-linux/phpgui.o b/lazarus/lib/x86_64-linux/phpgui.o index c4ead83..4c692ee 100644 Binary files a/lazarus/lib/x86_64-linux/phpgui.o and b/lazarus/lib/x86_64-linux/phpgui.o differ diff --git a/lazarus/lib/x86_64-linux/phpgui.or b/lazarus/lib/x86_64-linux/phpgui.or index 5b9e7a0..c63151a 100644 Binary files a/lazarus/lib/x86_64-linux/phpgui.or and b/lazarus/lib/x86_64-linux/phpgui.or differ diff --git a/lazarus/lib/x86_64-linux/unit1.ppu b/lazarus/lib/x86_64-linux/unit1.ppu index 1a7f3e7..38b002b 100644 Binary files a/lazarus/lib/x86_64-linux/unit1.ppu and b/lazarus/lib/x86_64-linux/unit1.ppu differ diff --git a/lazarus/lib/x86_64-linux/unitipcthread.o b/lazarus/lib/x86_64-linux/unitipcthread.o index 647c641..87f5af8 100644 Binary files a/lazarus/lib/x86_64-linux/unitipcthread.o and b/lazarus/lib/x86_64-linux/unitipcthread.o differ diff --git a/lazarus/lib/x86_64-linux/unitipcthread.ppu b/lazarus/lib/x86_64-linux/unitipcthread.ppu index 8b51f9e..e6962cf 100644 Binary files a/lazarus/lib/x86_64-linux/unitipcthread.ppu and b/lazarus/lib/x86_64-linux/unitipcthread.ppu differ diff --git a/lazarus/phpgui-i386-darwin b/lazarus/phpgui-i386-darwin index 556d221..7fc9bc0 100755 Binary files a/lazarus/phpgui-i386-darwin and b/lazarus/phpgui-i386-darwin differ diff --git a/lazarus/phpgui-i386-freebsd b/lazarus/phpgui-i386-freebsd new file mode 100644 index 0000000..f3a777d Binary files /dev/null and b/lazarus/phpgui-i386-freebsd differ diff --git a/lazarus/phpgui-i386-linux b/lazarus/phpgui-i386-linux new file mode 100644 index 0000000..b8477a9 Binary files /dev/null and b/lazarus/phpgui-i386-linux differ diff --git a/lazarus/phpgui-i386-win32.exe b/lazarus/phpgui-i386-win32.exe index e1bb661..a0086fd 100644 Binary files a/lazarus/phpgui-i386-win32.exe and b/lazarus/phpgui-i386-win32.exe differ diff --git a/lazarus/phpgui-x86_64-darwin b/lazarus/phpgui-x86_64-darwin new file mode 100644 index 0000000..22e2ba7 Binary files /dev/null and b/lazarus/phpgui-x86_64-darwin differ diff --git a/lazarus/phpgui-x86_64-darwin.app/Contents/Info.plist b/lazarus/phpgui-x86_64-darwin.app/Contents/Info.plist new file mode 100644 index 0000000..3dee426 --- /dev/null +++ b/lazarus/phpgui-x86_64-darwin.app/Contents/Info.plist @@ -0,0 +1,45 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + phpgui-x86_64-darwin + CFBundleName + phpgui + CFBundleIdentifier + com.company.phpgui-x86_64-darwin + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + APPL + CFBundleSignature + phpg + CFBundleShortVersionString + 0.1 + CFBundleVersion + 1 + CSResourcesFileMapped + + CFBundleDocumentTypes + + + CFBundleTypeRole + Viewer + CFBundleTypeExtensions + + * + + CFBundleTypeOSTypes + + fold + disk + **** + + + + NSHighResolutionCapable + + + diff --git a/lazarus/phpgui-x86_64-darwin.app/Contents/PkgInfo b/lazarus/phpgui-x86_64-darwin.app/Contents/PkgInfo new file mode 100644 index 0000000..6f749b0 --- /dev/null +++ b/lazarus/phpgui-x86_64-darwin.app/Contents/PkgInfo @@ -0,0 +1 @@ +APPL???? diff --git a/lazarus/phpgui-x86_64-freebsd b/lazarus/phpgui-x86_64-freebsd index a889850..2048a67 100755 Binary files a/lazarus/phpgui-x86_64-freebsd and b/lazarus/phpgui-x86_64-freebsd differ diff --git a/lazarus/phpgui-x86_64-linux b/lazarus/phpgui-x86_64-linux index 19a61a4..01128ac 100755 Binary files a/lazarus/phpgui-x86_64-linux and b/lazarus/phpgui-x86_64-linux differ diff --git a/lazarus/phpgui-x86_64-win64.exe b/lazarus/phpgui-x86_64-win64.exe index af742d0..127a981 100644 Binary files a/lazarus/phpgui-x86_64-win64.exe and b/lazarus/phpgui-x86_64-win64.exe differ diff --git a/lazarus/phpgui.lpi b/lazarus/phpgui.lpi index 692b577..fba1686 100644 --- a/lazarus/phpgui.lpi +++ b/lazarus/phpgui.lpi @@ -1,10 +1,12 @@ - + + + + - <ResourceType Value="res"/> <UseXPManifest Value="True"/> @@ -13,19 +15,66 @@ <i18n> <EnableI18N LFM="False"/> </i18n> - <VersionInfo> - <StringTable ProductVersion=""/> - </VersionInfo> - <BuildModes Count="1"> + <BuildModes Count="2"> <Item1 Name="Default" Default="True"/> + <Item2 Name="Debug"> + <CompilerOptions> + <Version Value="11"/> + <Target> + <Filename Value="phpgui-$(TargetCPU)-$(TargetOS)"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <OtherUnitFiles Value="."/> + <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <Parsing> + <SyntaxOptions> + <IncludeAssertionCode Value="True"/> + </SyntaxOptions> + </Parsing> + <CodeGeneration> + <Checks> + <IOChecks Value="True"/> + <RangeChecks Value="True"/> + <OverflowChecks Value="True"/> + <StackChecks Value="True"/> + </Checks> + <VerifyObjMethodCallValidity Value="True"/> + </CodeGeneration> + <Linking> + <Debugging> + <DebugInfoType Value="dsDwarf3"/> + <UseHeaptrc Value="True"/> + <TrashVariables Value="True"/> + <UseExternalDbgSyms Value="True"/> + </Debugging> + <Options> + <Win32> + <GraphicApplication Value="True"/> + </Win32> + </Options> + </Linking> + <Other> + <CustomOptions Value="-dUseCThreads"/> + <OtherDefines Count="1"> + <Define0 Value="UseCThreads"/> + </OtherDefines> + </Other> + </CompilerOptions> + </Item2> + <SharedMatrixOptions Count="1"> + <Item1 ID="765649312898" Type="IDEMacro" MacroName="LCLWidgetType" Value="cocoa"/> + </SharedMatrixOptions> </BuildModes> <PublishOptions> <Version Value="2"/> </PublishOptions> <RunParams> - <local> - <FormatVersion Value="1"/> - </local> + <FormatVersion Value="2"/> + <Modes Count="1"> + <Mode0 Name="default"/> + </Modes> </RunParams> <RequiredPackages Count="1"> <Item1> diff --git a/lazarus/phpgui.lps b/lazarus/phpgui.lps index a2fff4a..1d13e67 100644 --- a/lazarus/phpgui.lps +++ b/lazarus/phpgui.lps @@ -1,15 +1,327 @@ <?xml version="1.0" encoding="UTF-8"?> <CONFIG> <ProjectSession> - <Version Value="9"/> - <BuildModes Active="Default"/> - <Units Count="15"> + <Version Value="12"/> + <BuildModes Count="8" Active="Release-darwin64"> + <Item1 Name="Release-win64"> + <CompilerOptions> + <Version Value="11"/> + <Target> + <Filename Value="phpgui-$(TargetCPU)-$(TargetOS)"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <OtherUnitFiles Value="."/> + <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <CodeGeneration> + <SmartLinkUnit Value="True"/> + <TargetCPU Value="x86_64"/> + <TargetOS Value="win64"/> + <Optimizations> + <OptimizationLevel Value="3"/> + </Optimizations> + </CodeGeneration> + <Linking> + <Debugging> + <GenerateDebugInfo Value="False"/> + </Debugging> + <LinkSmart Value="True"/> + <Options> + <Win32> + <GraphicApplication Value="True"/> + </Win32> + </Options> + </Linking> + <Other> + <CustomOptions Value="-dUseCThreads"/> + <OtherDefines Count="1"> + <Define0 Value="UseCThreads"/> + </OtherDefines> + </Other> + </CompilerOptions> + </Item1> + <Item2 Name="Release-win32"> + <CompilerOptions> + <Version Value="11"/> + <Target> + <Filename Value="phpgui-$(TargetCPU)-$(TargetOS)"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <OtherUnitFiles Value="."/> + <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <CodeGeneration> + <SmartLinkUnit Value="True"/> + <TargetCPU Value="i386"/> + <TargetOS Value="win32"/> + <Optimizations> + <OptimizationLevel Value="3"/> + </Optimizations> + </CodeGeneration> + <Linking> + <Debugging> + <GenerateDebugInfo Value="False"/> + </Debugging> + <LinkSmart Value="True"/> + <Options> + <Win32> + <GraphicApplication Value="True"/> + </Win32> + </Options> + </Linking> + <Other> + <CustomOptions Value="-dUseCThreads"/> + <OtherDefines Count="1"> + <Define0 Value="UseCThreads"/> + </OtherDefines> + </Other> + </CompilerOptions> + </Item2> + <Item3 Name="Release-lin64"> + <CompilerOptions> + <Version Value="11"/> + <Target> + <Filename Value="phpgui-$(TargetCPU)-$(TargetOS)"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <OtherUnitFiles Value="."/> + <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <CodeGeneration> + <SmartLinkUnit Value="True"/> + <TargetCPU Value="x86_64"/> + <TargetOS Value="linux"/> + <Optimizations> + <OptimizationLevel Value="3"/> + </Optimizations> + </CodeGeneration> + <Linking> + <Debugging> + <GenerateDebugInfo Value="False"/> + </Debugging> + <LinkSmart Value="True"/> + <Options> + <Win32> + <GraphicApplication Value="True"/> + </Win32> + </Options> + </Linking> + <Other> + <CustomOptions Value="-dUseCThreads"/> + <OtherDefines Count="1"> + <Define0 Value="UseCThreads"/> + </OtherDefines> + </Other> + </CompilerOptions> + </Item3> + <Item4 Name="Release-lin32"> + <CompilerOptions> + <Version Value="11"/> + <Target> + <Filename Value="phpgui-$(TargetCPU)-$(TargetOS)"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <OtherUnitFiles Value="."/> + <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <CodeGeneration> + <SmartLinkUnit Value="True"/> + <TargetCPU Value="i386"/> + <TargetOS Value="linux"/> + <Optimizations> + <OptimizationLevel Value="3"/> + </Optimizations> + </CodeGeneration> + <Linking> + <Debugging> + <GenerateDebugInfo Value="False"/> + </Debugging> + <LinkSmart Value="True"/> + <Options> + <Win32> + <GraphicApplication Value="True"/> + </Win32> + </Options> + </Linking> + <Other> + <CustomOptions Value="-dUseCThreads"/> + <OtherDefines Count="1"> + <Define0 Value="UseCThreads"/> + </OtherDefines> + </Other> + </CompilerOptions> + </Item4> + <Item5 Name="Release-darwin32"> + <CompilerOptions> + <Version Value="11"/> + <Target> + <Filename Value="phpgui-$(TargetCPU)-$(TargetOS)"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <OtherUnitFiles Value="."/> + <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <CodeGeneration> + <SmartLinkUnit Value="True"/> + <TargetCPU Value="i386"/> + <TargetOS Value="darwin"/> + <Optimizations> + <OptimizationLevel Value="3"/> + </Optimizations> + </CodeGeneration> + <Linking> + <Debugging> + <GenerateDebugInfo Value="False"/> + </Debugging> + <LinkSmart Value="True"/> + <Options> + <Win32> + <GraphicApplication Value="True"/> + </Win32> + </Options> + </Linking> + <Other> + <CustomOptions Value="-dUseCThreads"/> + <OtherDefines Count="1"> + <Define0 Value="UseCThreads"/> + </OtherDefines> + </Other> + </CompilerOptions> + </Item5> + <Item6 Name="Release-darwin64"> + <MacroValues Count="1"> + <Macro1 Name="LCLWidgetType" Value="cocoa"/> + </MacroValues> + <CompilerOptions> + <Version Value="11"/> + <Target> + <Filename Value="phpgui-$(TargetCPU)-$(TargetOS)"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <OtherUnitFiles Value="."/> + <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <CodeGeneration> + <SmartLinkUnit Value="True"/> + <TargetCPU Value="x86_64"/> + <TargetOS Value="darwin"/> + <Optimizations> + <OptimizationLevel Value="3"/> + </Optimizations> + </CodeGeneration> + <Linking> + <Debugging> + <GenerateDebugInfo Value="False"/> + </Debugging> + <LinkSmart Value="True"/> + <Options> + <Win32> + <GraphicApplication Value="True"/> + </Win32> + </Options> + </Linking> + <Other> + <CustomOptions Value="-dUseCThreads"/> + <OtherDefines Count="1"> + <Define0 Value="UseCThreads"/> + </OtherDefines> + </Other> + </CompilerOptions> + </Item6> + <Item7 Name="Release-fBSD64"> + <CompilerOptions> + <Version Value="11"/> + <Target> + <Filename Value="phpgui-$(TargetCPU)-$(TargetOS)"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <OtherUnitFiles Value="."/> + <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <CodeGeneration> + <SmartLinkUnit Value="True"/> + <TargetCPU Value="x86_64"/> + <TargetOS Value="freebsd"/> + <Optimizations> + <OptimizationLevel Value="3"/> + </Optimizations> + </CodeGeneration> + <Linking> + <Debugging> + <GenerateDebugInfo Value="False"/> + </Debugging> + <LinkSmart Value="True"/> + <Options> + <Win32> + <GraphicApplication Value="True"/> + </Win32> + </Options> + </Linking> + <Other> + <CustomOptions Value="-dUseCThreads"/> + <OtherDefines Count="1"> + <Define0 Value="UseCThreads"/> + </OtherDefines> + </Other> + </CompilerOptions> + </Item7> + <Item8 Name="Release-fBSD32"> + <CompilerOptions> + <Version Value="11"/> + <Target> + <Filename Value="phpgui-$(TargetCPU)-$(TargetOS)"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <OtherUnitFiles Value="."/> + <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <CodeGeneration> + <SmartLinkUnit Value="True"/> + <TargetCPU Value="i386"/> + <TargetOS Value="freebsd"/> + <Optimizations> + <OptimizationLevel Value="3"/> + </Optimizations> + </CodeGeneration> + <Linking> + <Debugging> + <GenerateDebugInfo Value="False"/> + </Debugging> + <LinkSmart Value="True"/> + <Options> + <Win32> + <GraphicApplication Value="True"/> + </Win32> + </Options> + </Linking> + <Other> + <CustomOptions Value="-dUseCThreads"/> + <OtherDefines Count="1"> + <Define0 Value="UseCThreads"/> + </OtherDefines> + </Other> + </CompilerOptions> + </Item8> + <SessionEnabledMatrixOptions Count="1"> + <Item1 Mode="Release-darwin64" Option="765649312898"/> + </SessionEnabledMatrixOptions> + </BuildModes> + <ManyBuildModesSelection Value="Release-win64,Release-win32,Release-lin64,Release-lin32,Release-darwin32,Release-darwin64,Release-fBSD64,Release-fBSD32"/> + <Units Count="17"> <Unit0> <Filename Value="phpgui.lpr"/> <IsPartOfProject Value="True"/> - <EditorIndex Value="4"/> + <EditorIndex Value="2"/> <CursorPos X="4" Y="23"/> - <UsageCount Value="181"/> + <UsageCount Value="186"/> <Loaded Value="True"/> </Unit0> <Unit1> @@ -20,7 +332,7 @@ <ResourceBaseClass Value="Form"/> <UnitName Value="Unit1"/> <CursorPos X="21" Y="15"/> - <UsageCount Value="181"/> + <UsageCount Value="186"/> <Loaded Value="True"/> <LoadedDesigner Value="True"/> </Unit1> @@ -30,9 +342,9 @@ <UnitName Value="UnitIpcThread"/> <IsVisibleTab Value="True"/> <EditorIndex Value="1"/> - <TopLine Value="140"/> - <CursorPos X="31" Y="181"/> - <UsageCount Value="177"/> + <TopLine Value="43"/> + <CursorPos X="65" Y="64"/> + <UsageCount Value="182"/> <Loaded Value="True"/> </Unit2> <Unit3> @@ -44,11 +356,10 @@ </Unit3> <Unit4> <Filename Value="/usr/local/share/fpcsrc/rtl/objpas/classes/classesh.inc"/> - <EditorIndex Value="3"/> + <EditorIndex Value="-1"/> <TopLine Value="855"/> <CursorPos X="28" Y="876"/> <UsageCount Value="18"/> - <Loaded Value="True"/> </Unit4> <Unit5> <Filename Value="/Developer/lazarus/lcl/include/control.inc"/> @@ -76,14 +387,14 @@ <Filename Value="/usr/local/share/fpcsrc/packages/fcl-base/src/rttiutils.pp"/> <EditorIndex Value="-1"/> <CursorPos X="15" Y="32"/> - <UsageCount Value="0"/> + <UsageCount Value="10"/> </Unit8> <Unit9> <Filename Value="/usr/local/share/fpcsrc/rtl/objpas/typinfo.pp"/> <EditorIndex Value="-1"/> <TopLine Value="343"/> <CursorPos X="79" Y="348"/> - <UsageCount Value="0"/> + <UsageCount Value="10"/> </Unit9> <Unit10> <Filename Value="/usr/local/share/fpcsrc/rtl/objpas/sysutils/sysstrh.inc"/> @@ -118,17 +429,32 @@ <Unit14> <Filename Value="/usr/local/share/fpcsrc/packages/fcl-process/src/pipes.pp"/> <UnitName Value="Pipes"/> - <EditorIndex Value="2"/> + <EditorIndex Value="-1"/> <TopLine Value="12"/> <CursorPos X="3" Y="31"/> <UsageCount Value="18"/> - <Loaded Value="True"/> </Unit14> + <Unit15> + <Filename Value="s:/fpc-lazarus/lazarus/lcl/interfaces/carbon/carbonbars.pp"/> + <UnitName Value="CarbonBars"/> + <EditorIndex Value="-1"/> + <TopLine Value="34"/> + <CursorPos X="42" Y="4"/> + <UsageCount Value="10"/> + </Unit15> + <Unit16> + <Filename Value="s:/fpc-lazarus/lazarus/lcl/interfaces/carbon/carbondef.pp"/> + <UnitName Value="CarbonDef"/> + <EditorIndex Value="-1"/> + <TopLine Value="170"/> + <CursorPos Y="187"/> + <UsageCount Value="10"/> + </Unit16> </Units> <OtherDefines Count="1"> <Define0 Value="UseCThreads"/> </OtherDefines> - <JumpHistory Count="10" HistoryIndex="9"> + <JumpHistory Count="9" HistoryIndex="8"> <Position1> <Filename Value="unit1.pas"/> <Caret Line="14" Column="24"/> @@ -154,32 +480,32 @@ <Caret Line="181" Column="31" TopLine="110"/> </Position6> <Position7> - <Filename Value="/usr/local/share/fpcsrc/packages/fcl-process/src/pipes.pp"/> - <Caret Line="31" Column="3" TopLine="12"/> + <Filename Value="unitipcthread.pas"/> + <Caret Line="426" Column="43" TopLine="421"/> </Position7> <Position8> - <Filename Value="/usr/local/share/fpcsrc/rtl/objpas/classes/classesh.inc"/> - <Caret Line="919" Column="3" TopLine="898"/> + <Filename Value="unitipcthread.pas"/> + <Caret Line="467" Column="18" TopLine="456"/> </Position8> <Position9> - <Filename Value="/usr/local/share/fpcsrc/rtl/objpas/classes/classesh.inc"/> - <Caret Line="872" Column="32" TopLine="843"/> + <Filename Value="unitipcthread.pas"/> + <Caret Line="488" Column="84" TopLine="368"/> </Position9> - <Position10> - <Filename Value="/usr/local/share/fpcsrc/rtl/objpas/classes/classesh.inc"/> - <Caret Line="876" Column="28" TopLine="843"/> - </Position10> </JumpHistory> + <RunParams> + <FormatVersion Value="2"/> + <Modes ActiveMode="default"/> + </RunParams> </ProjectSession> <Debugging> - <BreakPoints Count="1"> - <Item1> + <BreakPoints> + <Item> <Kind Value="bpkSource"/> <WatchScope Value="wpsLocal"/> <WatchKind Value="wpkWrite"/> <Source Value="unit1.pas"/> <Line Value="50"/> - </Item1> + </Item> </BreakPoints> </Debugging> </CONFIG> diff --git a/lazarus/phpgui.res b/lazarus/phpgui.res index 1c1de50..ec1c7cc 100644 Binary files a/lazarus/phpgui.res and b/lazarus/phpgui.res differ diff --git a/lazarus/unitipcthread.pas b/lazarus/unitipcthread.pas index 89c12b2..efbccf1 100644 --- a/lazarus/unitipcthread.pas +++ b/lazarus/unitipcthread.pas @@ -53,6 +53,27 @@ TEventHandler = class(TObject) implementation +function Escape(input: string): string; +var + output: string; + i: integer; +begin + output := ''; + i := 0; + + while(i < Length(input)) do + begin + if (input[i+1] <> '"') AND (input[i+1] <> '\') then + begin + output := output + input[i+1]; + end else begin + output := output + '\' + input[i+1]; + end; + i := i + 1; + end; + Escape := output; +end; + procedure TIpcThread.CreateObject; var obj: TControl; objClass: TPersistentClass; @@ -464,7 +485,7 @@ procedure TIpcThread.CallObjectMethod; end; messageId := jData.FindPath('id').AsInteger; - Output('{"id": ' + IntToStr(messageId) + ', "result": "' + strCtrl[0] + '"}'); + Output('{"id": ' + IntToStr(messageId) + ', "result": "' + Escape(strCtrl[0]) + '"}'); sent := true; end; diff --git a/src/Application.php b/src/Application.php index 23712a3..ff6523b 100644 --- a/src/Application.php +++ b/src/Application.php @@ -9,6 +9,7 @@ use Gui\Ipc\Receiver; use Gui\Ipc\Sender; use Gui\OsDetector; +use http\Exception\RuntimeException; use React\ChildProcess\Process; use React\EventLoop\Factory; use React\EventLoop\LoopInterface; @@ -267,33 +268,13 @@ public function run() $application = $this; - if (OsDetector::isMacOS()) { - $processName = './phpgui-i386-darwin'; - $processPath = __DIR__ . '/../lazarus/phpgui-i386-darwin.app/Contents/MacOS/'; - } elseif (OsDetector::isFreeBSD()) { - $processName = './phpgui-x86_64-freebsd'; - $processPath = __DIR__ . '/../lazarus/'; - } elseif (OsDetector::isUnix()) { - switch(OsDetector::systemArchitecture()) { - case 'x86_64': - $processName = './phpgui-x86_64-linux'; - break; - case 'i686': - case 'i586': - case 'i386': - $processName = './phpgui-i386-linux'; - break; - default: - throw new \RuntimeException('Operational System architecture not identified by PHP-GUI.'); - break; - } - $processPath = __DIR__ . '/../lazarus/'; - } elseif (OsDetector::isWindows()) { - $processName = '.\\phpgui-x86_64-win64'; - $processPath = __DIR__ . '\\..\\lazarus\\'; - } else { - throw new \RuntimeException('Operational System not identified by PHP-GUI.'); - } + $processName = $this->getProcessName(); + $processPath = $this->getProcessPath(); + + $binPath = rtrim($processPath, "/\\") . DIRECTORY_SEPARATOR . ltrim($processName, ".\\/"); + if (!file_exists(realpath($binPath))) { + throw new \RuntimeException("Correct binary cannot be found (checked $binPath) by PHP-GUI."); + } $this->process = $process = new Process($processName, $processPath); @@ -487,4 +468,67 @@ public function isRunning() return $this->running; } + + /** + * Returns Lazarus process path, using correct slashes for current platform. + * + * @return string + */ + private function getProcessPath() + { + if (OsDetector::isWindows()) { + return __DIR__ . '\\..\\lazarus\\'; + } elseif (OsDetector::isMacOS()) { + return __DIR__ . '/../lazarus/phpgui-' . $this->getProcessArchId() .'-darwin.app/Contents/MacOS/'; + } else { + return __DIR__ . '/../lazarus/'; + } + } + + /** + * Returns Lazarus process name, selecting current platform. + * + * @return string + */ + private function getProcessName() + { + $arch = $this->getProcessArchId(); + $proc = "phpgui-" . $arch . "-"; + // mac, bsd, unix, windows + if (OsDetector::isMacOS()) { + return $proc . "darwin"; + } elseif (OsDetector::isFreeBSD()) { + return $proc . "freebsd"; + } elseif (OsDetector::isUnix()) { + return $proc . "linux"; + } elseif (OsDetector::isWindows()) { + if ($arch === "x86_64") { + return $proc . "win64.exe"; + } else { + return $proc . "win32.exe"; + } + } else { + throw new \RuntimeException('Operational System not identified by PHP-GUI.'); + } + } + + /** + * Returns processor architecture in such manner, that it fits file names (returns 'x86_64' or 'i386') + * + * @return string + */ + private function getProcessArchId() + { + switch (OsDetector::systemArchitecture()) { + case 'AMD64': + case 'x86_64': + return 'x86_64'; + case 'i686': + case 'i586': + case 'i386': + return 'i386'; + default: + throw new \RuntimeException('Operational System architecture not identified by PHP-GUI.'); + } + } }