JsonSchemaModule::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 12
rs 9.9332
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Resource\Module;
6
7
use BEAR\Resource\Annotation\JsonSchema;
8
use BEAR\Resource\Interceptor\JsonSchemaInterceptor;
9
use BEAR\Resource\Interceptor\JsonSchemaInterceptorInterface;
10
use BEAR\Resource\JsonSchemaExceptionHandlerInterface;
11
use BEAR\Resource\JsonSchemaExceptionNullHandler;
12
use BEAR\Resource\JsonSchemaRequestExceptionHandlerInterface;
13
use BEAR\Resource\JsonSchemaRequestExceptionNullHandler;
14
use BEAR\Resource\ResourceObject;
15
use Override;
16
use Ray\Di\AbstractModule;
17
18
final class JsonSchemaModule extends AbstractModule
19
{
20
    /**
21
     * @param string $jsonSchemaDir   Json-schema json file directory
22
     * @param string $jsonValidateDir Json-schema validator json file directory
23
     */
24
    public function __construct(
25
        private readonly string $jsonSchemaDir = '',
26
        private readonly string $jsonValidateDir = '',
27
        AbstractModule|null $module = null,
28
    ) {
29
        parent::__construct($module);
30
    }
31
32
    /**
33
     * {@inheritDoc}
34
     */
35
    #[Override]
36
    protected function configure(): void
37
    {
38
        $this->bind()->annotatedWith('json_schema_dir')->toInstance($this->jsonSchemaDir);
39
        $this->bind()->annotatedWith('json_validate_dir')->toInstance($this->jsonValidateDir);
40
        $this->bind(JsonSchemaExceptionHandlerInterface::class)->to(JsonSchemaExceptionNullHandler::class);
41
        $this->bind(JsonSchemaRequestExceptionHandlerInterface::class)->to(JsonSchemaRequestExceptionNullHandler::class);
42
        $this->bind(JsonSchemaInterceptorInterface::class)->to(JsonSchemaInterceptor::class);
43
        $this->bindInterceptor(
44
            $this->matcher->subclassesOf(ResourceObject::class),
45
            $this->matcher->annotatedWith(JsonSchema::class),
46
            [JsonSchemaInterceptorInterface::class],
47
        );
48
    }
49
}
50