14
14
* Requires V8JS PHP extension: http://php.net/v8js
15
15
*/
16
16
class ReactJS {
17
-
17
+
18
18
private
19
19
/**
20
20
* Name of the component to render
21
21
* @var string
22
22
*/
23
23
$ component ,
24
-
24
+
25
25
/**
26
26
* Properties that go along with the component
27
27
* @var mixed
28
28
*/
29
29
$ data = null ,
30
-
30
+
31
31
/**
32
32
* Instance of V8Js class
33
33
* @var object
34
34
*/
35
35
$ v8 ,
36
-
36
+
37
37
/**
38
38
* Custom error handler
39
39
* @var callable
40
40
*/
41
41
$ errorHandler ;
42
-
42
+
43
43
/**
44
44
* Initialize by passing JS code as a string.
45
45
* The application source code is concatenated string
@@ -64,7 +64,7 @@ function __construct($libsrc, $appsrc) {
64
64
$ this ->v8 = new V8Js ();
65
65
$ this ->executeJS ($ concatenated );
66
66
}
67
-
67
+
68
68
/**
69
69
* Which components is to be rendered along with it's data
70
70
* E.g.
@@ -80,7 +80,7 @@ function setComponent($component, $data = null) {
80
80
$ this ->data = json_encode ($ data );
81
81
return $ this ;
82
82
}
83
-
83
+
84
84
/**
85
85
* Custom error handler. The default one var_dumps the exception
86
86
* and die()s.
@@ -92,7 +92,7 @@ function setErrorHandler($err) {
92
92
$ this ->errorHandler = $ err ;
93
93
return $ this ;
94
94
}
95
-
95
+
96
96
/**
97
97
* Returns the markup to print to the page
98
98
*
@@ -106,18 +106,18 @@ function getMarkup() {
106
106
107
107
return $ this ->executeJS ($ js );
108
108
}
109
-
109
+
110
110
/**
111
111
* Returns JS to be inlined in the page (without <script> tags)
112
112
* It instantiates the client side, once the JS arrives
113
- *
113
+ *
114
114
* NOTE: This class makes no attempt to load files JS so you can load it
115
115
* however is appropriate - from a CDN, asynchronously, etc.
116
116
*
117
- * e.g. getJS('document.body');
117
+ * e.g. getJS('document.body');
118
118
* renders in body and doesn't retain a var
119
- * e.g. getJS('#page', "GLOB");
120
- * renders in element id="page" and assigns the component to
119
+ * e.g. getJS('#page', "GLOB");
120
+ * renders in element id="page" and assigns the component to
121
121
* a JavaScript variable named GLOB for later use if needed
122
122
* @param string $where A reference to a DOM object, or an ID
123
123
* for convenience if prefixed by a #. E.g. "#page"
@@ -134,7 +134,7 @@ function getJS($where, $return_var = null) {
134
134
substr ($ where , 1 )
135
135
);
136
136
}
137
- return
137
+ return
138
138
($ return_var ? "var $ return_var = " : "" ) .
139
139
sprintf (
140
140
"React.render(React.createElement(%s, %s), %s); " ,
@@ -163,10 +163,9 @@ private function executeJS($js) {
163
163
echo "<pre> " ;
164
164
echo $ e ->getMessage ();
165
165
echo "</pre> " ;
166
- die ();
166
+ die ();
167
167
}
168
168
}
169
169
}
170
170
171
171
}
172
-
0 commit comments