Issues (2884)

src/Di/Traits/PluginTrait.php (2 issues)

1
<?php
2
3
namespace Jaxon\Di\Traits;
4
5
use Jaxon\Jaxon;
6
use Jaxon\App\Config\ConfigManager;
7
use Jaxon\App\Dialog\Library\DialogLibraryManager;
8
use Jaxon\App\I18n\Translator;
9
use Jaxon\App\View\ViewRenderer;
10
use Jaxon\Di\Container;
11
use Jaxon\Plugin\Code\AssetManager;
12
use Jaxon\Plugin\Code\CodeGenerator;
13
use Jaxon\Plugin\Code\MinifierInterface;
14
use Jaxon\Plugin\Manager\PackageManager;
15
use Jaxon\Plugin\Manager\PluginManager;
16
use Jaxon\Plugin\Response\DataBag\DataBagPlugin;
17
use Jaxon\Plugin\Response\Dialog\DialogPlugin;
18
use Jaxon\Plugin\Response\JQuery\JQueryPlugin;
19
use Jaxon\Request\Handler\CallbackManager;
20
use Jaxon\Request\Handler\ParameterReader;
21
use Jaxon\Utils\File\FileMinifier;
22
use Jaxon\Utils\Template\TemplateEngine;
23
24
trait PluginTrait
25
{
26
    /**
27
     * Register the values into the container
28
     *
29
     * @return void
30
     */
31
    private function registerPlugins()
32
    {
33
        // Plugin manager
34
        $this->set(PluginManager::class, function($di) {
0 ignored issues
show
It seems like set() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
        $this->/** @scrutinizer ignore-call */ 
35
               set(PluginManager::class, function($di) {
Loading history...
35
            return new PluginManager($di->g(Container::class),
36
                $di->g(CodeGenerator::class), $di->g(Translator::class));
37
        });
38
        // Package manager
39
        $this->set(PackageManager::class, function($di) {
40
            return new PackageManager($di->g(Container::class), $di->g(PluginManager::class),
41
                $di->g(ConfigManager::class), $di->g(CallbackManager::class),
42
                $di->g(CodeGenerator::class), $di->g(ViewRenderer::class), $di->g(Translator::class));
43
        });
44
        // Code Generation
45
        $this->set(MinifierInterface::class, function() {
46
            return new class extends FileMinifier implements MinifierInterface
47
            {};
48
        });
49
        $this->set(AssetManager::class, function($di) {
50
            return new AssetManager($di->g(ConfigManager::class), $di->g(ParameterReader::class),
51
                $di->g(MinifierInterface::class));
52
        });
53
        $this->set(CodeGenerator::class, function($di) {
54
            return new CodeGenerator(Jaxon::VERSION, $di->g(Container::class), $di->g(TemplateEngine::class));
55
        });
56
57
        // JQuery response plugin
58
        $this->set(JQueryPlugin::class, function($di) {
59
            $jQueryNs = $di->g(ConfigManager::class)->getOption('core.jquery.no_conflict', false) ? 'jQuery' : '$';
60
            return new JQueryPlugin($jQueryNs);
61
        });
62
        // DataBag response plugin
63
        $this->set(DataBagPlugin::class, function($di) {
64
            return new DataBagPlugin($di->g(Container::class));
65
        });
66
        // Dialog response plugin
67
        $this->set(DialogPlugin::class, function($di) {
68
            return new DialogPlugin($di->g(DialogLibraryManager::class));
69
        });
70
    }
71
72
    /**
73
     * Get the plugin manager
74
     *
75
     * @return PluginManager
76
     */
77
    public function getPluginManager(): PluginManager
78
    {
79
        return $this->g(PluginManager::class);
0 ignored issues
show
It seems like g() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

79
        return $this->/** @scrutinizer ignore-call */ g(PluginManager::class);
Loading history...
80
    }
81
82
    /**
83
     * Get the package manager
84
     *
85
     * @return PackageManager
86
     */
87
    public function getPackageManager(): PackageManager
88
    {
89
        return $this->g(PackageManager::class);
90
    }
91
92
    /**
93
     * Get the code generator
94
     *
95
     * @return CodeGenerator
96
     */
97
    public function getCodeGenerator(): CodeGenerator
98
    {
99
        return $this->g(CodeGenerator::class);
100
    }
101
102
    /**
103
     * Get the asset manager
104
     *
105
     * @return AssetManager
106
     */
107
    public function getAssetManager(): AssetManager
108
    {
109
        return $this->g(AssetManager::class);
110
    }
111
112
    /**
113
     * Get the jQuery plugin
114
     *
115
     * @return JQueryPlugin
116
     */
117
    public function getJQueryPlugin(): JQueryPlugin
118
    {
119
        return $this->g(JQueryPlugin::class);
120
    }
121
122
    /**
123
     * Get the dialog plugin
124
     *
125
     * @return DialogPlugin
126
     */
127
    public function getDialogPlugin(): DialogPlugin
128
    {
129
        return $this->g(DialogPlugin::class);
130
    }
131
}
132