JsSandboxModulesServiceProvider::provides()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
c 0
b 0
f 0
ccs 0
cts 2
cp 0
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
crap 2
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\Common\NativeGlobalObjectWrapper;
22
use Pinepain\JsSandbox\Common\NativeGlobalObjectWrapperInterface;
23
use Pinepain\JsSandbox\Modules\ModulesCache;
24
use Pinepain\JsSandbox\Modules\ModulesCacheInterface;
25
use Pinepain\JsSandbox\Modules\ModulesService;
26
use Pinepain\JsSandbox\Modules\ModulesStack;
27
use Pinepain\JsSandbox\Modules\ModulesStackInterface;
28
use Pinepain\JsSandbox\Modules\NativeRequireFunctionWrapperInterface;
29
use Pinepain\JsSandbox\Modules\Repositories\NativeModulesRepository;
30
use Pinepain\JsSandbox\Modules\Repositories\NativeModulesRepositoryInterface;
31
use Pinepain\JsSandbox\Modules\Repositories\SourceModulesRepository;
32
use Pinepain\JsSandbox\Modules\Repositories\SourceModulesRepositoryInterface;
33
use Pinepain\JsSandbox\Modules\RequireCallback;
34
use Pinepain\JsSandbox\Modules\RequireCallbackInterface;
35
use Pinepain\JsSandbox\Specs\ObjectSpecsCollectionInterface;
36
use Pinepain\JsSandbox\Wrappers\WrapperInterface;
37
use V8\Context;
38
use V8\Isolate;
39
40
41
class JsSandboxModulesServiceProvider extends ServiceProvider
42
{
43
    protected $defer = true;
44
45
    public function register()
46
    {
47
        $this->app->singleton(ModulesCacheInterface::class, ModulesCache::class);
48
        $this->app->singleton(ModulesStackInterface::class, ModulesStack::class);
49
50
        $this->app->singleton(NativeModulesRepositoryInterface::class, NativeModulesRepository::class);
51
        // NOTE: to resolve specific FilesystemInterface for SourceModulesRepository you may need to write rule. e.g.:
52
        // $this->app->when(JsSandboxModulesServiceProvider::class)
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
53
        //           ->needs(FilesystemInterface::class)
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
54
        //           ->give(...);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
55
        // or default implementation for FilesystemInterface would we set, which may not be exactly what you want
56
        $this->app->singleton(SourceModulesRepositoryInterface::class, SourceModulesRepository::class);
57
58
        $this->app->singleton(RequireCallbackInterface::class, RequireCallback::class);
59
60
61
        $this->app->singleton(NativeRequireFunctionWrapperInterface::class, function (Container $app) {
62
63
            $service = $app->make(ModulesService::class);
64
65
            $service->registerObjectSpecs($app->make(ObjectSpecsCollectionInterface::class));
66
67
            return $service->createNativeFunctionWrapper(
68
                $app->make(Context::class),
69
                $app->make(RequireCallbackInterface::class),
70
                $app->make(WrapperInterface::class)
71
            );
72
        });
73
74
    }
75
76
    public function provides()
77
    {
78
        return [
79
            ModulesCacheInterface::class,
80
            ModulesStackInterface::class,
81
82
            NativeModulesRepositoryInterface::class,
83
            SourceModulesRepositoryInterface::class,
84
85
            RequireCallbackInterface::class,
86
            NativeRequireFunctionWrapperInterface::class,
87
88
        ];
89
    }
90
}
91