Git Product home page Git Product logo

vrzno's Introduction

What is VRZNO?

(/vərəˈzɑːnoʊ/ | vər-ə-ZAH-noh )

VRZNO is a bridge between Javascript & PHP in an extremely nontraditional sense.

  • VRZNO lets you call javascript code from PHP.
  • VRZNO is a statically compiled PHP module.
  • VRZNO runs in-browser, nodeJS and cloudflare.

Contents

How is this possible?

VRZNO is the first PHP extension built for php-wasm. Once its compiled with PHP, it can be served to any browser and executed client side. It can also run in NodeJS and CloudFlare workers.

https://github.com/seanmorris/php-wasm

PDO D1 SQL Connector (Cloudflare)

You can connect to a D1 database inside cloudflare with PDO.

In javascript, just pass the DB object into the contructor (note that Cloudflare workers use PhpWeb. not PhpNode.)

const php = new PhpWeb({ db: context.env.db });

In PHP, just import that object through vrzno_env, take the target ID with vrzno_target and append it to vrzno:. Thats it, that's your whole connection string.

$pdo = new PDO('vrzno:' . vrzno_target(vrzno_env('db')));

PDO can now be used as normal:

$select = $pdo->prepare('SELECT PageTitle, PageContent FROM WikiPages WHERE PageTitle = ?');
$select->execute([$pageTitle]);
$page = $select->fetchObject();

PHP API

new Vrzno()

Creates a new Vrzno object that holds a reference to JavaScript's globalThis object.

vrzno_import()

Import a javascript library asyncronously. This is the PHP equivalent of JavaScript's dynamic import().

$import = vrzno_import('https://cdn.jsdelivr.net/npm/@observablehq/[email protected]/+esm');

See a demo: https://codepen.io/SeanMorris227/pen/LYqNNrE

<script async type = "text/javascript" src = "https://cdn.jsdelivr.net/npm/php-wasm/php-tags.mjs"></script>

<script type = "text/php" data-stdout = "#out" data-stderr = "#err">
<?php
  $window = new Vrzno;
  $import = vrzno_import('https://cdn.jsdelivr.net/npm/@observablehq/[email protected]/+esm');
  $import->then(function($Plot) use($window) {
  $plot = $Plot->rectY(
    (object)['length' => 100000],
    $Plot->binX(
      (object)['y'=> function($a,$b){
        return -cos($b->x1*pi());
      }],
      (object)['x'=> $window->Math->random]
    )
  )->plot();

  $window->document->body->append($plot);

  })->catch(fn($error) => $window->console->error($error->message));

</script>

<pre id = "out"></pre>
<pre id = "err"></pre>

vrzno_env()

Takes a string, and returns an object passed into the PHP Object's constructor.

For example, if you invoke PhpNode like this in JavaScript:

import { PhpNode } from './PhpNode.mjs';
import gi from 'node-gtk';
const Gtk = gi.require('Gtk', '3.0');
const WebKit2 = gi.require('WebKit2');

const php = new PhpNode({Gtk, gi, WebKit2});

You can access those values in PHP like so:

<?php
$gi  = vrzno_env('gi');
$Gtk = vrzno_env('Gtk');
$WebKit2 = vrzno_env('WebKit2');

vrzno_target()

Get the targetId as an integer from a Vrzno object.

vrzno_await()

Wait on a Promise-like object to resolve within PHP before proceeding with the script. This will pause execution of PHP in the same way the await keyword will when used in JavaScript.

vrzno's People

Contributors

seanmorris avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.