aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-18 04:47:02 +0900
committernsfisis <nsfisis@gmail.com>2026-08-18 04:47:18 +0900
commitced1f9aa91ee36857fec9664c9ccd86ba2310821 (patch)
tree630ea3eb3b0e710403669de9ba6a78a421e182a8 /crates/shirabe/src/util
parent6b7c6cb9a3d1cdf93f261238c1edbc70706a33c7 (diff)
downloadphp-shirabe-ced1f9aa91ee36857fec9664c9ccd86ba2310821.tar.gz
php-shirabe-ced1f9aa91ee36857fec9664c9ccd86ba2310821.tar.zst
php-shirabe-ced1f9aa91ee36857fec9664c9ccd86ba2310821.zip
refactor(function-exists): drop checks for always-present capabilities
function_exists() returns false in PHP when a function is blocked by disable_functions, when its extension is not compiled in, or when the PHP version predates it. None of those apply to a native binary.
Diffstat (limited to 'crates/shirabe/src/util')
-rw-r--r--crates/shirabe/src/util/filesystem.rs44
-rw-r--r--crates/shirabe/src/util/http_downloader.rs6
-rw-r--r--crates/shirabe/src/util/platform.rs32
-rw-r--r--crates/shirabe/src/util/stream_context_factory.rs16
4 files changed, 19 insertions, 79 deletions
diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs
index 41b81b7b..2395d1cd 100644
--- a/crates/shirabe/src/util/filesystem.rs
+++ b/crates/shirabe/src/util/filesystem.rs
@@ -6,11 +6,11 @@ use crate::util::Silencer;
use shirabe_php_shim::{
ErrorException, LogicException, PhpMixed, PregMatches, RuntimeException, array_pop, basename,
chdir, clearstatcache, clearstatcache2, copy, dirname, explode, fclose, feof, file_exists,
- file_get_contents, file_put_contents, fileatime, filemtime, filesize, fopen, fread,
- function_exists, fwrite, implode, is_dir, is_file, is_link, is_readable, lstat, mkdir,
- php_regex, preg_is_match, preg_match, preg_replace, preg_replace_callback, rename, rmdir,
- rtrim, str_repeat, str_replace, strlen, strpos, strtoupper, strtr, substr, substr_count,
- symlink, touch, unlink, usleep, var_export,
+ file_get_contents, file_put_contents, fileatime, filemtime, filesize, fopen, fread, fwrite,
+ implode, is_dir, is_file, is_link, is_readable, lstat, mkdir, php_regex, preg_is_match,
+ preg_match, preg_replace, preg_replace_callback, rename, rmdir, rtrim, str_repeat, str_replace,
+ strlen, strpos, strtoupper, strtr, substr, substr_count, symlink, touch, unlink, usleep,
+ var_export,
};
use shirabe_symfony_filesystem::exception::IOException;
use shirabe_symfony_finder::Finder;
@@ -114,9 +114,6 @@ impl Filesystem {
}
/// Recursively remove a directory
- ///
- /// Uses the process component if proc_open is enabled on the PHP
- /// installation.
pub fn remove_directory(&mut self, directory: impl AsRef<Path>) -> anyhow::Result<bool> {
// TODO(bytes):
// This path is matched against a regex (remove_edge_cases) and passed to an
@@ -129,7 +126,7 @@ impl Filesystem {
directory.display()
))
})?;
- let edge_case_result = self.remove_edge_cases(directory, true)?;
+ let edge_case_result = self.remove_edge_cases(directory)?;
if let Some(r) = edge_case_result {
return Ok(r);
}
@@ -167,13 +164,6 @@ impl Filesystem {
}
/// Recursively remove a directory asynchronously
- ///
- /// Uses the process component if proc_open is enabled on the PHP
- /// installation.
- ///
- /// Takes the shared handle instead of `&mut self`: the Filesystem is borrowed only for the
- /// synchronous head and tail, never across the subprocess await, so sibling futures can keep
- /// using the same `Rc<RefCell<Filesystem>>` while the removal runs.
pub async fn remove_directory_async_via(
this: &std::rc::Rc<std::cell::RefCell<Filesystem>>,
directory: &str,
@@ -189,7 +179,7 @@ impl Filesystem {
return Ok(result);
}
- let edge_case_result = fs.remove_edge_cases(directory, true)?;
+ let edge_case_result = fs.remove_edge_cases(directory)?;
if let Some(r) = edge_case_result {
return Ok(r);
}
@@ -225,11 +215,7 @@ impl Filesystem {
}
/// Returns null when no edge case was hit. Otherwise a bool whether removal was successful
- fn remove_edge_cases(
- &mut self,
- directory: &str,
- fallback_to_php: bool,
- ) -> anyhow::Result<Option<bool>> {
+ fn remove_edge_cases(&mut self, directory: &str) -> anyhow::Result<Option<bool>> {
if self.is_symlinked_directory(directory) {
return Ok(Some(self.unlink_symlinked_directory(directory)?));
}
@@ -251,10 +237,6 @@ impl Filesystem {
.into());
}
- if !function_exists("proc_open") && fallback_to_php {
- return Ok(Some(self.remove_directory_php(directory)?));
- }
-
Ok(None)
}
@@ -264,7 +246,7 @@ impl Filesystem {
/// before directories, creating a single non-recursive loop
/// to delete files/directories in the correct order.
pub fn remove_directory_php(&mut self, directory: &str) -> anyhow::Result<bool> {
- let edge_case_result = self.remove_edge_cases(directory, false)?;
+ let edge_case_result = self.remove_edge_cases(directory)?;
if let Some(r) = edge_case_result {
return Ok(r);
}
@@ -497,10 +479,6 @@ impl Filesystem {
RuntimeException::new(format!("Path contains invalid UTF-8: {}", target.display()))
})?;
- if !function_exists("proc_open") {
- return self.copy_then_remove(source, target);
- }
-
if Platform::is_windows() {
// Try to copy & delete - this is a workaround for random "Access denied" errors.
let mut output = String::new();
@@ -884,10 +862,6 @@ impl Filesystem {
/// Creates a relative symlink from $link to $target
pub fn relative_symlink(&self, target: &str, link: &str) -> bool {
- if !function_exists("symlink") {
- return false;
- }
-
let cwd = Platform::get_cwd(false).unwrap_or_default();
let relative_path = self.find_shortest_path(link, target, false, false);
diff --git a/crates/shirabe/src/util/http_downloader.rs b/crates/shirabe/src/util/http_downloader.rs
index 36ccb712..8d34dcdf 100644
--- a/crates/shirabe/src/util/http_downloader.rs
+++ b/crates/shirabe/src/util/http_downloader.rs
@@ -19,8 +19,8 @@ use indexmap::IndexMap;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpMixed, array_replace_recursive, extension_loaded,
- file_get_contents, function_exists, implode, is_numeric, php_regex, preg_is_match, preg_match,
- preg_replace, rawurldecode, stream_context_create, stripos, strpos, substr, ucfirst,
+ file_get_contents, implode, is_numeric, php_regex, preg_is_match, preg_match, preg_replace,
+ rawurldecode, stream_context_create, stripos, strpos, substr, ucfirst,
};
use shirabe_semver::constraint::SimpleConstraint;
@@ -505,8 +505,6 @@ impl HttpDownloader {
/// @internal
pub fn is_curl_enabled() -> bool {
extension_loaded("curl")
- && function_exists("curl_multi_exec")
- && function_exists("curl_multi_init")
}
/// For testing only. Builds an HttpDownloader whose request methods are fully
diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs
index ccee2953..c40f3ec5 100644
--- a/crates/shirabe/src/util/platform.rs
+++ b/crates/shirabe/src/util/platform.rs
@@ -4,8 +4,8 @@ use crate::util::ProcessExecutor;
use crate::util::Silencer;
use shirabe_php_shim::{
PHP_ENV, PHP_SERVER, PhpMixed, PhpResource, PregMatches, RuntimeException, defined,
- file_exists, file_get_contents, fstat, function_exists, getcwd, getenv, ini_get, is_readable,
- mb_strlen, php_os_family, php_regex, posix_geteuid, posix_getpwuid, posix_getuid, posix_isatty,
+ file_exists, file_get_contents, function_exists, getcwd, getenv, ini_get, is_readable,
+ mb_strlen, php_os_family, php_regex, posix_geteuid, posix_getpwuid, posix_getuid,
preg_is_match, preg_replace_callback, putenv, putenv_clear, realpath, stream_isatty, stripos,
strlen, strtoupper, substr, usleep,
};
@@ -244,9 +244,7 @@ impl Platform {
let mut use_mb_string = USE_MB_STRING.lock().unwrap();
if use_mb_string.is_none() {
*use_mb_string = Some(
- function_exists("mb_strlen")
- && ini_get("mbstring.func_overload")
- .is_some_and(|s| PhpMixed::String(s).to_bool()),
+ ini_get("mbstring.func_overload").is_some_and(|s| PhpMixed::String(s).to_bool()),
);
}
@@ -270,29 +268,7 @@ impl Platform {
return true;
}
- // modern cross-platform function, includes the fstat
- // fallback so if it is present we trust it
- if function_exists("stream_isatty") {
- return stream_isatty(fd);
- }
-
- // only trusting this if it is positive, otherwise prefer fstat fallback
- if function_exists("posix_isatty") && posix_isatty(fd.clone()) {
- return true;
- }
-
- let stat = Silencer::call(|| Ok(fstat(&fd)));
- let stat = match stat {
- Ok(s) => s,
- Err(_) => return false,
- };
- let stat = match stat {
- Some(stat) => stat,
- None => return false,
- };
-
- // Check if formatted mode is S_IFCHR
- 0o020000 == (stat.mode & 0o170000)
+ stream_isatty(fd)
}
/// Whether the current command is for bash completion
diff --git a/crates/shirabe/src/util/stream_context_factory.rs b/crates/shirabe/src/util/stream_context_factory.rs
index dea964ec..bce35832 100644
--- a/crates/shirabe/src/util/stream_context_factory.rs
+++ b/crates/shirabe/src/util/stream_context_factory.rs
@@ -9,8 +9,8 @@ use crate::util::http::ProxyManager;
use indexmap::IndexMap;
use shirabe_ca_bundle::CaBundle;
use shirabe_php_shim::{
- PhpMixed, array_replace_recursive, extension_loaded, function_exists, php_uname,
- stream_context_create, stripos, uasort,
+ PhpMixed, array_replace_recursive, extension_loaded, php_uname, stream_context_create, stripos,
+ uasort,
};
pub struct StreamContextFactory;
@@ -180,16 +180,8 @@ impl StreamContextFactory {
let user_agent = format!(
"User-Agent: Composer/{} ({os}; {release}; {php_version}; {http_version}{platform}{ci})",
composer::get_version(),
- os = if function_exists("php_uname") {
- php_uname("s")
- } else {
- "Unknown".to_string()
- },
- release = if function_exists("php_uname") {
- php_uname("r")
- } else {
- "Unknown".to_string()
- },
+ os = php_uname("s"),
+ release = php_uname("r"),
php_version = php_version,
http_version = http_version,
platform = platform_php_version