Skip to content

Commit 4cb8a0c

Browse files
author
J. Christopher Pereira
committed
Unix support
- Added PHP_OS (necessary for other commited patches) - Fixed absolute-path-includes
1 parent c170280 commit 4cb8a0c

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

Source/Core/ScriptContext.CLR.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,23 @@ private void InitConstants(DualDictionary<string, object> _constants)
289289
_constants.Add("PHP_RELEASE_VERSION", PhpVersion.Release, false);
290290
_constants.Add("PHP_VERSION_ID", PhpVersion.Major * 10000 + PhpVersion.Minor * 100 + PhpVersion.Release, false);
291291
_constants.Add("PHP_EXTRA_VERSION", PhpVersion.Extra, false);
292-
_constants.Add("PHP_OS", Environment.OSVersion.Platform == PlatformID.Win32NT ? "WINNT" : "WIN32", false); // TODO: GENERICS (Unix)
292+
293+
string php_os = "Unknown";
294+
switch (Environment.OSVersion.Platform)
295+
{
296+
case PlatformID.Win32NT:
297+
php_os = "WINNT";
298+
break;
299+
case PlatformID.Win32S:
300+
case PlatformID.Win32Windows:
301+
case PlatformID.WinCE:
302+
php_os = "WIN32";
303+
break;
304+
case PlatformID.Unix:
305+
php_os = "Linux";
306+
break;
307+
}
308+
_constants.Add("PHP_OS", php_os, false);
293309
_constants.Add("PHP_SAPI", (System.Web.HttpContext.Current == null) ? "cli" : "isapi", false);
294310
_constants.Add("DIRECTORY_SEPARATOR", FullPath.DirectorySeparatorString, false);
295311
_constants.Add("PATH_SEPARATOR", Path.PathSeparator.ToString(), false);
@@ -574,6 +590,14 @@ public object DynamicInclude(
574590
DTypeDesc includer,
575591
InclusionTypes inclusionType)
576592
{
593+
if (Environment.OSVersion.Platform == PlatformID.Unix)
594+
{
595+
// Fix for absolute-path-includes on Unix filesystems.
596+
// Example: include_once('/path/app\libs\include.php')
597+
// HACK: Translate "\" to "/"
598+
includerFileRelPath = includerFileRelPath.Replace('\\', '/');
599+
}
600+
577601
ApplicationConfiguration app_config = Configuration.Application;
578602

579603
// determines inclusion behavior:

0 commit comments

Comments
 (0)