Skip to content

Commit 4259a2a

Browse files
committed
Pull external schemas and fix example URL
1 parent f06c567 commit 4259a2a

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/PHPDraft/In/ApibFileParser.php

+25-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ function get_apib($filename)
6060
$this->get_apib($this->location . $value . '.apib'), $file);
6161
}
6262

63+
preg_match_all('<!-- schema\(([a-z0-9_.\/\:]*?)\) -->', $file, $matches);
64+
foreach ($matches[1] as $value) {
65+
$file = str_replace('<!-- schema(' . $value . ') -->', $this->get_schema($value), $file);
66+
}
67+
6368
return $file;
6469
}
6570

@@ -72,13 +77,31 @@ function get_apib($filename)
7277
*/
7378
private function file_check($filename)
7479
{
75-
if (!file_exists($filename))
76-
{
80+
if (!file_exists($filename)) {
7781
file_put_contents('php://stderr', "API File not found: $filename\n");
7882
exit(1);
7983
}
8084
}
8185

86+
/**
87+
* Get an external Schema by URL
88+
*
89+
* @param string $url URL to fetch the schema from
90+
*
91+
* @return string The schema as a string
92+
*/
93+
function get_schema($url)
94+
{
95+
$ch = curl_init();
96+
curl_setopt($ch, CURLOPT_URL, $url);
97+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
98+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
99+
$result = curl_exec($ch);
100+
curl_close($ch);
101+
102+
return $result;
103+
}
104+
82105
/**
83106
* Return the value of the class
84107
*

src/PHPDraft/Out/HTML/default.phtml

+1-2
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,7 @@ $base = $this->categories;
177177
<?= $request->description; ?>
178178
<?php if ($transition->url_variables !== []): ?>
179179
<h5>Example URI</h5>
180-
<span class="base-url"><?= $this->base_data['HOST']; ?></span>
181-
<em><?= $transition->build_url(); ?></em>
180+
<span class="base-url"><?= $this->base_data['HOST']; ?></span><em><?= $transition->build_url(); ?></em>
182181
<?php endif; ?>
183182
<?php if ($request->headers !== []): ?>
184183
<h5>Headers</h5>

0 commit comments

Comments
 (0)