@@ -74,6 +74,9 @@ |
||
74 | 74 | return (string) $this->execJs->evalJs($code); |
75 | 75 | } |
76 | 76 | |
77 | + /** |
|
78 | + * @param string $bundleSrc |
|
79 | + */ |
|
77 | 80 | private function getSsrCode($bundleSrc, array $store, array $metas) : string |
78 | 81 | { |
79 | 82 | $storeJson = json_encode($store); |
@@ -47,10 +47,10 @@ |
||
47 | 47 | /** |
48 | 48 | * {@inheritdoc} |
49 | 49 | */ |
50 | - public function render(string $appName, array $store, array $metas = []) : string |
|
50 | + public function render(string $appName, array $store, array $metas = [ ]) : string |
|
51 | 51 | { |
52 | 52 | $bundleSrcPath = sprintf('%s/%s.bundle.js', $this->bundleSrcBasePath, $appName); |
53 | - if (! file_exists($bundleSrcPath)) { |
|
53 | + if (!file_exists($bundleSrcPath)) { |
|
54 | 54 | throw new JsFileNotExistsException($bundleSrcPath); |
55 | 55 | } |
56 | 56 | $bundleSrc = file_get_contents($bundleSrcPath); |
@@ -5,6 +5,6 @@ |
||
5 | 5 | use Koriym\Baracoa\Baracoa; |
6 | 6 | |
7 | 7 | $baracoa = new Baracoa(__DIR__, new ExceptionHandler()); |
8 | -$state = ['name' => 'World']; |
|
8 | +$state = [ 'name' => 'World' ]; |
|
9 | 9 | |
10 | 10 | echo $baracoa->render('min_ssr', $state) . PHP_EOL; |
@@ -6,8 +6,8 @@ |
||
6 | 6 | |
7 | 7 | $jsBundleDir = __DIR__ . '/build'; |
8 | 8 | $baracoa = new Baracoa($jsBundleDir, new ExceptionHandler(), new V8Js()); |
9 | -$state = ['hello' => ['name' => 'SSR']]; |
|
10 | -$metas = ['title' => '<page-title>']; |
|
9 | +$state = [ 'hello' => [ 'name' => 'SSR' ] ]; |
|
10 | +$metas = [ 'title' => '<page-title>' ]; |
|
11 | 11 | $html = $baracoa->render('index_ssr', $state, $metas); |
12 | 12 | |
13 | 13 | echo $html; |
@@ -7,8 +7,8 @@ |
||
7 | 7 | |
8 | 8 | $jsBundleDir = __DIR__ . '/build'; |
9 | 9 | $baracoa = new CacheBaracoa($jsBundleDir, new ExceptionHandler(), new FilesystemCache()); |
10 | -$state = ['hello' => ['name' => 'SSR']]; |
|
11 | -$metas = ['title' => '<page-title>']; |
|
10 | +$state = [ 'hello' => [ 'name' => 'SSR' ] ]; |
|
11 | +$metas = [ 'title' => '<page-title>' ]; |
|
12 | 12 | $html = $baracoa->render('index_ssr', $state, $metas); |
13 | 13 | |
14 | 14 | echo $html; |
@@ -6,6 +6,6 @@ |
||
6 | 6 | |
7 | 7 | $jsBundleDir = __DIR__ . '/build'; |
8 | 8 | $baracoa = new Baracoa($jsBundleDir, new ExceptionHandler()); |
9 | -$html = $baracoa->render('handlesbar', ['name' => 'Handlebar']); |
|
9 | +$html = $baracoa->render('handlesbar', [ 'name' => 'Handlebar' ]); |
|
10 | 10 | |
11 | 11 | echo $html; |
@@ -39,13 +39,13 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * {@inheritdoc} |
41 | 41 | */ |
42 | - public function render(string $appName, array $store, array $metas = []) : string |
|
42 | + public function render(string $appName, array $store, array $metas = [ ]) : string |
|
43 | 43 | { |
44 | - if (! $this->cache->has($appName)) { |
|
44 | + if (!$this->cache->has($appName)) { |
|
45 | 45 | $this->saveSnapshot($appName); |
46 | 46 | } |
47 | 47 | $snapShot = $this->cache->get($appName); |
48 | - $v8 = new V8Js('PHP', [], [], true, $snapShot); |
|
48 | + $v8 = new V8Js('PHP', [ ], [ ], true, $snapShot); |
|
49 | 49 | try { |
50 | 50 | $html = $v8->executeString($this->getSsrCode($store, $metas)); |
51 | 51 | } catch (\V8JsScriptException $e) { |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | private function saveSnapshot(string $appName) : void |
63 | 63 | { |
64 | 64 | $bundleSrcPath = sprintf('%s/%s.bundle.js', $this->bundleSrcBasePath, $appName); |
65 | - if (! file_exists($bundleSrcPath)) { |
|
65 | + if (!file_exists($bundleSrcPath)) { |
|
66 | 66 | throw new JsFileNotExistsException($bundleSrcPath); |
67 | 67 | } |
68 | 68 | $bundleSrc = file_get_contents($bundleSrcPath); |
@@ -12,7 +12,7 @@ |
||
12 | 12 | { |
13 | 13 | $erroCode = mb_strimwidth($e->getJsSourceLine(), $e->getJsStartColumn(), 240, '...'); |
14 | 14 | $errorMsg = sprintf( |
15 | - "%s\n%s\nJS Stack trace:\n%s" , |
|
15 | + "%s\n%s\nJS Stack trace:\n%s", |
|
16 | 16 | $e->getMessage(), |
17 | 17 | $erroCode, |
18 | 18 | $e->getJsTrace() |
@@ -17,5 +17,5 @@ |
||
17 | 17 | * |
18 | 18 | * @return string |
19 | 19 | */ |
20 | - public function render(string $appName, array $store, array $metas = []) : string; |
|
20 | + public function render(string $appName, array $store, array $metas = [ ]) : string; |
|
21 | 21 | } |