&1'); if (false !== strpos($out, 'All good. Saving')) { echo_line('Yes.'); } else { // Hmm.... this should never happen ;) echo_line('No.'); } // PhD installation if (!$configs['PATH_PHD']) { echo_line('Running: Attempting to install PhD.'); if ($configs['PATH_PEAR']) { $command = $configs['PATH_PEAR'] . ' install doc.php.net/PhD doc.php.net/PhD_PHP'; $out = shell_exec($command); if (!$configs['PATH_PHD'] = get_installed_path('phd', $configs['PATH_PHD'], '-V')) { echo_line('Warning: Attempted and failed to install PhD. Here was the output:'); print_r($out); } else { echo_line('Status: PhD is now installed.'); } } else { // Then use PhD from SVN instead? echo_line('Warning: I decided to not install PhD, without PEAR.'); } } echo_line(); echo_line('INFO: Done. You now have the PHP Documentation checked out:'); echo_line('-- PHP Documentation SVN path: '. $configs['DIR_SVN']); echo_line('-- PhD Installed: '. (empty($configs['PATH_PHD']) ? 'no' : $configs['PATH_PHD'])); echo_line(); echo_line('INFO: Now, some things you might want to do:'); echo_line('-- Go there : cd ' . $configs['DIR_SVN']); echo_line('-- Validate XML : php doc-base/configure.php'); echo_line('-- Render XHTML : phd --docbook doc-base/.manual.xml --package PHP --format xhtml'); echo_line('-- View it : open output/php-chunked-xhtml/index.html &'); echo_line('-- Edit docs : vim en/reference/strings/functions/strlen.xml'); echo_line('-- See diff : svn diff -u en/reference/strings/functions/strlen.xml'); echo_line('-- Is Validate? : php doc-base/configure.php'); echo_line('-- Commit :) : svn commit en/reference/strings/functions/strlen.xml'); /******* Function library ****************************************************/ function get_installed_path($program, $test_path = NULL, $version = '--version') { // Test $test_path, if provided by user if (!empty($test_path)) { $command = "$test_path $version 2>&1"; $out = shell_exec($command); if (false !== strpos($out, 'command not found')) { return $test_path; } else { // Yes, bad to echo here, but oh well echo_line("Warning: The desired program ($program) was not found at path ($test_path). Will try finding it myself."); } } // Now try finding it ourselves... // FIXME: will this always work? $command = "which $program 2>&1"; $out = shell_exec($command); if (false !== strpos($out, '/' . $program)) { return trim($out); } return false; } function usage() { $descriptions = array( 'h' => 'Help : This help', 't' => 'TEST Mode: Test mode. Writes nothing. Displays your configs', 'l' => 'Language : Country code, typically two letters. Default: en', 'b' => 'SVN dir : Full path to the SVN base dir, where PHP will be checked out', 's' => 'SVN path: Full path to the SVN binary', 'd' => 'PhD path: PhD renders the manual, you probably do not have it installed', 'r' => 'PEAR path: Full path to the pear command', 'p' => 'PHP path: Full path to the PHP binary', 'u' => 'SVN Up : Update the existing SVN checkout', ); echo_line(); echo_line('This script checks out PHP from SVN, and installs PhD.'); echo_line('The following options are available. All but -b are optional.'); echo_line(); echo_line('Example: php ' . $_SERVER['SCRIPT_NAME'] . ' -b /my/svn -l en'); echo_line('Creates: /my/svn/doc-en/ with full php documentation checkout'); echo_line(); foreach ($descriptions as $config_n => $config_v) { echo_line(' -' . $config_n . ' : ' . $config_v); } exit; } // Questionable function do_getopts() { // Intentionally 'require' everything, as 'optional' is broken. $options = getopt('b:l:p:r:d:s:uht'); $defaults = $configs = array( 'h' => '', // Show usage/help information 'b' => '', // Base directory for the SVN Checkout 'l' => 'en', // Language (en, or lang code for translation) 'p' => '', // PHP binary Path 'r' => '', // PEAR binary Path 'd' => '', // PHD binary Path 's' => '', // SVN binary Path 'u' => '', // Update the checkout, instead of checkout 't' => '', // Test. Outputs your configuration. ); foreach ($options as $option_k => $option_v) { // This means it was set. But, I don't like false being the value. if (in_array($option_k, array('h','u','t')) && $option_v === false) { $option_v = true; } if (!empty($option_v)) { $configs[$option_k] = $option_v; } } $configs = array( 'BASEDIR_SVN' => $configs['b'], 'LANG_CODE' => $configs['l'], 'PATH_PHP' => $configs['p'], 'PATH_PEAR' => $configs['r'], 'PATH_PHD' => $configs['d'], 'PATH_SVN' => $configs['s'], 'UPDATE_CO' => $configs['u'], 'HELP' => $configs['h'], 'TEST' => $configs['t'], ); if (!empty($configs['BASEDIR_SVN'])) { $configs['DIR_SVN'] = $configs['BASEDIR_SVN'] . '/doc-' . $configs['LANG_CODE']; } return $configs; } function is_phpdoc_checkout($configs) { if (empty($configs['DIR_SVN'])) { echo_line('Warning: Configuration is not set properly while testing the checkout. Massive fail!'); exit; } // TODO: Improve this check if (file_exists($configs['DIR_SVN'] . '/en/reference/apc/book.xml') && file_exists($configs['DIR_SVN'] . '/doc-base/configure.php')) { return true; } else { return false; } } function echo_line($line = '', $newline = TRUE) { echo $line; if ($newline) { echo PHP_EOL; } }