From 0f89061c80c9e81e228bd6cd831e39a867a9c262 Mon Sep 17 00:00:00 2001 From: Jack Chapple Date: Thu, 28 May 2015 14:43:48 +0100 Subject: [PATCH 1/2] Added interface to allow for setting the Javascript scope in which React components are contained --- ReactJS.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/ReactJS.php b/ReactJS.php index 89d961e..e6d8c15 100644 --- a/ReactJS.php +++ b/ReactJS.php @@ -21,6 +21,12 @@ class ReactJS { * @var string */ $component, + + /** + * The Javascript scope in which React components are contained (defaults to global) + * @var string + */ + $componentScope = 'global', /** * Properties that go along with the component @@ -80,6 +86,17 @@ function setComponent($component, $data = null) { $this->data = json_encode($data); return $this; } + + /** + * Sets the Javascript scope in which React components are contained + * + * @param string $scope The Javascript scope + * @return ReactJS $this instance + */ + function setComponentScope($scope) { + $this->componentScope = $scope; + return $this; + } /** * Custom error handler. The default one var_dumps the exception @@ -100,7 +117,8 @@ function setErrorHandler($err) { */ function getMarkup() { $js = sprintf( - "print(React.renderToString(React.createElement(%s, %s)))", + "print(React.renderToString(React.createElement(%s.%s, %s)))", + $this->componentScope, $this->component, $this->data); From 571d8c68c25e7726ebcc12828e2534c26ec53c29 Mon Sep 17 00:00:00 2001 From: 18601673727 <18601673727@163.com> Date: Wed, 16 Dec 2015 14:02:23 +0800 Subject: [PATCH 2/2] https://github.com/reactjs/react-php-v8js/pull/9 --- ReactJS.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ReactJS.php b/ReactJS.php index e6d8c15..22fce20 100644 --- a/ReactJS.php +++ b/ReactJS.php @@ -23,10 +23,10 @@ class ReactJS { $component, /** - * The Javascript scope in which React components are contained (defaults to global) + * The JavaScript scope in which React components are contained (defaults to global) * @var string */ - $componentScope = 'global', + $componentScope, /** * Properties that go along with the component @@ -88,9 +88,9 @@ function setComponent($component, $data = null) { } /** - * Sets the Javascript scope in which React components are contained + * Sets the JavaScript scope in which React components are contained * - * @param string $scope The Javascript scope + * @param string $scope The JavaScript scope * @return ReactJS $this instance */ function setComponentScope($scope) { @@ -116,9 +116,12 @@ function setErrorHandler($err) { * @return string HTML string */ function getMarkup() { + if ($this->componentScope) { + $this->component = $this->componentScope.'.'.$this->component; + } + $js = sprintf( - "print(React.renderToString(React.createElement(%s.%s, %s)))", - $this->componentScope, + "print(React.renderToString(React.createElement(%s, %s)))", $this->component, $this->data); @@ -163,7 +166,7 @@ function getJS($where, $return_var = null) { } /** - * Executes Javascript using V8JS, with primitive exception handling + * Executes JavaScript using V8JS, with primitive exception handling * * @param string $js JS code to be executed * @return string The execution response