aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/downloader
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-16 10:00:50 +0900
committernsfisis <nsfisis@gmail.com>2026-08-16 10:00:50 +0900
commit112df62a01e482f33b68e1dac190f70085fcec64 (patch)
tree19d126032309193cfd5f5d0fb63b6562ef17e5c9 /crates/shirabe/src/downloader
parent3fb08fab7ca69a028a9a89544b246ca70534cbce (diff)
downloadphp-shirabe-112df62a01e482f33b68e1dac190f70085fcec64.tar.gz
php-shirabe-112df62a01e482f33b68e1dac190f70085fcec64.tar.zst
php-shirabe-112df62a01e482f33b68e1dac190f70085fcec64.zip
refactor(php-shim): give parse_url a typed UrlComponents result
parse_url now returns Option<UrlComponents> instead of a PhpMixed array, and the component-selecting overload with the PHP_URL_* constants is gone: callers read the field they want. Two call sites change behaviour as a result, both towards PHP: * CurlDownloader::handle_redirect tested scheme and host with is_null(), so an unparsable Location header (PhpMixed::Bool(false)) counted as an absolute URL. PHP's truthiness test sends it to the relative-path branch. * Url::get_origin appended a literal port 0, which PHP treats as falsy and leaves off. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/downloader')
-rw-r--r--crates/shirabe/src/downloader/file_downloader.rs21
-rw-r--r--crates/shirabe/src/downloader/gzip_downloader.rs17
2 files changed, 20 insertions, 18 deletions
diff --git a/crates/shirabe/src/downloader/file_downloader.rs b/crates/shirabe/src/downloader/file_downloader.rs
index 64b348e1..027205a0 100644
--- a/crates/shirabe/src/downloader/file_downloader.rs
+++ b/crates/shirabe/src/downloader/file_downloader.rs
@@ -27,10 +27,10 @@ use crate::util::sync_executor;
use indexmap::IndexMap;
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
- InvalidArgumentException, PATHINFO_BASENAME, PATHINFO_EXTENSION, PHP_URL_PATH, PhpMixed,
- RuntimeException, UnexpectedValueException, array_search, file_exists, filesize, get_class,
- hash, hash_file, impl_php_class, is_dir, is_executable, parse_url, pathinfo, realpath, rtrim,
- spl_object_hash, strlen, strpos, strtr, trim, umask, usleep,
+ InvalidArgumentException, PATHINFO_BASENAME, PATHINFO_EXTENSION, PhpMixed, RuntimeException,
+ UnexpectedValueException, array_search, file_exists, filesize, get_class, hash, hash_file,
+ impl_php_class, is_dir, is_executable, parse_url, pathinfo, realpath, rtrim, spl_object_hash,
+ strlen, strpos, strtr, trim, umask, usleep,
};
use std::sync::{LazyLock, Mutex};
@@ -259,12 +259,13 @@ impl FileDownloader {
fn get_dist_path(&self, package: PackageInterfaceHandle, component: i64) -> String {
pathinfo(
- parse_url(
- &strtr(&package.get_dist_url().unwrap_or_default(), "\\", "/"),
- PHP_URL_PATH,
- )
- .as_string()
- .unwrap_or(""),
+ &parse_url(&strtr(
+ &package.get_dist_url().unwrap_or_default(),
+ "\\",
+ "/",
+ ))
+ .and_then(|url| url.path)
+ .unwrap_or_default(),
component,
)
}
diff --git a/crates/shirabe/src/downloader/gzip_downloader.rs b/crates/shirabe/src/downloader/gzip_downloader.rs
index 962c5bb8..ff229d38 100644
--- a/crates/shirabe/src/downloader/gzip_downloader.rs
+++ b/crates/shirabe/src/downloader/gzip_downloader.rs
@@ -14,8 +14,8 @@ use crate::util::Platform;
use crate::util::ProcessExecutor;
use indexmap::IndexMap;
use shirabe_php_shim::{
- PATHINFO_FILENAME, PHP_URL_PATH, PhpMixed, RuntimeException, extension_loaded, fclose, fopen,
- fwrite, gzclose, gzopen, gzread, impl_php_class, implode, parse_url, pathinfo, strtr,
+ PATHINFO_FILENAME, PhpMixed, RuntimeException, extension_loaded, fclose, fopen, fwrite,
+ gzclose, gzopen, gzread, impl_php_class, implode, parse_url, pathinfo, strtr,
};
#[derive(Debug)]
@@ -82,12 +82,13 @@ impl ArchiveDownloader for GzipDownloader {
path: &str,
) -> anyhow::Result<Option<PhpMixed>> {
let filename = pathinfo(
- parse_url(
- &strtr(&package.get_dist_url().unwrap_or_default(), "\\", "/"),
- PHP_URL_PATH,
- )
- .as_string()
- .unwrap_or(""),
+ &parse_url(&strtr(
+ &package.get_dist_url().unwrap_or_default(),
+ "\\",
+ "/",
+ ))
+ .and_then(|url| url.path)
+ .unwrap_or_default(),
PATHINFO_FILENAME,
);
let target_filepath = std::path::Path::new(path)