public static void DefaultAutoload(NamingContext namingContext, DTypeDesc caller, string className) { // TODO: skip in pure mode var context = ScriptContext.CurrentContext; var fileExtensions = context.SplAutoloadExtensions.GetEnumerator(); bool stateChanged = true; while (!stateChanged || ScriptContext.CurrentContext.ResolveType(className, namingContext, caller, null, ResolveTypeFlags.None) == null) { if (!fileExtensions.MoveNext()) { PhpException.Throw(PhpError.Error, string.Format(CoreResources.class_could_not_be_loaded, className)); return; } // try to dynamically include the file specified by the class name, if it exists string FullFileName = className + fileExtensions.Current; if (PhpFile.Exists(FullFileName)) { context.DynamicInclude(FullFileName, context.WorkingDirectory, null, null, null, InclusionTypes.IncludeOnce); stateChanged = true; } else { stateChanged = false; } } }
public static bool ChangeFileMode(string path, int mode) { StreamWrapper wrapper; if (!PhpStream.ResolvePath(ref path, out wrapper, CheckAccessMode.FileOrDirectory, CheckAccessOptions.Empty)) { return(false); } bool isDir = PhpFile.IsDirectory(path); FileSystemInfo fInfo = isDir ? (FileSystemInfo) new DirectoryInfo(path) : new FileInfo(path); if (!fInfo.Exists) { PhpException.Throw(PhpError.Warning, CoreResources.GetString("invalid_path", path)); return(false); } //Directories has no equivalent of a readonly flag, //instead, their content permission should be adjusted accordingly //[http://msdn.microsoft.com/en-us/library/system.security.accesscontrol.directorysecurity.aspx] if (isDir) { //DirectoryInfo dInfo = (DirectoryInfo)fInfo; //DirectorySecurity dSecurity = dInfo.GetAccessControl(); //foreach(FileSystemAccessRule rule in ResolveAccessRules(mode)) // dSecurity.AddAccessRule(rule); //try //{ // dInfo.SetAccessControl(dSecurity); //} //catch { return(false); } } else { // according to <io.h> and <chmod.c> from C libraries in Visual Studio 2008 // and PHP 5.3 source codes, which are using standard _chmod() function in C // on Windows it only changes the ReadOnly flag of the file // // see <chmod.c> for more details /* #define _S_IREAD 0x0100 // read permission, owner #define _S_IWRITE 0x0080 // write permission, owner #define _S_IEXEC 0x0040 // execute/search permission, owner */ ((FileInfo)fInfo).IsReadOnly = ((mode & 0x0080) == 0); } return(true); }
public static PhpArray GetMetaTags(string fileName, FileOpenOptions flags) { PhpArray result = new PhpArray(); ScriptContext context = ScriptContext.CurrentContext; if (getMetaTagsRegex == null) { getMetaTagsRegex = new Regex(@"^meta\s+name\s*=\s*(?:(\w*)|'([^']*)'|\u0022([^\u0022]*)\u0022)\s+" + @"content\s*=\s*(?:(\w*)|'([^']*)'|\u0022([^\u0022]*)\u0022)\s*/?$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); } try { PhpStream stream = PhpStream.Open(fileName, "rt", PhpFile.ProcessOptions(flags)); StringBuilder tag = new StringBuilder(); bool in_brackets = false; int in_quotes = 0; // 1 = ', 2 = " int in_comment = 0; // 1 = <, 2 = <!, 3 = <!-, 4 = <!--, 5 = <!-- -, 6 <!-- -- while (!stream.Eof) { int start_index = 0; string line = stream.ReadLine(-1, null); for (int i = 0; i < line.Length; i++) { switch (line[i]) { case '<': { if (!in_brackets && in_quotes == 0 && in_comment == 0) { in_brackets = true; in_comment = 1; start_index = i + 1; } break; } case '>': { if (in_brackets && in_quotes == 0 && in_comment != 4 && in_comment != 5) { in_brackets = false; in_comment = 0; if (start_index < i) { tag.Append(line, start_index, i - start_index); } string str = tag.ToString(); tag.Length = 0; // did we reach the end of <head>? if (str.Equals("/head", StringComparison.InvariantCultureIgnoreCase)) { return(result); } // try to match the tag with the <meta> regex Match match = getMetaTagsRegex.Match(str); if (match.Success) { string name = null, value = null; for (int j = 1; j <= 3; j++) { if (match.Groups[j].Success) { name = match.Groups[j].Value; break; } } if (name != null) { for (int j = 4; j <= 6; j++) { if (match.Groups[j].Success) { value = match.Groups[j].Value; break; } } result[name] = (value == null ? String.Empty : Core.Convert.Quote(value, context)); } } } break; } case '\'': { if (in_quotes == 0) { in_quotes = 1; } else if (in_quotes == 1) { in_quotes = 0; } break; } case '"': { if (in_quotes == 0) { in_quotes = 2; } else if (in_quotes == 2) { in_quotes = 0; } break; } case '!': if (in_comment == 1) { in_comment = 2; } break; case '-': if (in_comment >= 2 && in_comment < 6) { in_comment++; } break; default: { // reset comment state machine if (in_comment < 4) { in_comment = 0; } if (in_comment > 4) { in_comment = 4; } break; } } } if (in_brackets && start_index < line.Length) { tag.Append(line, start_index, line.Length - start_index); } } } catch (IOException) { return(null); } return(result); }