-
Notifications
You must be signed in to change notification settings - Fork 3
/
cli.php
executable file
·39 lines (30 loc) · 1.09 KB
/
cli.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
require_once __DIR__ . '/vendor/autoload.php';
use ComponentLibrary\Init;
class CLI
{
public function executeCommand(array $args): void
{
$output = $this->renderComponent($args[1], $args[2], $args[3]);
echo $output . PHP_EOL;
}
private function renderComponent(string $componentClass, string $view, string $componentDataJSON): string
{
if (!class_exists($componentClass)) {
throw new Error("Class $componentClass does not exist");
}
try {
$data = json_decode($componentDataJSON, true);
} catch (Exception $e) {
throw new Error("Could not decode JSON data");
}
$component = new $componentClass($data);
$componentClassPath = (new ReflectionClass($componentClass))->getFileName();
$componentClassDir = dirname($componentClassPath);
$data = $component->getData();
$bladeService = (new Init([]))->getEngine();
return $bladeService->makeView($view, $data, [], $componentClassDir)->render();
}
}
$cli = new CLI();
$cli->executeCommand($argv);