RequestTrait::getUploadHandler()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Jaxon\Di\Traits;
4
5
use Jaxon\App\Config\ConfigManager;
6
use Jaxon\App\I18n\Translator;
7
use Jaxon\Di\ClassContainer;
8
use Jaxon\Di\Container;
9
use Jaxon\Script\Factory\CallFactory;
10
use Jaxon\Script\Factory\ParameterFactory;
11
use Jaxon\Plugin\Manager\PluginManager;
12
use Jaxon\Plugin\Response\DataBag\DataBagPlugin;
13
use Jaxon\Plugin\Response\Dialog\DialogCommand;
14
use Jaxon\Request\Handler\CallbackManager;
15
use Jaxon\Request\Handler\ParameterReader;
16
use Jaxon\Request\Handler\RequestHandler;
17
use Jaxon\Request\Upload\UploadHandlerInterface;
18
use Jaxon\Response\ResponseManager;
19
use Jaxon\Utils\Http\UriDetector;
20
21
trait RequestTrait
22
{
23
    /**
24
     * Register the values into the container
25
     *
26
     * @return void
27
     */
28
    private function registerRequests()
29
    {
30
        // The parameter reader
31
        $this->set(ParameterReader::class, function($di) {
0 ignored issues
show
Bug introduced by
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

31
        $this->/** @scrutinizer ignore-call */ 
32
               set(ParameterReader::class, function($di) {
Loading history...
32
            return new ParameterReader($di->g(Container::class), $di->g(Translator::class),
33
                $di->g(ConfigManager::class), $di->g(UriDetector::class));
34
        });
35
        // Callback Manager
36
        $this->set(CallbackManager::class, function($di) {
37
            return new CallbackManager($di->g(ResponseManager::class));
38
        });
39
        // By default, register a null upload handler
40
        $this->set(UploadHandlerInterface::class, function() {
41
            return null;
42
        });
43
        // Request Handler
44
        $this->set(RequestHandler::class, function($di) {
45
            return new RequestHandler($di->g(Container::class), $di->g(PluginManager::class),
46
                $di->g(ResponseManager::class), $di->g(CallbackManager::class),
47
                $di->g(DataBagPlugin::class));
48
        });
49
        // Requests and calls Factory
50
        $this->set(CallFactory::class, function($di) {
51
            return new CallFactory($di->g(ClassContainer::class), $di->g(DialogCommand::class));
52
        });
53
        // Factory for function parameters
54
        $this->set(ParameterFactory::class, function() {
55
            return new ParameterFactory();
56
        });
57
    }
58
59
    /**
60
     * Get the js call factory
61
     *
62
     * @return CallFactory
63
     */
64
    public function getCallFactory(): CallFactory
65
    {
66
        return $this->g(CallFactory::class);
0 ignored issues
show
Bug introduced by
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

66
        return $this->/** @scrutinizer ignore-call */ g(CallFactory::class);
Loading history...
67
    }
68
69
    /**
70
     * Get the js call parameter factory
71
     *
72
     * @return ParameterFactory
73
     */
74
    public function getParameterFactory(): ParameterFactory
75
    {
76
        return $this->g(ParameterFactory::class);
77
    }
78
79
    /**
80
     * Get the request handler
81
     *
82
     * @return RequestHandler
83
     */
84
    public function getRequestHandler(): RequestHandler
85
    {
86
        return $this->g(RequestHandler::class);
87
    }
88
89
    /**
90
     * Get the upload handler
91
     *
92
     * @return UploadHandlerInterface|null
93
     */
94
    public function getUploadHandler(): ?UploadHandlerInterface
95
    {
96
        return $this->g(UploadHandlerInterface::class);
97
    }
98
99
    /**
100
     * Get the callback manager
101
     *
102
     * @return CallbackManager
103
     */
104
    public function getCallbackManager(): CallbackManager
105
    {
106
        return $this->g(CallbackManager::class);
107
    }
108
109
    /**
110
     * Get the parameter reader
111
     *
112
     * @return ParameterReader
113
     */
114
    public function getParameterReader(): ParameterReader
115
    {
116
        return $this->g(ParameterReader::class);
117
    }
118
}
119