React-like library for component based development in PHP.
class MyComponent extends \React\Component {
static function render($props = []) {
?>
<p>This is the message: <?= $props['msg'] ?></p>
<?php
}
}
class MyOtherComponent extends \React\Component {
static function render($props = []) {
?>
<div>
<?php self::render_children($props['children']) ?>
</div>
<?php
}
}
// Basic
MyComponent::render(['msg' => 'Hello World!']);
// Nested
MyOtherComponent::render([
'children' => [
new MyComponent(['msg' => 'First child']),
new MyComponent(['msg' => 'Second child']),
]
]);
I recommend using webpack so you can co-locate both the back end and the front end code of each component in the same directory. The structure for a generic project could look like this:
.
└── src
├── MyComponent
│ ├── Component.php
│ ├── index.js
│ └── style.css
├── MyOtherComponent
│ ├── Component.php
│ ├── index.js
│ └── style.css
└── index.js