Skip to content

Commit

Permalink
Pull external schemas and fix example URL
Browse files Browse the repository at this point in the history
  • Loading branch information
SMillerDev committed Dec 19, 2016
1 parent f06c567 commit 4259a2a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
27 changes: 25 additions & 2 deletions src/PHPDraft/In/ApibFileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ function get_apib($filename)
$this->get_apib($this->location . $value . '.apib'), $file);
}

preg_match_all('<!-- schema\(([a-z0-9_.\/\:]*?)\) -->', $file, $matches);
foreach ($matches[1] as $value) {
$file = str_replace('<!-- schema(' . $value . ') -->', $this->get_schema($value), $file);
}

return $file;
}

Expand All @@ -72,13 +77,31 @@ function get_apib($filename)
*/
private function file_check($filename)
{
if (!file_exists($filename))
{
if (!file_exists($filename)) {
file_put_contents('php://stderr', "API File not found: $filename\n");
exit(1);
}
}

/**
* Get an external Schema by URL
*
* @param string $url URL to fetch the schema from
*
* @return string The schema as a string
*/
function get_schema($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);

return $result;
}

/**
* Return the value of the class
*
Expand Down
3 changes: 1 addition & 2 deletions src/PHPDraft/Out/HTML/default.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ $base = $this->categories;
<?= $request->description; ?>
<?php if ($transition->url_variables !== []): ?>
<h5>Example URI</h5>
<span class="base-url"><?= $this->base_data['HOST']; ?></span>
<em><?= $transition->build_url(); ?></em>
<span class="base-url"><?= $this->base_data['HOST']; ?></span><em><?= $transition->build_url(); ?></em>
<?php endif; ?>
<?php if ($request->headers !== []): ?>
<h5>Headers</h5>
Expand Down

0 comments on commit 4259a2a

Please sign in to comment.