Skip to content

Commit 443af54

Browse files
committed
In: Add support for non apib includes
1 parent 066bdd6 commit 443af54

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

src/PHPDraft/In/ApibFileParser.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ private function get_apib($filename)
7070
$this->file_check($filename);
7171
$file = file_get_contents($filename);
7272
$matches = [];
73-
preg_match_all('<!-- include\(([a-z0-9_.\/]*?).apib\) -->', $file, $matches);
74-
foreach ($matches[1] as $value) {
75-
$file = str_replace('<!-- include(' . $value . '.apib) -->',
76-
$this->get_apib($this->location . $value . '.apib'), $file);
73+
preg_match_all('<!-- include\(([a-z0-9_.\/]*?)(\.[a-z]*?)\) -->', $file, $matches);
74+
for ($i = 0; $i < count($matches[1]); $i++) {
75+
$file = str_replace('<!-- include(' . $matches[1][$i] . $matches[2][$i] . ') -->',
76+
$this->get_apib($this->location . $matches[1][$i] . $matches[2][$i]), $file);
7777
}
7878

7979
preg_match_all('<!-- schema\(([a-z0-9_.\/\:]*?)\) -->', $file, $matches);
@@ -89,6 +89,8 @@ private function get_apib($filename)
8989
*
9090
* @param string $filename File to check
9191
*
92+
* @throws ExecutionException when the file could not be found.
93+
*
9294
* @return void
9395
*/
9496
private function file_check($filename)

src/PHPDraft/In/Tests/ApibFileParserTest.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ class ApibFileParserTest extends BaseTest
2020
{
2121

2222
/**
23-
* Set up tests
24-
* @return void
23+
* Set up tests.
24+
*
25+
* @return void Test is now set up.
2526
*/
2627
public function setUp()
2728
{
@@ -88,7 +89,8 @@ public function testParseBasic()
8889
$full_property->setAccessible(true);
8990

9091
$text = "FORMAT: 1A\nHOST: https://owner-api.teslamotors.com\nEXTRA_HOSTS: https://test.owner-api.teslamotors.com\nSOMETHING: INFO\n\n";
91-
$text .="# Tesla Model S JSON API\nThis is unofficial documentation of the Tesla Model S JSON API used by the iOS and Android apps. It features functionality to monitor and control the Model S remotely.\n\nTEST\nhello";
92+
$text .="# Tesla Model S JSON API\nThis is unofficial documentation of the Tesla Model S JSON API used by the iOS and Android apps. It features functionality to monitor and control the Model S remotely.\n\nTEST";
93+
$text .="\n\n# Hello\nThis is a test.\nhello";
9294

9395
$this->assertSame($text, $full_property->getValue($this->class));
9496
$this->assertSame($text, $this->class->__toString());

tests/statics/drafter/apib/include.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
# Hello
3+
This is a test.

tests/statics/drafter/apib/including.apib

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ SOMETHING: INFO
77
This is unofficial documentation of the Tesla Model S JSON API used by the iOS and Android apps. It features functionality to monitor and control the Model S remotely.
88

99
<!-- include(include.apib) -->
10+
<!-- include(include.md) -->
1011
<!-- schema(include.apib) -->

0 commit comments

Comments
 (0)