Example #1
0
        /// <summary>
        /// Merges the path with the current working directory
        /// to get a canonicalized absolute pathname representing the same path
        /// (local files only). If the provided <paramref name="path"/>
        /// is absolute (rooted local path or an URL) it is returned unchanged.
        /// </summary>
        /// <param name="path">An absolute or relative path to a directory or an URL.</param>
        /// <returns>Canonicalized absolute path in case of a local directory or the original
        /// <paramref name="path"/> in case of an URL.</returns>
        internal static string AbsolutePath(string path)
        {
            // Don't combine remote file paths with CWD.
            try
            {
                if (IsRemoteFile(path))
                {
                    return(path);
                }

                // Remove the file:// schema if any.
                path = GetFilename(path);

                // Combine the path and simplify it.
                string combinedPath = Path.Combine(PhpDirectory.GetWorking(), path);

                // Note: GetFullPath handles "C:" incorrectly
                if (combinedPath[combinedPath.Length - 1] == ':')
                {
                    combinedPath += '\\';
                }
                return(Path.GetFullPath(combinedPath));
            }
            catch (Exception)
            {
                PhpException.Throw(PhpError.Notice,
                                   LibResources.GetString("invalid_path", FileSystemUtils.StripPassword(path)));
                return(null);
            }
        }
Example #2
0
        public object read(ScriptContext context, [Optional] object handle)
        {
            PhpResource res = (handle == Arg.Default ? this.handle.Value : handle) as PhpResource;

            if (res == null)
            {
                PhpException.InvalidImplicitCast("handle", PhpResource.PhpTypeName, "read");
                return(null);
            }

            return(PhpDirectory.Read(res));
        }
Example #3
0
 /// <summary>
 /// Start listing of a directory (intended to be used from C#).
 /// </summary>
 /// <param name="directory">The path to the directory.</param>
 public Directory(string directory)
     : this(ScriptContext.CurrentContext, true)
 {
     this.path   = new PhpReference(directory);
     this.handle = new PhpReference(PhpDirectory.Open(directory));
 }