├── example
├── build
│ └── .gitkeep
├── src
│ ├── react-bundle.js
│ └── table.js
├── package.json
├── README.md
└── example.php
├── .gitignore
├── composer.json
├── LICENSE
├── PATENTS
├── README.md
└── ReactJS.php
/example/build/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | example/node_modules
2 | example/build
3 |
--------------------------------------------------------------------------------
/example/src/react-bundle.js:
--------------------------------------------------------------------------------
1 | // We know we're using browserify which compiles modules with global exposted
2 | global.React = require('react');
3 | global.ReactDOM = require('react-dom');
4 | global.ReactDOMServer = require('react-dom/server');
5 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "reactjs/react-php-v8js",
3 | "description": "PHP library that renders React components on the server",
4 | "require": {
5 | "ext-v8js": ">=0.1.3"
6 | },
7 | "license": "BSD-3-Clause",
8 | "autoload": {
9 | "classmap": ["ReactJS.php"]
10 | }
11 | }
--------------------------------------------------------------------------------
/example/src/table.js:
--------------------------------------------------------------------------------
1 | /**!
2 | * Copyright (c) 2014, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | */
9 | var Table = React.createClass({
10 | render: function () {
11 | var rows = this.props.data.map(function (row) {
12 | var cells = row.map(function(cell) {
13 | return
{cell} | ;
14 | });
15 |
16 | return {cells}
;
17 | });
18 |
19 | return (
20 |
23 | );
24 | }
25 | });
26 |
--------------------------------------------------------------------------------
/example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-php-v8js",
3 | "private": true,
4 | "version": "1.0.0",
5 | "scripts": {
6 | "make": "npm run make-dev && npm run make-min && npm run make-table",
7 | "make-dev": "browserify -t [ envify --NODE_ENV development ] src/react-bundle.js > build/react-bundle.js",
8 | "make-min": "browserify -t [ envify --NODE_ENV production ] src/react-bundle.js | uglifyjs > build/react-bundle.min.js",
9 | "make-table": "babel --presets react src/table.js > build/table.js"
10 | },
11 | "dependencies": {
12 | "babel-cli": "^6.3.17",
13 | "babel-preset-react": "^6.3.13",
14 | "browserify": "^12.0.1",
15 | "envify": "^3.4.0",
16 | "react": "^0.14.5",
17 | "react-dom": "^0.14.5",
18 | "uglifyjs": "^2.4.10"
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | BSD License for React-PHP-V8Js
2 |
3 | Copyright (c) 2014, Facebook, Inc. All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without modification,
6 | are permitted provided that the following conditions are met:
7 |
8 | * Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | * Redistributions in binary form must reproduce the above copyright notice,
12 | this list of conditions and the following disclaimer in the documentation
13 | and/or other materials provided with the distribution.
14 |
15 | * Neither the name Facebook nor the names of its contributors may be used to
16 | endorse or promote products derived from this software without specific
17 | prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
--------------------------------------------------------------------------------
/example/README.md:
--------------------------------------------------------------------------------
1 | # Example
2 |
3 | This example uses npm to build a custom library that will be inserted to be used for rendering React. You may want to do something similar in your own project.
4 |
5 | ## Set up
6 |
7 | 1. Ensure node and npm are installed
8 | 2. `npm install`
9 | 3. `npm run make`
10 |
11 | This will create several files in the `build/` directory. `bundle-react.js` is what will be passed into the `ReactJS` constructor as `libsrc`. It exposes 3 globals: `React`, `ReactDOM`, and `ReactDOMServer`.
12 |
13 | ## Alternative Approach
14 |
15 | This example works by building a single bundle for React exposing 3 globals. Another approach would be to concatenate the existing 3 browser bundles that React ships with. Each of these exposes the necessary globals. Here's how you might change the existing `example.php` to make this work.
16 |
17 | ```diff
18 | @@ -14,9 +14,11 @@
19 | include '../ReactJS.php';
20 |
21 | $rjs = new ReactJS(
22 | // location of React's code
23 | - file_get_contents('build/react-bundle.js'),
24 | + file_get_contents('path/to/react/react.js') .
25 | + file_get_contents('path/to/react/react-dom.js') .
26 | + file_get_contents('path/to/react/react-dom-server.js'),
27 | // app code
28 | file_get_contents('build/table.js')
29 | );
30 |
31 | @@ -46,9 +48,10 @@ $rjs->setComponent('Table', $data);
32 |
33 | getMarkup(); ?>
34 |
35 |
36 | -
37 | +
38 | +
39 |
40 |
41 |
51 |
52 |
53 |
61 |