Skip to content

Update for PHP 8.0 doc #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions PHP.docset/Contents/Info.plist

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ dash-phpdoc

Generates a [Dash](http://kapeli.com/dash) docset for [PHP](http://php.net/).

Support PHP 7.x, multi-language documents (en/ja/ru/ro/es/tr/fr/de/zh/pt_BR).
Support PHP 8.x, multi-language documents (en/ja/ru/ro/es/tr/fr/de/zh/pt_BR).

This software is released under the MIT License, see LICENSE.txt.

Expand Down
110 changes: 88 additions & 22 deletions generate-php.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

// set your language (en/ja/ru/ro/es/tr/fr/de/zh/pt_BR)
$cfg_lang = 'zh';
$cfg_ver = '7.4';
$cfg_ver = '8.0';

// set your chm-extract command
// ** must be 'sprintf() format'
Expand All @@ -27,7 +27,7 @@
$cfg_chm = 'extract_chmLib %1$s %2$s';

// set true, if you have font trouble with google open sans (e.g. Zeal on windows)
$cfg_nosans = true;
$cfg_nosans = false;


//----------------------------------------
Expand All @@ -54,7 +54,7 @@
// @link http://php.net/download-docs.php
// ** chm (manual or enhanced) only!
//
$c_url_chm = "http://jp2.php.net/get/php_enhanced_{$cfg_lang}.chm/from/this/mirror";
$c_url_chm = "https://www.php.net/distributions/manual/php_enhanced_{$cfg_lang}.chm";


//----------------------------------------
Expand All @@ -63,13 +63,16 @@
//
//----------------------------------------

echo "\nStart build PHP 7.x docset ...\n";
echo "\nStart build PHP {$cfg_ver} docset ...\n";
echo "\nDownload original docset (en) and 'CHM' help file ...\n\n";

$target_chm = basename($c_url_chm);
$target_doc = basename($c_url_doc);
$clean_on_err = false;

try {
// get php manual (en) docset
exec_ex("rm -rf {$c_rbase}/");
// exec_ex("mkdir -p {$c_rbase}/");
remove_dir("{$c_rbase}");

if (
!mkdir("{$c_dbase}/", 0777, true) ||
Expand All @@ -80,6 +83,7 @@

exec_ex("wget {$c_url_doc}");
exec_ex("wget --trust-server-names {$c_url_chm}");
$match = [];

if (preg_match('#.+/get/(php_(manual|enhanced)_(en|ja|ru|ro|es|tr|fr|de|zh|pt_BR)\.chm)/from/.+#i', $c_url_chm, $match)) {
$target_chm = $match[1];
Expand All @@ -89,7 +93,6 @@
$target_chm = basename($c_url_chm);
echo "\nDetect CHM failure, fallback to '{$target_chm}'. set as target ...\n";
}
$target_doc = basename($c_url_doc);

echo "\nReplace docset files for your language ...\n\n";

Expand Down Expand Up @@ -117,10 +120,13 @@
}

echo "Removing original manual/en ...\n";
exec_ex("rm -rf {$c_origd}/Contents/Resources/Documents/www.php.net/manual/en");
remove_dir($base_dir);
exec_ex(sprintf($cfg_chm, $target_chm, $c_mychm));
sleep(1);
exec_ex("rm -f {$c_mychm}/res/style.css");

if (!unlink("{$c_mychm}/res/style.css")) {
do_exception(__LINE__);
}

// copy database
if (
Expand All @@ -131,9 +137,15 @@
}

// copy & replace documents
exec_ex("mkdir -p {$c_dbase}/www.php.net/manual");
exec_ex("mv {$c_origd}/Contents/Resources/Documents/www.php.net {$c_dbase}/php.net");
exec_ex("mv {$c_mychm}/res {$c_dbase}/www.php.net/manual/en");
if (!rename("{$c_origd}/Contents/Resources/Documents/php.net", "{$c_dbase}/php.net")) {
do_exception(__LINE__);
}
if (!rename("{$c_origd}/Contents/Resources/Documents/www.php.net", "{$c_dbase}/www.php.net")) {
do_exception(__LINE__);
}
if (!rename("{$c_mychm}/res", "{$c_dbase}/www.php.net/manual/en")) {
do_exception(__LINE__);
}

if (!copy(
__DIR__ . sprintf('/%s', $cfg_nosans ? 'style-nosans.css' : 'style.css'),
Expand All @@ -143,14 +155,24 @@
}
}
catch (Exception $e) {
$clean_on_err = true;
throw new Exception("\nPHP docset build failed.\nFix error and try again.\n\n", -1, $e);
}
finally {
// clean up
exec("rm -rf " . __DIR__ . "/{$target_doc}");
exec("rm -rf " . __DIR__ . "/{$target_chm}");
exec("rm -rf {$c_origd}");
exec("rm -rf {$c_mychm}");
if ($clean_on_err) {
@unlink(__DIR__ . "/{$target_doc}");
@unlink(__DIR__ . "/{$target_chm}");

try { remove_dir("{$c_origd}"); } catch (Exception $e) { }
try { remove_dir("{$c_mychm}"); } catch (Exception $e) { }
} else {
unlink(__DIR__ . "/{$target_doc}");
unlink(__DIR__ . "/{$target_chm}");

remove_dir("{$c_origd}");
remove_dir("{$c_mychm}");
}
}

// gen Info.plist
Expand All @@ -166,7 +188,7 @@
<key>DocSetPlatformFamily</key>
<string>php</string>
<key>dashIndexFilePath</key>
<string>php.net/manual/en/index.html</string>
<string>www.php.net/manual/en/index.html</string>
<key>DashDocSetFamily</key>
<string>dashtoc</string>
<key>isDashDocset</key>
Expand Down Expand Up @@ -218,7 +240,7 @@
continue;
}

$list[] = [$t->nodeValue, $c_guide, $row['path'], 'ja'];
$list[] = [$t->nodeValue, $c_guide, $row['path'], $cfg_lang];
}

$stmt = $db->prepare('INSERT OR IGNORE INTO searchIndex(name, type, path, lang) VALUES (?, ?, ?, ?)');
Expand All @@ -227,33 +249,77 @@
$stmt->execute($val);
}

echo "\nPHP 7.x docset updated !\n\n";
echo "\nPHP {$cfg_ver} docset updated !\n\n";


//----------------------------------------
// Helper functions
//----------------------------------------

// Throw Exception
/**
* Throw Exception
*
* @param mixed $line
* @param integer $code
* @throws Exception
*/
function do_exception($line, $code = -1) {
throw new Exception("Error at line: {$line}", $code);
}

// Exec with exception logic
/**
* Exec with exception logic
*
* @param string $cmd
* @return boolean
*/
function exec_ex($cmd) {
if (($cmd = strval($cmd)) === '') {
do_exception(__LINE__);
}

$out = null;
$out = [];
$ret = 0;

echo "Exec: {$cmd}\n";
exec($cmd, $out, $ret);

$log = implode("\n", $out);
echo "Exec status: {$ret}\nExec output: {$log}\n\n";

if ($ret) {
do_exception(__LINE__, $ret);
}

return true;
}

/**
* Remove directory recursively
*
* @param string $dir
*/
function remove_dir($dir) {
if ($dir === "" || !is_dir($dir)) {
return;
}

$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS),
RecursiveIteratorIterator::CHILD_FIRST
);

foreach ($iterator as $item) {
if ($item->isDir()) {
rmdir($item->getPathname());
} else {
unlink($item->getPathname());
}
}

if (!rmdir($dir)) {
do_exception(__LINE__);
}
}