aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/autoload
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-06 05:43:24 +0900
committernsfisis <nsfisis@gmail.com>2026-08-06 05:43:24 +0900
commita86bbd67954f7bbc38bb09138edb335d82666526 (patch)
tree461a893737b54b9e13972d5477764c39491386f5 /crates/shirabe/src/autoload
parent0b9c129df5b3c6fd31eada1ed13de10cb5b35721 (diff)
downloadphp-shirabe-a86bbd67954f7bbc38bb09138edb335d82666526.tar.gz
php-shirabe-a86bbd67954f7bbc38bb09138edb335d82666526.tar.zst
php-shirabe-a86bbd67954f7bbc38bb09138edb335d82666526.zip
style(autoload): use raw strings for the PHP heredoc templates
The generated-file templates are heredocs in Composer's AutoloadGenerator. Writing them as raw string literals keeps the emitted PHP laid out the way it is written out, matching the blocks in getAutoloadRealFile and getStaticFile that already use them. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/autoload')
-rw-r--r--crates/shirabe/src/autoload/autoload_generator.rs141
1 files changed, 130 insertions, 11 deletions
diff --git a/crates/shirabe/src/autoload/autoload_generator.rs b/crates/shirabe/src/autoload/autoload_generator.rs
index 93dbca09..06225c08 100644
--- a/crates/shirabe/src/autoload/autoload_generator.rs
+++ b/crates/shirabe/src/autoload/autoload_generator.rs
@@ -217,12 +217,28 @@ impl AutoloadGenerator {
let app_base_dir_code = str_replace("__DIR__", "$vendorDir", &app_base_dir_code);
let mut namespaces_file = format!(
- "<?php\n\n// autoload_namespaces.php @generated by Composer\n\n$vendorDir = {};\n$baseDir = {};\n\nreturn array(\n",
+ r#"<?php
+
+// autoload_namespaces.php @generated by Composer
+
+$vendorDir = {};
+$baseDir = {};
+
+return array(
+"#,
vendor_path_code, app_base_dir_code
);
let mut psr4_file = format!(
- "<?php\n\n// autoload_psr4.php @generated by Composer\n\n$vendorDir = {};\n$baseDir = {};\n\nreturn array(\n",
+ r#"<?php
+
+// autoload_psr4.php @generated by Composer
+
+$vendorDir = {};
+$baseDir = {};
+
+return array(
+"#,
vendor_path_code, app_base_dir_code
);
@@ -333,7 +349,25 @@ impl AutoloadGenerator {
filesystem.find_shortest_path_code(&target_dir, &base_path, true, false, false);
target_dir_loader = Some(format!(
- "\n public static function autoload($class)\n {{\n $dir = {} . '/';\n $prefixes = array({});\n foreach ($prefixes as $prefix) {{\n if (0 !== strpos($class, $prefix)) {{\n continue;\n }}\n $path = $dir . implode('/', array_slice(explode('\\\\', $class), {})).'.php';\n if (!$path = stream_resolve_include_path($path)) {{\n return false;\n }}\n require $path;\n\n return true;\n }}\n }}\n",
+ r#"
+ public static function autoload($class)
+ {{
+ $dir = {} . '/';
+ $prefixes = array({});
+ foreach ($prefixes as $prefix) {{
+ if (0 !== strpos($class, $prefix)) {{
+ continue;
+ }}
+ $path = $dir . implode('/', array_slice(explode('\\', $class), {})).'.php';
+ if (!$path = stream_resolve_include_path($path)) {{
+ return false;
+ }}
+ require $path;
+
+ return true;
+ }}
+ }}
+"#,
base_dir_from_target_dir_code, prefixes, levels
));
}
@@ -481,7 +515,15 @@ impl AutoloadGenerator {
class_map.sort();
let mut classmap_file = format!(
- "<?php\n\n// autoload_classmap.php @generated by Composer\n\n$vendorDir = {};\n$baseDir = {};\n\nreturn array(\n",
+ r#"<?php
+
+// autoload_classmap.php @generated by Composer
+
+$vendorDir = {};
+$baseDir = {};
+
+return array(
+"#,
vendor_path_code, app_base_dir_code
);
for (class_name, path) in class_map.get_map() {
@@ -978,7 +1020,16 @@ impl AutoloadGenerator {
}
Some(format!(
- "<?php\n\n// include_paths.php @generated by Composer\n\n$vendorDir = {};\n$baseDir = {};\n\nreturn array(\n{});\n",
+ r#"<?php
+
+// include_paths.php @generated by Composer
+
+$vendorDir = {};
+$baseDir = {};
+
+return array(
+{});
+"#,
vendor_path_code, app_base_dir_code, include_paths_code
))
}
@@ -1039,7 +1090,16 @@ impl AutoloadGenerator {
let _ = &mut files;
Some(format!(
- "<?php\n\n// autoload_files.php @generated by Composer\n\n$vendorDir = {};\n$baseDir = {};\n\nreturn array(\n{});\n",
+ r#"<?php
+
+// autoload_files.php @generated by Composer
+
+$vendorDir = {};
+$baseDir = {};
+
+return array(
+{});
+"#,
vendor_path_code, app_base_dir_code, files_code
))
}
@@ -1253,13 +1313,23 @@ impl AutoloadGenerator {
if !required_php.is_empty() {
required_php = format!(
- "\nif (!({})) {{\n $issues[] = 'Your Composer dependencies require a PHP version {}. You are running ' . PHP_VERSION . '.';\n}}\n",
+ r#"
+if (!({})) {{
+ $issues[] = 'Your Composer dependencies require a PHP version {}. You are running ' . PHP_VERSION . '.';
+}}
+"#,
required_php, required_php_error
);
}
if required_php_64bit {
- required_php.push_str("\nif (PHP_INT_SIZE !== 8) {\n $issues[] = 'Your Composer dependencies require a 64-bit build of PHP.';\n}\n");
+ required_php.push_str(
+ r#"
+if (PHP_INT_SIZE !== 8) {
+ $issues[] = 'Your Composer dependencies require a 64-bit build of PHP.';
+}
+"#,
+ );
}
let required_extensions_str = implode(
@@ -1268,7 +1338,13 @@ impl AutoloadGenerator {
);
let required_extensions_block = if !required_extensions_str.is_empty() {
format!(
- "\n$missingExtensions = array();\n{}\nif ($missingExtensions) {{\n $issues[] = 'Your Composer dependencies require the following PHP extensions to be installed: ' . implode(', ', $missingExtensions) . '.';\n}}\n",
+ r#"
+$missingExtensions = array();
+{}
+if ($missingExtensions) {{
+ $issues[] = 'Your Composer dependencies require the following PHP extensions to be installed: ' . implode(', ', $missingExtensions) . '.';
+}}
+"#,
required_extensions_str
)
} else {
@@ -1280,7 +1356,28 @@ impl AutoloadGenerator {
}
Some(format!(
- "<?php\n\n// platform_check.php @generated by Composer\n\n$issues = array();\n{}{}\nif ($issues) {{\n if (!headers_sent()) {{\n header('HTTP/1.1 500 Internal Server Error');\n }}\n if (!ini_get('display_errors')) {{\n if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {{\n fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL);\n }} elseif (!headers_sent()) {{\n echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;\n }}\n }}\n throw new \\RuntimeException(\n 'Composer detected issues in your platform: ' . implode(' ', $issues)\n );\n}}\n",
+ r#"<?php
+
+// platform_check.php @generated by Composer
+
+$issues = array();
+{}{}
+if ($issues) {{
+ if (!headers_sent()) {{
+ header('HTTP/1.1 500 Internal Server Error');
+ }}
+ if (!ini_get('display_errors')) {{
+ if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {{
+ fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL);
+ }} elseif (!headers_sent()) {{
+ echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;
+ }}
+ }}
+ throw new \RuntimeException(
+ 'Composer detected issues in your platform: ' . implode(' ', $issues)
+ );
+}}
+"#,
required_php, required_extensions_block
))
}
@@ -1305,7 +1402,29 @@ impl AutoloadGenerator {
};
format!(
- "<?php\n\n// autoload.php @generated by Composer\n\nif (PHP_VERSION_ID < 50600) {{\n if (!headers_sent()) {{\n header('HTTP/1.1 500 Internal Server Error');\n }}\n $err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via \"composer self-update --2.2\". Aborting.'.PHP_EOL;\n if (!ini_get('display_errors')) {{\n if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {{\n fwrite(STDERR, $err);\n }} elseif (!headers_sent()) {{\n echo $err;\n }}\n }}\n throw new RuntimeException($err);\n}}\n\nrequire_once {};\n\nreturn ComposerAutoloaderInit{}::getLoader();\n",
+ r#"<?php
+
+// autoload.php @generated by Composer
+
+if (PHP_VERSION_ID < 50600) {{
+ if (!headers_sent()) {{
+ header('HTTP/1.1 500 Internal Server Error');
+ }}
+ $err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
+ if (!ini_get('display_errors')) {{
+ if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {{
+ fwrite(STDERR, $err);
+ }} elseif (!headers_sent()) {{
+ echo $err;
+ }}
+ }}
+ throw new RuntimeException($err);
+}}
+
+require_once {};
+
+return ComposerAutoloaderInit{}::getLoader();
+"#,
vendor_path_to_target_dir_code, suffix
)
}