2017 © Pedro Peláez
 

library hypernova-php

A PHP client for hypernova. https://github.com/airbnb/hypernova

image

wayfair/hypernova-php

A PHP client for hypernova. https://github.com/airbnb/hypernova

  • Friday, February 23, 2018
  • by roippi
  • Repository
  • 11 Watchers
  • 53 Stars
  • 22,064 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 7 Forks
  • 0 Open issues
  • 8 Versions
  • 16 % Grown

The README.md

Hypernova-PHP Build Status

PHP client for your Hypernova service., (*1)

Why Hypernova?

The broader question tends to be "how do I Server-Side Render my React app?" You may have this as a business requirement (e.g. SEO) or just want to give users the fastest initial render possible., (*2)

Assuming you have a PHP backend (why are you here, otherwise?), generally you will want to stand up a node.js service to do the rendering for you. You could try phpv8js but I believe it is contraindicated for production use at any scale. That's just my opinion, do your own research :grin:, (*3)

So then - write your own node.js service, or use one off the shelf. Writing your own node.js service isn't terrifically hard - you could reasonably stand up a thing that would render react components for you in ~20 lines of code. We personally went with hypernova because it's lightweight, pluggable (see the plugin system), performant (see the clever bytecode caching in createVM), and has nice client-side fallback behavior in case the service has issues., (*4)

Getting Started

composer require wayfair/hypernova-php, (*5)

Make a Renderer:, (*6)

use \WF\Hypernova\Renderer;

$renderer = new Renderer('http://localhost:3030/batch');

Give it some work:, (*7)

$renderer->addJob('myViewId', ['name' => 'my_module_name', 'data' => ['some' => ['props']]]);

Optionally add a plugin or two (see plugin section):, (*8)

$renderer->addPlugin($myPlugin);
$renderer->addPlugin($myOtherPlugin);

Then go get your rendered Response:, (*9)

$response = $renderer->render();

echo $response->results['myViewId']->html;

Plugin API

This is how you customize client behavior. Common usecases include:, (*10)

  • Logging request metadata like performance timings
  • Error logging
  • Injecting/removing props
  • Inlining stack traces in development environments
  • Stopping requests to the service entirely, letting everything fall back to client rendering

Generally, you will want to implement some subset of the lifecycle hooks; maybe you want onError handling but have no need for shouldSendRequest. For developer convenience, you may extend \WF\Hypernova\Plugin\BasePlugin which provides no-op implementations of all of the hooks., (*11)

See the js client docs for full descriptions of the available hooks., (*12)

Contributing:

Fork it, submit a PR., (*13)

Run tests:

composer test, (*14)

The Versions

23/02 2018

dev-guzzle_5_backport

dev-guzzle_5_backport

A PHP client for hypernova. https://github.com/airbnb/hypernova

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

react hypernova wayfair

23/02 2018

dev-master

9999999-dev

A PHP client for hypernova. https://github.com/airbnb/hypernova

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

react hypernova wayfair

23/02 2018

v2.0.1

2.0.1.0

A PHP client for hypernova. https://github.com/airbnb/hypernova

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

react hypernova wayfair

23/02 2018

v2.0

2.0.0.0

A PHP client for hypernova. https://github.com/airbnb/hypernova

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

react hypernova wayfair

19/10 2017

v1.2

1.2.0.0

A PHP client for hypernova. https://github.com/airbnb/hypernova

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

react hypernova wayfair

21/01 2017

v1.1

1.1.0.0

A PHP client for hypernova. https://github.com/airbnb/hypernova

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

react hypernova wayfair

21/01 2017

dev-more_jobresult_fields

dev-more_jobresult_fields

A PHP client for hypernova. https://github.com/airbnb/hypernova

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

react hypernova wayfair

20/01 2017

v1.0

1.0.0.0

A PHP client for hypernova. https://github.com/airbnb/hypernova

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

react hypernova wayfair