Repository navigation
Expand file tree
/
Copy pathdoctum-config.php
More file actions
123 lines (100 loc) · 3.74 KB
/
Copy pathdoctum-config.php
File metadata and controls
123 lines (100 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
use Doctum\Doctum;
use Doctum\RemoteRepository\GitHubRemoteRepository;
use Doctum\Version\GitVersionCollection;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator;
use Symfony\Component\Finder\RecursiveFinder;
require_once __DIR__ . '/src/FrameworkVersionResolver.php';
$flarum = getenv('FLARUM_CORE_PATH');
$iterator = Finder::create()
->files()
->name('*.php')
->in("$flarum/src");
// Get all tags and find latest minor of each major version
$tags = explode("\n", trim(shell_exec("git -C $flarum tag")));
$latestMinors = [];
foreach ($tags as $tag) {
if (preg_match('/^v?([0-9]+)\.([0-9]+)\.[0-9]+$/', $tag, $matches)) {
$major = $matches[1];
$minor = $matches[2];
$key = "$major.$minor";
// Store or update if this tag is newer
if (!isset($latestMinors[$key]) || version_compare($tag, $latestMinors[$key], '>')) {
$latestMinors[$key] = $tag;
}
}
}
unset($latestMinors['1.0']);
unset($latestMinors['1.1']);
unset($latestMinors['1.2']);
// Read composer.json for each tagged version to get Laravel/Symfony versions
// Use git show to get composer.json at each specific tag (different Flarum versions have different deps)
$libraryVersions = [];
$versionRe = '/\\^(\\d+)\\.\\d+/m';
$versionSubst = '$1.x';
$allRefs = [
...$latestMinors,
'1.x' => '1.x',
'2.x' => '2.x',
];
foreach ($allRefs as $minorKey => $tag) {
// $tag = $latestMinors[$minorKey];
$versions = [];
// Use git show to get composer.json at this specific tag
$composerOutput = @shell_exec("git -C \"$flarum\" show $tag:composer.json");
if ($composerOutput && strlen(trim($composerOutput)) > 0) {
$composerJson = json_decode($composerOutput, true);
if ($composerJson && isset($composerJson['require'])) {
// Get Laravel version (check for illuminate packages)
$hasIlluminate = false;
foreach (array_keys($composerJson['require']) as $pkg) {
if (str_starts_with($pkg, 'illuminate/')) {
$illuminateVersion = $composerJson['require'][$pkg];
$versions['laravel'] = preg_replace($versionRe, $versionSubst, $illuminateVersion);
break;
}
}
// Get Symfony version
if (isset($composerJson['require']['symfony/config'])) {
// Extract version constraint (e.g., ^5.2.2 -> 5.4)
$symfonyConstraint = $composerJson['require']['symfony/config'];
if (preg_match('/^[\^~]?(\d+)\.(\d+)/', $symfonyConstraint, $m)) {
$versions['symfony'] = $m[1] . '.' . $m[2];
}
}
}
}
$libraryVersions[$minorKey] = $versions;
}
$versions = GitVersionCollection::create($flarum)
->add('1.x', '1.x')
->add('2.x', '2.x');
foreach ($latestMinors as $key => $tag) {
$versions->add($tag, $tag);
}
// Allow resolving dependency versions for API documentation links
$frameworkVersions = new FrameworkVersionResolver($flarum);
$frameworkVersions->preload([
...$latestMinors,
'1.x' => '1.x',
'2.x' => '2.x',
]);
$GLOBALS['frameworkVersions'] = $frameworkVersions;
function package_version(string $combined): ?string
{
[$ref, $library] = explode(':', $combined, 2);
return $GLOBALS['frameworkVersions']->get($ref, $library);
}
return new Doctum($iterator, array(
'theme' => 'flarum',
'versions' => $versions,
'title' => 'Flarum API',
'build_dir' => __DIR__ . '/docs/php/%version%/',
'cache_dir' => __DIR__ . '/cache/php/%version%/',
'template_dirs' => array(__DIR__ . '/themes/flarum'),
'remote_repository' => new GitHubRemoteRepository('flarum/framework', $flarum),
'default_opened_level' => 1,
'source_url' => 'https://github.com/flarum/framework/',
'source_dir' => 'src',
));