Commit: d6f3166ac652830cd8a3e1a95f173bb6fcfc06b4 Author: Anatol Belski <a...@php.net> Sun, 13 Jan 2019 19:42:43 +0100 Parents: 821797c70745d4e8e2a91473ec71431871a9b950 Branches: master
Link: http://git.php.net/?p=web/windows.git;a=commitdiff;h=d6f3166ac652830cd8a3e1a95f173bb6fcfc06b4 Log: Implement web.config generation Changed paths: M include/listing.php Diff: diff --git a/include/listing.php b/include/listing.php index 51a57b8..fa9d902 100644 --- a/include/listing.php +++ b/include/listing.php @@ -204,9 +204,72 @@ function generate_listing($path, $snaps = false) { file_put_contents($tmp_name, $cache_content); rename($tmp_name, 'cache.info'); chdir($old_cwd); + + generate_web_config($releases); + return $releases; } +function transform_fname_to_latest($fname_real, $ver, $cur_ver) +{ + $ret = implode($ver, explode($cur_ver, $fname_real)); + $ret = str_replace(".zip", "-latest.zip", $ret); + + return $ret; +} + +function get_redirection_conf_piece($tpl, $fname_real, $ver, $cur_ver) +{ + $search = array("REAL_FILENAME", "FAKE_FILENAME"); + $fname_fake = transform_fname_to_latest($fname_real, $ver, $cur_ver); + $ret = str_replace($search, array($fname_real, $fname_fake), $tpl); + + return $ret . "\n\t\t"; +} + +function generate_web_config(array $releases = array()) +{ + $config_tpl = file_get_contents(TPL_PATH . "/web.config.tpl"); + $redirect_tpl = trim(file_get_contents(TPL_PATH . "/web.config.redirect.tpl")); + + /* Handle releases. */ + if (empty($releases)) { + $cache = DOCROOT . "/downloads/releases/cache.info"; + if (!file_exists($cache)) { + return false; + } + include $cache; + } + + $tmp = ""; + foreach ($releases as $version => $release) { + + $cur_ver = $release["version"]; + unset($release["version"]); + + $tmp .= "\t\t\t<!-- redirect to latest downloads php-$version -->\n\t\t"; + + $tmp .= get_redirection_conf_piece($redirect_tpl, $release["source"]["path"], $version, $cur_ver); + unset($release["source"]); + + foreach ($release as $flavour) { + $tmp .= get_redirection_conf_piece($redirect_tpl, $flavour["zip"]["path"], $version, $cur_ver); + $tmp .= get_redirection_conf_piece($redirect_tpl, $flavour["debug_pack"]["path"], $version, $cur_ver); + } + } + + $config_content = str_replace("RELEASES_REDIRECT_TO_LATEST_PLACEHOLDER", $tmp, $config_tpl); + + + /* Save generated web.config. */ + $config_path = DOCROOT . "/web.config"; + if (!file_put_contents($config_path, $config_content, LOCK_EX)) { + return false; + } + + return true; +} + /* * Local variables: * tab-width: 4 -- PHP Webmaster List Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php