diff --git a/README.md b/README.md index 646e36b..a98f2fd 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ You can get the value of body by `escape()` or `raw()`. render(['hello']); +$view = $ssr->render(['hello']); return <<<"EOT" @@ -112,10 +112,10 @@ return <<<"EOT" {$ssr->escape('title')} -
{$markup}
+
{$view->markup}
- + EOT; diff --git a/composer.json b/composer.json index 40db4ca..d42ec64 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "require": { "php": ">=7.0.0", "bear/resource": "^1.2", - "koriym/redux-react-ssr": "^0.2" + "koriym/redux-react-ssr": "^1.0.1" }, "require-dev": { "phpunit/phpunit": "^5.3" @@ -18,10 +18,7 @@ ], "autoload": { "psr-4": { - "BEAR\\ReactJsModule\\": [ - "src/", - "src-deprecated" - ] + "BEAR\\ReactJsModule\\": "src/" } }, "autoload-dev": { diff --git a/docs/demo/Greeting.html.php b/docs/demo/Greeting.html.php index 0bba59e..4cd375b 100644 --- a/docs/demo/Greeting.html.php +++ b/docs/demo/Greeting.html.php @@ -3,7 +3,7 @@ use BEAR\ReactJsModule\Ssr; /* @var $ssr Ssr */ -list($markup, $script) = $ssr->render(['hello']); +$view = $ssr->render(['hello']); return <<<"EOT" @@ -12,10 +12,10 @@ {$ssr->escape('title')} -
{$markup}
+
{$view->markup}
- + EOT; diff --git a/src-deprecated/ReactJsModule.php b/src-deprecated/ReactJsModule.php deleted file mode 100644 index d489098..0000000 --- a/src-deprecated/ReactJsModule.php +++ /dev/null @@ -1,51 +0,0 @@ -reactLibsrc = $reactLibsrc; - $this->reactAppSrc = $reactAppSrc; - } - - /** - * {@inheritdoc} - */ - protected function configure() - { - $this->bind()->annotatedWith('reactBundleSrc')->toInstance(file_get_contents($this->reactAppSrc)); - $this->bind()->annotatedWith('appBundleSrc')->toInstance(file_get_contents($this->reactLibsrc)); - $this->bind(ReduxSsrInterface::class)->toConstructor(ReduxReactSsr::class, 'reactBundleSrc=reactBundleSrc,appBundleSrc=appBundleSrc'); - $this->bind(RenderInterface::class)->annotatedWith(ReduxSsrInject::class)->to(ReduxServerSideRenderer::class)->in(Scope::SINGLETON); - } -} diff --git a/src-deprecated/ReduxServerSideRenderer.php b/src-deprecated/ReduxServerSideRenderer.php deleted file mode 100644 index 3118fb4..0000000 --- a/src-deprecated/ReduxServerSideRenderer.php +++ /dev/null @@ -1,44 +0,0 @@ -ssr = $ssr; - } - - /** - * {@inheritdoc} - * - * @SuppressWarnings(PHPMD.UnusedLocalVariable) - */ - public function render(ResourceObject $ro) - { - $file = $ro instanceof WeavedInterface ? (new \ReflectionClass($ro))->getParentClass()->getFileName() : (new \ReflectionClass($ro))->getFileName(); - $template = substr($file, 0, -4) . '.html.php'; - $ssr = $this->ssr; - $ro->view = require $template; - - return $ro->view; - } -} diff --git a/src-deprecated/ReduxSsr.php b/src-deprecated/ReduxSsr.php deleted file mode 100644 index d574507..0000000 --- a/src-deprecated/ReduxSsr.php +++ /dev/null @@ -1,35 +0,0 @@ -renderer = $renderer; - } -} diff --git a/src/ReduxModule.php b/src/ReduxModule.php index 8c94e1b..0090c70 100644 --- a/src/ReduxModule.php +++ b/src/ReduxModule.php @@ -7,6 +7,8 @@ namespace BEAR\ReactJsModule; use BEAR\Resource\RenderInterface; +use Koriym\ReduxReactSsr\ExceptionHandler; +use Koriym\ReduxReactSsr\ExceptionHandlerInterface; use Koriym\ReduxReactSsr\ReduxReactJs; use Koriym\ReduxReactSsr\ReduxReactJsInterface; use Ray\Di\AbstractModule; @@ -53,5 +55,11 @@ protected function configure() $this->bind(ReduxReactJsInterface::class)->annotatedWith($this->name)->toConstructor(ReduxReactJs::class, $reduxReactJsname); $reduxRendererName = "appName=redux_app_name_{$this->name},redux={$this->name}"; $this->bind(RenderInterface::class)->annotatedWith($this->name)->toConstructor(ReduxRenderer::class, $reduxRendererName); + $this->bind(ExceptionHandlerInterface::class)->to(ExceptionHandler::class); + $this->bind(\V8Js::class)->toConstructor(\V8Js::class, 'object_name=v8js_object_name,variables=v8js_variables,extensions=v8js_extensions,snapshot_blob=v8js_snapshot_blob'); + $this->bind()->annotatedWith('v8js_object_name')->toInstance(''); + $this->bind()->annotatedWith('v8js_variables')->toInstance([]); + $this->bind()->annotatedWith('v8js_extensions')->toInstance([]); + $this->bind()->annotatedWith('v8js_snapshot_blob')->toInstance(''); } } diff --git a/src/Ssr.php b/src/Ssr.php index 75d1484..353b6c3 100644 --- a/src/Ssr.php +++ b/src/Ssr.php @@ -11,6 +11,7 @@ use BEAR\ReactJsModule\Exception\BodyKeyNotExistsException; use BEAR\Resource\ResourceObject; use Koriym\ReduxReactSsr\ReduxReactJs; +use Koriym\ReduxReactSsr\View; final class Ssr implements SsrInterface { @@ -49,7 +50,7 @@ public function __construct(ResourceObject $ro, ReduxReactJs $reduxReactJs, stri /** * {@inheritdoc} */ - public function render(array $storeNames, string $rootContainer = 'App', string $domId = 'root') : array + public function render(array $storeNames, string $rootContainer = 'App', string $domId = 'root') : View { $body = $this->ro->body; $store = []; @@ -59,9 +60,9 @@ public function render(array $storeNames, string $rootContainer = 'App', string } $store[$storeName] = $body[$storeName]; } - list($markup, $script) = $this->reduxReactJs->__invoke($rootContainer, $store, $domId); + $view = $this->reduxReactJs->__invoke($rootContainer, $store, $domId); - return [$markup, $script]; + return $view; } /** diff --git a/src/SsrInterface.php b/src/SsrInterface.php index 5af7144..2251673 100644 --- a/src/SsrInterface.php +++ b/src/SsrInterface.php @@ -8,6 +8,8 @@ */ namespace BEAR\ReactJsModule; +use Koriym\ReduxReactSsr\View; + interface SsrInterface { /** @@ -19,7 +21,7 @@ interface SsrInterface * * @return array [$markup, $script] */ - public function render(array $storeNames, string $rootContainer = 'App', string $domId = 'root') : array; + public function render(array $storeNames, string $rootContainer = 'App', string $domId = 'root') : View; /** * Get escaped resource body item diff --git a/tests/Fake/FakeReduxRo.html.php b/tests/Fake/FakeReduxRo.html.php index f2e1aaa..33537a9 100644 --- a/tests/Fake/FakeReduxRo.html.php +++ b/tests/Fake/FakeReduxRo.html.php @@ -4,7 +4,7 @@ use Koriym\ReduxReactSsr\ReduxSsrInterface; /* @var $ssr Ssr */ -list($markup, $script) = $ssr->render(['hello']); +$view = $ssr->render(['hello']); return <<<"EOD" @@ -16,10 +16,10 @@ -
{$markup}>
+
{$view->markup}>
- + EOD; diff --git a/tests/ReactJsModuleTest.php b/tests/ReactJsModuleTest.php deleted file mode 100644 index cb4e888..0000000 --- a/tests/ReactJsModuleTest.php +++ /dev/null @@ -1,21 +0,0 @@ -getInstance(RenderInterface::class, ReduxSsrInject::class); - $this->assertInstanceOf(ReduxServerSideRenderer::class, $renderer); - } -} diff --git a/tests/ReduxModuleTest.php b/tests/ReduxModuleTest.php index 2cd7291..e13d3c8 100644 --- a/tests/ReduxModuleTest.php +++ b/tests/ReduxModuleTest.php @@ -10,7 +10,11 @@ public function testModule() { $uiPath = __DIR__ . '/Fake'; $injector = new Injector(new ReduxModule($uiPath, 'ssr_app')); - $ro = $injector->getInstance(FakeReduxRo::class); + try { + $ro = $injector->getInstance(FakeReduxRo::class); + } catch (\Exception $e) { + echo $e; + } $this->assertInstanceOf(ReduxRenderer::class, $ro->renderer); } } diff --git a/tests/ReduxRendererTest.php b/tests/ReduxRendererTest.php index 20ab5a9..d1385c3 100644 --- a/tests/ReduxRendererTest.php +++ b/tests/ReduxRendererTest.php @@ -3,6 +3,7 @@ namespace BEAR\ReactJsModule; use BEAR\ReactJsModule\Exception\BodyKeyNotExistsException; +use Koriym\ReduxReactSsr\ExceptionHandler; use Koriym\ReduxReactSsr\ReduxReactJs; class ReduxRendererTest extends \PHPUnit_Framework_TestCase @@ -13,7 +14,12 @@ public function testRender() $appBundleJs = file_get_contents(__DIR__ . '/Fake/app.bundle.js'); $reduxRenderer = new ReduxRenderer( 'app', - new ReduxReactJs($reactBundleJs, $appBundleJs) + new ReduxReactJs( + $reactBundleJs, + $appBundleJs, + new ExceptionHandler(), + new \V8Js() + ) ); $ro = new FakeReduxRo; $ro->setRenderer($reduxRenderer); @@ -31,7 +37,7 @@ public function testRender()

konichiwa

>
- + EOT; @@ -45,7 +51,11 @@ public function testRenderWithNoKey() $appBundleJs = file_get_contents(__DIR__ . '/Fake/app.bundle.js'); $reduxRenderer = new ReduxRenderer( 'app', - new ReduxReactJs($reactBundleJs, $appBundleJs) + new ReduxReactJs( + $reactBundleJs, + $appBundleJs, + new ExceptionHandler(), + new \V8Js()) ); $ro = new FakeReduxRo; unset($ro->body['hello']); diff --git a/tests/SsrTest.php b/tests/SsrTest.php index d2b66b3..764bba6 100644 --- a/tests/SsrTest.php +++ b/tests/SsrTest.php @@ -3,6 +3,7 @@ namespace BEAR\ReactJsModule; use BEAR\ReactJsModule\Exception\BodyKeyNotExistsException; +use Koriym\ReduxReactSsr\ExceptionHandler; use Koriym\ReduxReactSsr\ReduxReactJs; class SsrTest extends \PHPUnit_Framework_TestCase @@ -18,7 +19,9 @@ public function setUp() new FakeReduxRo, new ReduxReactJs( file_get_contents(__DIR__ . '/Fake/react.bundle.js'), - file_get_contents(__DIR__ . '/Fake/app.bundle.js') + file_get_contents(__DIR__ . '/Fake/app.bundle.js'), + new ExceptionHandler(), + new \V8Js() ), 'app' );