• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eliashaeussler / typo3-config-objects / 14489654786

16 Apr 2025 09:41AM UTC coverage: 67.55% (-32.5%) from 100.0%
14489654786

Pull #1

github

eliashaeussler
[FEATURE] Add configuration object for request middlewares
Pull Request #1: [FEATURE] Add configuration object for request middlewares

0 of 49 new or added lines in 2 files covered. (0.0%)

102 of 151 relevant lines covered (67.55%)

2.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/ValueObject/RequestMiddleware.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Composer package "eliashaeussler/typo3-config-objects".
7
 *
8
 * Copyright (C) 2025 Elias Häußler <elias@haeussler.dev>
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation, either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23

24
namespace EliasHaeussler\Typo3ConfigObjects\ValueObject;
25

26
use EliasHaeussler\Typo3ConfigObjects\Contracts;
27
use Psr\Http\Server;
28

29
/**
30
 * RequestMiddleware.
31
 *
32
 * @author Elias Häußler <elias@haeussler.dev>
33
 * @license GPL-2.0-or-later
34
 *
35
 * @phpstan-type MiddlewareOptions array{
36
 *     target: class-string<Server\MiddlewareInterface>,
37
 *     disabled?: bool,
38
 *     before?: list<non-empty-string>,
39
 *     after?: list<non-empty-string>,
40
 * }
41
 *
42
 * @implements Contracts\Arrayable<MiddlewareOptions>
43
 */
44
final class RequestMiddleware implements Contracts\Arrayable
45
{
46
    private bool $disabled = false;
47

48
    /**
49
     * @var array{before: list<non-empty-string>, after: list<non-empty-string>}
50
     */
51
    private array $dependencies = [
52
        'before' => [],
53
        'after' => [],
54
    ];
55

56
    /**
57
     * @param non-empty-string                         $name
58
     * @param class-string<Server\MiddlewareInterface> $target
59
     */
NEW
60
    public function __construct(
×
61
        public readonly string $name,
62
        private string $target,
NEW
63
    ) {}
×
64

65
    /**
66
     * @param non-empty-string                         $name
67
     * @param class-string<Server\MiddlewareInterface> $target
68
     */
NEW
69
    public static function create(string $name, string $target): self
×
70
    {
NEW
71
        return new self($name, $target);
×
72
    }
73

74
    /**
75
     * @param class-string<Server\MiddlewareInterface> $target
76
     */
NEW
77
    public function setTarget(string $target): self
×
78
    {
NEW
79
        $this->target = $target;
×
80

NEW
81
        return $this;
×
82
    }
83

NEW
84
    public function disable(): self
×
85
    {
NEW
86
        $this->disabled = true;
×
87

NEW
88
        return $this;
×
89
    }
90

NEW
91
    public function enable(): self
×
92
    {
NEW
93
        $this->disabled = false;
×
94

NEW
95
        return $this;
×
96
    }
97

98
    /**
99
     * @param non-empty-string ...$dependencies
100
     */
NEW
101
    public function before(string ...$dependencies): self
×
102
    {
NEW
103
        foreach ($dependencies as $dependency) {
×
NEW
104
            $this->dependencies['before'][] = $dependency;
×
105
        }
106

NEW
107
        return $this;
×
108
    }
109

110
    /**
111
     * @param non-empty-string ...$dependencies
112
     */
NEW
113
    public function after(string ...$dependencies): self
×
114
    {
NEW
115
        foreach ($dependencies as $dependency) {
×
NEW
116
            $this->dependencies['after'][] = $dependency;
×
117
        }
118

NEW
119
        return $this;
×
120
    }
121

NEW
122
    public function toArray(): array
×
123
    {
NEW
124
        return [
×
NEW
125
            'target' => $this->target,
×
NEW
126
            'disabled' => $this->disabled,
×
NEW
127
            'before' => $this->dependencies['before'],
×
NEW
128
            'after' => $this->dependencies['after'],
×
NEW
129
        ];
×
130
    }
131
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc