- First commit
This commit is contained in:
commit
f5317f906d
9 files changed
+484
No files matched your search
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Api;
|
||||
|
||||
use League\CommonMark\CommonMarkConverter;
|
||||
use Notes\Attribute\Ignore;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
trait LeanApiTrait
|
||||
{
|
||||
#[Ignore]
|
||||
public function renderMarkdown(string $filepath, array $entities = [], array $forms = [], int $code = 200, array $headers = []) : ResponseInterface
|
||||
{
|
||||
if ( ! class_exists(CommonMarkConverter::class)) {
|
||||
throw new \BadFunctionCallException("League\CommonMark seems to be missing, please install dependency before trying to render Markdown content");
|
||||
}
|
||||
|
||||
$markdown = ( new CommonMarkConverter() )->convert(file_get_contents($filepath))->getContent();
|
||||
|
||||
if (str_contains($markdown, '{route:descriptor}'))
|
||||
{
|
||||
$describe = (new RouteDescriptor($this))->describe();
|
||||
$markdown = str_replace('{route:descriptor}', $describe, $markdown);
|
||||
}
|
||||
|
||||
if (str_contains($markdown, '{entity:descriptor}'))
|
||||
{
|
||||
$describe = (new EntityDescriptor())->describe(... $entities);
|
||||
$markdown = str_replace('{entity:descriptor}', $describe, $markdown);
|
||||
}
|
||||
|
||||
|
||||
if (str_contains($markdown, '{form:descriptor}'))
|
||||
{
|
||||
$describe = (new FormDescriptor())->describe(... $forms);
|
||||
$markdown = str_replace('{form:descriptor}', $describe, $markdown);
|
||||
}
|
||||
|
||||
return $this->renderView("lean/layout/docs", get_defined_vars());
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
protected function output(\JsonSerializable|array $data, int $count) {
|
||||
return $this->renderJson([
|
||||
'data' => $data,
|
||||
'count' => $count,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user