Skip to content

Commit e584dc8

Browse files
committed
Add script to index pgaes, for faster lookup by php.net
1 parent 7fa8bd8 commit e584dc8

File tree

6 files changed

+63
-0
lines changed

6 files changed

+63
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var/
2+
!var/.gitkeep
3+
4+
vendor/

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ The legacy documentation is maintained by Zend and the community.
88

99
Ideally, we'd love to see everyone running the latest version of PHP! But to achieve this, someone has to read the old documentation to ensure the application's compatibility with the new PHP version.
1010

11+
## Indexing
12+
13+
This project comes with a script to create an index of which manual page exists for which PHP version. The resulting file will be supplied to php.net in order to speed up lookup.
14+
15+
- Generate the autoload file: `composer install`
16+
- Execute using `php bin/indexpages.php`
17+
1118
## FAQ
1219

1320
__Q: Where are the translations?__

bin/indexpages.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
require 'vendor/autoload.php';
5+
6+
use App\Command\IndexPages;
7+
8+
(new IndexPages())->execute();

composer.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"autoload": {
3+
"psr-4": {
4+
"App\\": "src/"
5+
}
6+
}
7+
}

src/Command/IndexPages.php

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace App\Command;
5+
6+
class IndexPages
7+
{
8+
public function execute()
9+
{
10+
$legacyUrlsIndex = [];
11+
foreach ([4, 5] as $versionNumber) {
12+
$filenames = $this->getHtmlFilenames($versionNumber);
13+
14+
foreach ($filenames as $filename) {
15+
$uri = $this->filenameToUri($filename);
16+
$legacyUrlsIndex[$uri][] = $versionNumber;
17+
}
18+
}
19+
20+
file_put_contents('var/legacyurls.json', json_encode($legacyUrlsIndex));
21+
}
22+
23+
/**
24+
* @return string[]
25+
*/
26+
private function getHtmlFilenames(int $versionNumber): array
27+
{
28+
return glob('php' . $versionNumber . '/**/*.html');
29+
}
30+
31+
private function filenameToUri(string $filename): string
32+
{
33+
return preg_replace_callback('/^php.*\/.*\/(.*)\.html$/', function (array $matches) {
34+
return $matches[1];
35+
}, $filename);
36+
}
37+
}

var/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)