2017 © Pedro Peláez
 

library v8

Helper library for the php-v8 extension

image

psx/v8

Helper library for the php-v8 extension

  • Friday, May 26, 2017
  • by k42b3
  • Repository
  • 1 Watchers
  • 1 Stars
  • 7,988 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 8 Versions
  • 13 % Grown

The README.md

V8

About

This is a small helper library which simplifies working with the PHP V8 extension (https://github.com/pinepain/php-v8). It adds small wrapper classes which help with the type juggling between PHP and the V8 environment., (*1)

Usage

<?php

$script = <<<JS

var message = 'Hello ' + console.foo;

resp = {
    message: console.log(message),
    bar: function(data){
        return 'Foo ' + data;
    },
    foo: 'bar'
};

JS;

$environment = new \PSX\V8\Environment();

$environment->set('console', [
    'foo' => 'foo',
    'log' => function($value){
         return $value . ' and bar';
    }
]);

$environment->run($script);

$resp = $environment->get('resp');

echo $resp->get('message') . "\n"; // Hello foo and bar
echo $resp->get('bar')(['test']) . "\n"; // Foo test
echo $resp->get('foo') . "\n"; // bar

Objects

It is also possible to expose complete PHP classes to the V8 engine. Therefor the class has to implement the PSX\V8\ObjectInterface interface. There is also a PSX\V8\ReflectionObject object which automatically exposes all public properties and methods. The javascript defined above would also work with the following environment:, (*2)

<?php

class Console
{
    public $foo;

    public function __construct()
    {
        $this->foo = 'foo';
    }

    public function log($value)
    {
        return $value . ' and bar';
    }
}

$console = new Console();

$environment = new \PSX\V8\Environment();
$environment->set('console', new \PSX\V8\Object\ReflectionObject($console));
$environment->run($script);

$resp = $environment->get('resp');

Build Status, (*3)

The Versions

26/05 2017

dev-master

9999999-dev http://phpsx.org

Helper library for the php-v8 extension

  Sources   Download

Apache-2.0

The Requires

  • php >=5.6

 

The Development Requires

v8

26/05 2017

v0.2.0

0.2.0.0 http://phpsx.org

Helper library for the php-v8 extension

  Sources   Download

Apache-2.0

The Requires

  • php >=5.6

 

The Development Requires

v8

19/02 2017

v0.1.5

0.1.5.0 http://phpsx.org

Helper library for the php-v8 extension

  Sources   Download

Apache-2.0

The Requires

  • php >=5.5

 

The Development Requires

v8

10/02 2017

v0.1.4

0.1.4.0 http://phpsx.org

Helper library for the php-v8 extension

  Sources   Download

Apache-2.0

The Requires

  • php >=5.5

 

The Development Requires

v8

04/02 2017

v0.1.3

0.1.3.0 http://phpsx.org

Helper library for the php-v8 extension

  Sources   Download

Apache-2.0

The Requires

  • php >=5.5

 

The Development Requires

v8

13/11 2016

v0.1.2

0.1.2.0 http://phpsx.org

Helper library for the php-v8 extension

  Sources   Download

Apache-2.0

The Requires

  • php >=5.5

 

The Development Requires

v8

04/11 2016

v0.1.1

0.1.1.0 http://phpsx.org

Helper library for the php-v8 extension

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0

 

The Development Requires

v8

20/09 2016

v0.1.0

0.1.0.0 http://phpsx.org

Helper library for the php-v8 extension

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0

 

The Development Requires

v8