-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5689 from sfadschm/docs-example-code
[Docs] Extract example php code for static analysis.
- Loading branch information
Showing
1,572 changed files
with
14,548 additions
and
9,526 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of CodeIgniter 4 framework. | ||
* | ||
* (c) CodeIgniter Foundation <admin@codeigniter.com> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
$srcFolder = __DIR__ . '/source'; | ||
|
||
// Exclude static folders | ||
$excludes = ['_static', 'images']; | ||
|
||
// Safety prefix | ||
$prefix = 'old_'; | ||
|
||
// Begin user info | ||
echo 'The following sections were renumerated:', PHP_EOL; | ||
|
||
// Loop source directory | ||
$srcIterator = new DirectoryIterator($srcFolder); | ||
|
||
foreach ($srcIterator as $chapterInfo) { | ||
if (! $chapterInfo->isDot() && $chapterInfo->isDir() && ! in_array($chapterInfo->getFilename(), $excludes, true)) { | ||
$chapterName = $chapterInfo->getFilename(); | ||
|
||
// Iterate the working directory | ||
$chapterIterator = new DirectoryIterator($chapterInfo->getPathname()); | ||
|
||
foreach ($chapterIterator as $sectionInfo) { | ||
if (! $sectionInfo->isDot() && $sectionInfo->isFile() && $sectionInfo->getExtension() === 'rst') { | ||
$sectionName = $sectionInfo->getBasename('.rst'); | ||
$sectionFolder = $sectionInfo->getPath() . '/' . $sectionName; | ||
|
||
// Read the section file | ||
$sectionContent = file_get_contents($sectionInfo->getPathname()); | ||
|
||
// Match all includes | ||
preg_match_all("~\\.\\. literalinclude:: {$sectionName}\\/(.+)\\.php(\n[ ]*:lines: 2\\-)?~", $sectionContent, $matches); | ||
$includeStrings = $matches[0]; | ||
$exampleNames = $matches[1]; | ||
|
||
// Exit early if no matches | ||
if (count($exampleNames) === 0) { | ||
continue; | ||
} | ||
|
||
// Check if examples are consecutive | ||
$consecutive = true; | ||
|
||
foreach ($exampleNames as $exampleIndex => $exampleName) { | ||
if (str_pad($exampleIndex + 1, 3, '0', STR_PAD_LEFT) !== $exampleName) { | ||
$consecutive = false; | ||
break; | ||
} | ||
} | ||
|
||
// Exit if examples are already consecutive | ||
if ($consecutive) { | ||
continue; | ||
} | ||
|
||
// Rename all example files to avoid conflicts | ||
$exampleIterator = new DirectoryIterator($sectionFolder); | ||
|
||
foreach ($exampleIterator as $exampleInfo) { | ||
if (! $exampleInfo->isDot() && $exampleInfo->isFile() && $exampleInfo->getExtension() === 'php') { | ||
rename($exampleInfo->getPathname(), $exampleInfo->getPath() . '/' . $prefix . $exampleInfo->getFilename()); | ||
} | ||
} | ||
$sectionContent = preg_replace("~\\.\\. literalinclude:: {$sectionName}\\/(.+)\\.php~", ".. literalinclude:: {$sectionName}/{$prefix}$1.php", $sectionContent); | ||
|
||
// Renumerate examples | ||
foreach ($exampleNames as $exampleIndex => $exampleName) { | ||
$newName = str_pad($exampleIndex + 1, 3, '0', STR_PAD_LEFT); | ||
|
||
// Rename example file | ||
rename($sectionFolder . '/' . $prefix . $exampleName . '.php', $sectionFolder . '/' . $newName . '.php'); | ||
|
||
// Fix include link | ||
$sectionContent = preg_replace(preg_quote(str_replace($exampleName, $prefix . $exampleName, $includeStrings[$exampleIndex]), '~'), str_replace($exampleName, $newName, $includeStrings[$exampleIndex]), $sectionContent, 1, $count); | ||
} | ||
|
||
// Write new content to rst | ||
file_put_contents($sectionInfo->getPathname(), $sectionContent); | ||
|
||
// User info | ||
echo $chapterName, '/', $sectionName, PHP_EOL; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// End user info | ||
echo 'Renumerating finished.', PHP_EOL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,7 +107,6 @@ tests / | |
- ParserTest #1311 | ||
- EntityTest #1319 | ||
|
||
|
||
user_guide_src /source/ | ||
- cli/ | ||
- cli_request #1303 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace App\Controllers; | ||
|
||
use CodeIgniter\Controller; | ||
|
||
class Tools extends Controller | ||
{ | ||
public function message($to = 'World') | ||
{ | ||
echo "Hello {$to}!" . PHP_EOL; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
$routes->cli('tools/message/(:segment)', 'Tools::message/$1'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.