Skip to content

Commit 661cf16

Browse files
authored
Merge pull request #5689 from sfadschm/docs-example-code
[Docs] Extract example php code for static analysis.
2 parents f205895 + b135145 commit 661cf16

File tree

1,572 files changed

+14548
-9526
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,572 files changed

+14548
-9526
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
__DIR__ . '/.no-header.php-cs-fixer.dist.php',
3333
__DIR__ . '/rector.php',
3434
__DIR__ . '/spark',
35+
__DIR__ . '/user_guide_src/renumerate.php',
3536
]);
3637

3738
$overrides = [];

user_guide_src/renumerate.php

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
/**
4+
* This file is part of CodeIgniter 4 framework.
5+
*
6+
* (c) CodeIgniter Foundation <admin@codeigniter.com>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
$srcFolder = __DIR__ . '/source';
13+
14+
// Exclude static folders
15+
$excludes = ['_static', 'images'];
16+
17+
// Safety prefix
18+
$prefix = 'old_';
19+
20+
// Begin user info
21+
echo 'The following sections were renumerated:', PHP_EOL;
22+
23+
// Loop source directory
24+
$srcIterator = new DirectoryIterator($srcFolder);
25+
26+
foreach ($srcIterator as $chapterInfo) {
27+
if (! $chapterInfo->isDot() && $chapterInfo->isDir() && ! in_array($chapterInfo->getFilename(), $excludes, true)) {
28+
$chapterName = $chapterInfo->getFilename();
29+
30+
// Iterate the working directory
31+
$chapterIterator = new DirectoryIterator($chapterInfo->getPathname());
32+
33+
foreach ($chapterIterator as $sectionInfo) {
34+
if (! $sectionInfo->isDot() && $sectionInfo->isFile() && $sectionInfo->getExtension() === 'rst') {
35+
$sectionName = $sectionInfo->getBasename('.rst');
36+
$sectionFolder = $sectionInfo->getPath() . '/' . $sectionName;
37+
38+
// Read the section file
39+
$sectionContent = file_get_contents($sectionInfo->getPathname());
40+
41+
// Match all includes
42+
preg_match_all("~\\.\\. literalinclude:: {$sectionName}\\/(.+)\\.php(\n[ ]*:lines: 2\\-)?~", $sectionContent, $matches);
43+
$includeStrings = $matches[0];
44+
$exampleNames = $matches[1];
45+
46+
// Exit early if no matches
47+
if (count($exampleNames) === 0) {
48+
continue;
49+
}
50+
51+
// Check if examples are consecutive
52+
$consecutive = true;
53+
54+
foreach ($exampleNames as $exampleIndex => $exampleName) {
55+
if (str_pad($exampleIndex + 1, 3, '0', STR_PAD_LEFT) !== $exampleName) {
56+
$consecutive = false;
57+
break;
58+
}
59+
}
60+
61+
// Exit if examples are already consecutive
62+
if ($consecutive) {
63+
continue;
64+
}
65+
66+
// Rename all example files to avoid conflicts
67+
$exampleIterator = new DirectoryIterator($sectionFolder);
68+
69+
foreach ($exampleIterator as $exampleInfo) {
70+
if (! $exampleInfo->isDot() && $exampleInfo->isFile() && $exampleInfo->getExtension() === 'php') {
71+
rename($exampleInfo->getPathname(), $exampleInfo->getPath() . '/' . $prefix . $exampleInfo->getFilename());
72+
}
73+
}
74+
$sectionContent = preg_replace("~\\.\\. literalinclude:: {$sectionName}\\/(.+)\\.php~", ".. literalinclude:: {$sectionName}/{$prefix}$1.php", $sectionContent);
75+
76+
// Renumerate examples
77+
foreach ($exampleNames as $exampleIndex => $exampleName) {
78+
$newName = str_pad($exampleIndex + 1, 3, '0', STR_PAD_LEFT);
79+
80+
// Rename example file
81+
rename($sectionFolder . '/' . $prefix . $exampleName . '.php', $sectionFolder . '/' . $newName . '.php');
82+
83+
// Fix include link
84+
$sectionContent = preg_replace(preg_quote(str_replace($exampleName, $prefix . $exampleName, $includeStrings[$exampleIndex]), '~'), str_replace($exampleName, $newName, $includeStrings[$exampleIndex]), $sectionContent, 1, $count);
85+
}
86+
87+
// Write new content to rst
88+
file_put_contents($sectionInfo->getPathname(), $sectionContent);
89+
90+
// User info
91+
echo $chapterName, '/', $sectionName, PHP_EOL;
92+
}
93+
}
94+
}
95+
}
96+
97+
// End user info
98+
echo 'Renumerating finished.', PHP_EOL;

user_guide_src/source/changelogs/v4.0.0-alpha.2.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ tests /
107107
- ParserTest #1311
108108
- EntityTest #1319
109109

110-
111110
user_guide_src /source/
112111
- cli/
113112
- cli_request #1303

user_guide_src/source/changelogs/v4.0.0-alpha.3.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Release Date: November 30, 2018
55

66
**Next alpha release of CodeIgniter4**
77

8-
98
The list of changed files follows, with PR numbers shown.
109

1110
- admin/

user_guide_src/source/changelogs/v4.0.0-beta.1.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ PRs merged:
158158
- #1737 Added support for dropTable and modifyTable with SQLite driver
159159
- #1736 Accommodate long travis execution times
160160
- #1733 Fix increment and decrement errors with Postgres
161-
- #1732 Don't check from CLI in Routes. Fixes #1724
161+
- #1732 Don't check from CLI in Routes. Fixes #1724
162162
- #1729 New View Layout functionality for simple template
163163
- #1725 Update Request.php
164164
- #1723 Log an error if redis authentication is failed
@@ -176,4 +176,4 @@ PRs merged:
176176
- #4f4a37 remove debugging from Model.
177177
- #1699 Fix install link in user guide
178178
- #1696 Fix page structure etc
179-
- #1695 Tidy up code blocks in the user guide
179+
- #1695 Tidy up code blocks in the user guide

user_guide_src/source/changelogs/v4.0.0-beta.2.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ The list of changed files follows, with PR numbers shown.
153153
- ViewTest #1827, #1836
154154
- ControllerTest #1850
155155

156-
157156
- user_guide_src/
158157
- cli/
159158
- cli_commands #1777
@@ -265,4 +264,4 @@ PRs merged:
265264
- #1769 Correction in Methods and Spellings
266265
- #1762 Fix: decimal rule. shouldn't it accept integers?
267266
- #1746 Improve: Update Model, to selective update created_at / updated_at field.
268-
- #1590 Improve: Enhance 404Override
267+
- #1590 Improve: Enhance 404Override

user_guide_src/source/changelogs/v4.0.0-beta.4.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ New messages:
1717

1818
App changes:
1919

20-
2120
Testing changes:
2221

2322
- enhanced database & migration testing in tests/_support
@@ -152,7 +151,6 @@ The list of changed files follows, with PR numbers shown.
152151
- testing/
153152
- database #2051, #2053
154153

155-
156154
PRs merged:
157155
-----------
158156

user_guide_src/source/changelogs/v4.0.0-rc.2.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ The list of changed files follows, with PR numbers shown.
162162
- news_section #2221
163163
- static_pages #2221
164164

165-
166165
PRs merged:
167166
--------------------------
168167

user_guide_src/source/changelogs/v4.0.0-rc.3.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ App changes:
1616

1717
Message changes:
1818

19-
2019
The list of changed files follows, with PR numbers shown.
2120

2221
- admin/
@@ -121,7 +120,6 @@ The list of changed files follows, with PR numbers shown.
121120
- outgoing/
122121
- table #2337
123122

124-
125123
PRs merged:
126124
-----------
127125

user_guide_src/source/changelogs/v4.0.0-rc.4.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Enhancements:
1212
- Add validation function `is_not_unique`
1313
- Various improvements and cleanup to the Email class
1414

15-
1615
PRs merged:
1716
-----------
1817
- #2527 Update manual.rst

0 commit comments

Comments
 (0)