aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/JsonApi/Middlewares/StudipMockNavigation.php
blob: 34225d4ad832e827a2d6c2cfe4a2cc26f37b45d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php

namespace JsonApi\Middlewares;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;

class DummyNavigation extends \Navigation implements \ArrayAccess
{
    /**
     * Return the list of subnavigation items of this object.
     */
    public function getSubNavigation()
    {
        return $this;
    }

    /**
     * ArrayAccess: Check whether the given offset exists.
     *
     * @todo Add bool return type when Stud.IP requires PHP8 minimal
     */
    #[ReturnTypeWillChange]
    public function offsetExists($offset)
    {
        return true;
    }

    /**
     * ArrayAccess: Get the value at the given offset.
     *
     * @todo Add mixed return type when Stud.IP requires PHP8 minimal
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($offset)
    {
        return $this;
    }

    /**
     * ArrayAccess: Set the value at the given offset.
     *
     * @todo Add void return type when Stud.IP requires PHP8 minimal
     */
    #[\ReturnTypeWillChange]
    public function offsetSet($offset, $value)
    {
    }

    /**
     * ArrayAccess: Delete the value at the given offset.
     *
     * @todo Add void return type when Stud.IP requires PHP8 minimal
     */
    #[\ReturnTypeWillChange]
    public function offsetUnset($offset)
    {
    }

    /**
     * IteratorAggregate: Create interator for request parameters.
     *
     * @todo Add \Traversable return type when Stud.IP requires PHP8 minimal
     */
    #[\ReturnTypeWillChange]
    public function getIterator()
    {
        return new \ArrayIterator();
    }
}

class StudipMockNavigation
{
    /**
     * @param Request        $request das PSR-7 Request-Objekt
     * @param RequestHandler $handler das PSR-7 Response-Objekt
     *
     * @return ResponseInterface die neue Response
     */
    public function __invoke(Request $request, RequestHandler $handler)
    {
        \Navigation::setRootNavigation(new DummyNavigation('stuff'));

        return $handler->handle($request);
    }
}