Rust

path

Module

Path functions.

Contents

use php_std::path::basename;
Rust
pub fn basename<'a>(path: &'a [u8], suffix: &[u8]) -> &'a [u8]

PHP basename($path, $suffix) (Unix separators), as php_basename: the last component, trailing slashes ignored, with suffix removed when the component ends with it and is longer than it.

Rust
use php_std::path::basename;

assert_eq!(basename(b"/tmp/report.pdf/", b""), b"report.pdf");
assert_eq!(basename(b"/tmp/report.pdf", b".pdf"), b"report");
assert_eq!(basename(b"/", b""), b"");
use php_std::path::dirname;
Rust
pub fn dirname(path: &str) -> String

PHP dirname($path) (one level, Unix separators), as zend_dirname.

use php_std::path::expand_filepath;
Rust
pub fn expand_filepath(path: &[u8]) -> Option<Vec<u8>>

expand_filepath(): the absolute path PHP opens for path. A relative path is resolved against the working directory, then . and .. components and repeated slashes are removed lexically (a trailing slash stays), without resolving symbolic links. None for an empty path or one longer than MAXPATHLEN.

Rust
use php_std::path::expand_filepath;

assert_eq!(expand_filepath(b"/tmp/a/../b//c/."), Some(b"/tmp/b/c".to_vec()));
assert_eq!(expand_filepath(b"/.."), Some(b"/".to_vec()));
use php_std::path::file_get_contents;
Rust
pub fn file_get_contents(path: &[u8]) -> Option<Vec<u8>>

file_get_contents($path) for a plain file path: the bytes of the file at expand_filepath(path), or None where PHP returns false (no such file, a directory, no permission). Paths with a NUL byte are None; PHP functions raise a \ValueError for them before opening.

use php_std::path::pathinfo_extension;
Rust
pub fn pathinfo_extension(path: &[u8]) -> &[u8]

PHP pathinfo($path, PATHINFO_EXTENSION): what follows the last . of basename, or an empty string when it has no ..

Rust
use php_std::path::pathinfo_extension;

assert_eq!(pathinfo_extension(b"server/pages/index.html"), b"html");
assert_eq!(pathinfo_extension(b"archive.tar.gz"), b"gz");
assert_eq!(pathinfo_extension(b"Dockerfile"), b"");
assert_eq!(pathinfo_extension(b".env"), b"env");