Passed
Push — master ( d2ebdc...958928 )
by Bogdan
05:05
created

JsSandboxExecutorServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 28
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 14 1
A provides() 0 8 1
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