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\Laravel; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
use Illuminate\Contracts\Container\Container; |
20
|
|
|
use Illuminate\Support\ServiceProvider; |
21
|
|
|
use Pinepain\JsSandbox\Executor; |
22
|
|
|
use Pinepain\JsSandbox\Executors\ModulesNativeExecutor; |
23
|
|
|
use Pinepain\JsSandbox\Executors\StringExecutor; |
24
|
|
|
use V8\Context; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
class JsSandboxExecutorServiceProvider extends ServiceProvider |
28
|
|
|
{ |
29
|
|
|
protected $defer = false; |
30
|
|
|
|
31
|
|
|
public function register() |
32
|
|
|
{ |
33
|
|
|
$this->app->singleton(StringExecutor::class); |
34
|
|
|
// TODO: if config('js_sandbox.modules_enabled') - with modules, without otherwise |
35
|
|
|
$this->app->singleton(ModulesNativeExecutor::class); // TODO: register native require function |
36
|
|
|
|
37
|
|
|
$this->app->singleton(Executor::class, function (Container $app) { |
38
|
|
|
$context = $app->make(Context::class); |
39
|
|
|
$string = $app->make(StringExecutor::class); |
40
|
|
|
$module = $app->make(ModulesNativeExecutor::class); |
41
|
|
|
|
42
|
|
|
return new Executor($context, $string, $module); |
43
|
|
|
}); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function provides() |
47
|
|
|
{ |
48
|
|
|
return [ |
49
|
|
|
StringExecutor::class, |
50
|
|
|
ModulesNativeExecutor::class, |
51
|
|
|
Executor::class, |
52
|
|
|
]; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|