Skip to content
This repository was archived by the owner on Mar 29, 2024. It is now read-only.

Commit d2ebdcc

Browse files
authored
Merge pull request #1 from pinepain/wip-public-release
Initial public release
2 parents 45ee302 + e558af5 commit d2ebdcc

File tree

164 files changed

+9363
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+9363
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor
2+
composer.lock

.scrutinizer.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
build:
2+
dependencies:
3+
before:
4+
- sudo apt-get install -y software-properties-common
5+
- sudo add-apt-repository ppa:pinepain/libv8-6.3
6+
- sudo apt-get update
7+
- sudo apt-get install -y libv8-6.3 libv8-6.3-dev libv8-6.3-dbg
8+
- pecl install v8
9+
- pecl install ref
10+
11+
checks:
12+
php:
13+
code_rating: true
14+
duplication: true
15+
filter:
16+
excluded_paths:
17+
- "vendor/"
18+
- "tests/"
19+
tools:
20+
external_code_coverage: true

.travis.yml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
sudo: false
2+
3+
language: php
4+
5+
cache:
6+
directories:
7+
- $HOME/.composer/cache
8+
- $HOME/.build
9+
- $HOME/.ccache
10+
11+
php:
12+
- 7.1
13+
- 7.2
14+
- nightly
15+
16+
matrix:
17+
allow_failures:
18+
- php: nightly
19+
20+
env:
21+
- PHP_V8=v0.2.0
22+
PHP_REF=v0.5.0
23+
24+
addons:
25+
apt:
26+
sources:
27+
- sourceline: ppa:pinepain/libv8-6.3
28+
packages:
29+
- libv8-6.3
30+
- libv8-6.3-dev
31+
- libv8-6.3-dbg
32+
- ccache
33+
34+
before_install:
35+
- pwd
36+
- env
37+
- export PATH="/usr/lib/ccache:$PATH"
38+
- if [ ! -d "$HOME/.build/php-v8" ]; then cd $HOME/.build && git clone git://github.com/pinepain/php-v8.git; else cd $HOME/.build/php-v8 && git fetch; fi
39+
- cd $HOME/.build/php-v8 && git checkout $PHP_V8
40+
- if [ ! -d "$HOME/.build/php-ref" ]; then cd $HOME/.build && git clone git://github.com/pinepain/php-ref.git; else cd $HOME/.build/php-ref && git fetch; fi
41+
- cd $HOME/.build/php-ref && git checkout $PHP_REF
42+
43+
install:
44+
- cd $HOME/.build/php-v8 && phpize && ./configure && make install && make clean && phpize --clean && cd $TRAVIS_BUILD_DIR
45+
- echo "extension=v8.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
46+
- cd $HOME/.build/php-ref && phpize && ./configure && make install && make clean && phpize --clean && cd $TRAVIS_BUILD_DIR
47+
- echo "extension=ref.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
48+
- php --ri v8
49+
- php --ri ref
50+
- ccache -s
51+
52+
before_script:
53+
- composer install
54+
55+
script:
56+
- vendor/bin/phpstan analyse -c phpstan.neon --level 7 src || true
57+
- vendor/bin/phpunit --coverage-text --configuration phpunit.xml --coverage-clover=coverage.clover
58+
59+
after_script:
60+
- if [ "nightly" != "${TRAVIS_PHP_VERSION}" ]; then
61+
wget https://scrutinizer-ci.com/ocular.phar &&
62+
php ocular.phar code-coverage:upload --format=php-clover coverage.clover;
63+
fi

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Embedding JavaScript in PHP made easy
2+
3+
4+
[![Build Status](https://travis-ci.org/pinepain/js-sandbox.svg?branch=master)](https://travis-ci.org/pinepain/js-sandbox)
5+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/pinepain/js-sandbox/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/pinepain/js-sandbox/?branch=master)
6+
[![Code Coverage](https://scrutinizer-ci.com/g/pinepain/js-sandbox/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/pinepain/js-sandbox/?branch=master)
7+
8+
**The definitive library for [pinepain/php-v8](https://github.com/pinepain/php-v8) extension**
9+
10+
Thi library provides high-level abstraction on top of [php-v8](https://github.com/pinepain/php-v8) extension and makes
11+
embedding JavaScript in PHP easier.
12+
13+
**This library is still under heavy development and its public API may change without any warning. Use at your own risk.**
14+
15+
### PLEASE READ:
16+
17+
Maintaining this project takes significant amount of time and efforts.
18+
If you like my work and want to show your appreciation, please consider supporting me at https://www.patreon.com/pinepain.
19+
20+
## Installation
21+
22+
```
23+
composer require pinepain/js-sandbox
24+
```
25+
26+
## License
27+
28+
Copyright (c) 2016-2017 Bogdan Padalko <[email protected]>
29+
30+
[js-sandbox](https://github.com/pinepain/js-sandbox) PHP library is licensed under the [MIT license](http://opensource.org/licenses/MIT).

composer.json

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "pinepain/js-sandbox",
3+
"type": "library",
4+
"description": "Embedding JavaScript in PHP made easy: the definitive library for pinepain/php-v8 extension",
5+
"keywords": ["php-v8", "v8", "js", "javascript", "sandbox", "embedding"],
6+
"homepage": "https://github.com/pinepain/js-sandbox",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Bogdan Padalko",
11+
"email": "[email protected]",
12+
"homepage": "https://github.com/pinepain"
13+
}
14+
],
15+
"require": {
16+
"php": "~7.1",
17+
"league/flysystem": "^1.0",
18+
"pinepain/php-object-maps": "^0.3.0"
19+
},
20+
"require-dev": {
21+
"illuminate/support": "5.5.*",
22+
"illuminate/contracts": "5.5.*",
23+
"phpunit/phpunit": "~6.3",
24+
"pinepain/php-v8-stubs": "^0.2.0",
25+
"pinepain/php-ref-stubs": "^0.5.0",
26+
"phpstan/phpstan": "^0.8.5"
27+
},
28+
"autoload": {
29+
"psr-4": {
30+
"Pinepain\\JsSandbox\\": "src/"
31+
}
32+
},
33+
"autoload-dev": {
34+
"psr-4": {
35+
"Pinepain\\JsSandbox\\Tests\\": "tests/"
36+
}
37+
}
38+
}

phpstan.neon

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
parameters:
2+
ignoreErrors:
3+
- '#Method Illuminate\\Contracts\\Foundation\\Application::environment\(\) invoked with 1 parameter, 0 required\.#'

phpunit.xml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
processIsolation="false"
9+
stopOnFailure="false"
10+
syntaxCheck="false">
11+
<testsuites>
12+
<testsuite name="Test Suite">
13+
<directory suffix="Test.php">./tests</directory>
14+
</testsuite>
15+
</testsuites>
16+
<filter>
17+
<whitelist processUncoveredFilesFromWhitelist="true">
18+
<directory suffix=".php">./src</directory>
19+
</whitelist>
20+
</filter>
21+
</phpunit>

src/Exceptions/Exception.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of the pinepain/js-sandbox PHP library.
5+
*
6+
* Copyright (c) 2016-2017 Bogdan Padalko <[email protected]>
7+
*
8+
* Licensed under the MIT license: http://opensource.org/licenses/MIT
9+
*
10+
* For the full copyright and license information, please view the
11+
* LICENSE file that was distributed with this source or visit
12+
* http://opensource.org/licenses/MIT
13+
*/
14+
15+
16+
namespace Pinepain\JsSandbox\Exceptions;
17+
18+
19+
class Exception extends \Exception
20+
{
21+
}

src/Exceptions/NativeException.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of the pinepain/js-sandbox PHP library.
5+
*
6+
* Copyright (c) 2016-2017 Bogdan Padalko <[email protected]>
7+
*
8+
* Licensed under the MIT license: http://opensource.org/licenses/MIT
9+
*
10+
* For the full copyright and license information, please view the
11+
* LICENSE file that was distributed with this source or visit
12+
* http://opensource.org/licenses/MIT
13+
*/
14+
15+
16+
namespace Pinepain\JsSandbox\Exceptions;
17+
18+
19+
class NativeException extends Exception
20+
{
21+
}

src/Exceptions/SandboxException.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of the pinepain/js-sandbox PHP library.
5+
*
6+
* Copyright (c) 2016-2017 Bogdan Padalko <[email protected]>
7+
*
8+
* Licensed under the MIT license: http://opensource.org/licenses/MIT
9+
*
10+
* For the full copyright and license information, please view the
11+
* LICENSE file that was distributed with this source or visit
12+
* http://opensource.org/licenses/MIT
13+
*/
14+
15+
16+
namespace Pinepain\JsSandbox\Exceptions;
17+
18+
19+
class SandboxException extends Exception
20+
{
21+
}

src/Executor.php

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of the pinepain/js-sandbox PHP library.
5+
*
6+
* Copyright (c) 2016-2017 Bogdan Padalko <[email protected]>
7+
*
8+
* Licensed under the MIT license: http://opensource.org/licenses/MIT
9+
*
10+
* For the full copyright and license information, please view the
11+
* LICENSE file that was distributed with this source or visit
12+
* http://opensource.org/licenses/MIT
13+
*/
14+
15+
16+
namespace Pinepain\JsSandbox;
17+
18+
19+
use Pinepain\JsSandbox\Executors\ExecutorInterface;
20+
use V8\Context;
21+
use V8\Value;
22+
23+
24+
class Executor
25+
{
26+
/**
27+
* @var Context
28+
*/
29+
private $context;
30+
/**
31+
* @var ExecutorInterface
32+
*/
33+
private $string;
34+
/**
35+
* @var ExecutorInterface
36+
*/
37+
private $file;
38+
39+
/**
40+
* @param Context $context
41+
* @param ExecutorInterface $string
42+
* @param ExecutorInterface $file
43+
*
44+
*/
45+
public function __construct(Context $context, ExecutorInterface $string, ExecutorInterface $file)
46+
{
47+
$this->context = $context;
48+
$this->string = $string;
49+
$this->file = $file;
50+
}
51+
52+
/**
53+
* @param string $string
54+
*
55+
* @return Value
56+
*/
57+
public function executeString(string $string): Value
58+
{
59+
return $this->string->execute($this->context->getIsolate(), $this->context, $string);
60+
}
61+
62+
/**
63+
* @param string $path
64+
*
65+
* @return Value
66+
*/
67+
public function execute(string $path): Value
68+
{
69+
return $this->file->execute($this->context->getIsolate(), $this->context, $path);
70+
}
71+
}

src/Executors/ExecutorInterface.php

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of the pinepain/js-sandbox PHP library.
5+
*
6+
* Copyright (c) 2016-2017 Bogdan Padalko <[email protected]>
7+
*
8+
* Licensed under the MIT license: http://opensource.org/licenses/MIT
9+
*
10+
* For the full copyright and license information, please view the
11+
* LICENSE file that was distributed with this source or visit
12+
* http://opensource.org/licenses/MIT
13+
*/
14+
15+
16+
namespace Pinepain\JsSandbox\Executors;
17+
18+
19+
use V8\Context;
20+
use V8\Isolate;
21+
use V8\Value;
22+
23+
24+
interface ExecutorInterface
25+
{
26+
/**
27+
* @param Isolate $isolate
28+
* @param Context $context
29+
* @param string $value
30+
*
31+
* @return Value
32+
*/
33+
public function execute(Isolate $isolate, Context $context, string $value): Value;
34+
}

0 commit comments

Comments
 (0)