Completed
Push — ezp26297-rest_embedding_http_c... ( 6dcd26...7b4207 )
by
unknown
44:13 queued 12:57
created

LocationController::loadLocationChildren()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 2
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
4
 * @license For full copyright and license information view LICENSE file distributed with this source code.
5
 */
6
namespace eZ\Publish\Core\REST\Server\HttpCache\Controller;
7
8
use eZ\Publish\API\Repository\Values\Content\Location;
9
use eZ\Publish\Core\REST\Server\Values\CachedValue;
10
use eZ\Publish\Core\REST\Server\Values\RestLocation;
11
use Symfony\Component\HttpFoundation\Request;
12
13
class LocationController extends AbstractController
14
{
15
    /**
16
     * @var \eZ\Publish\Core\REST\Server\Controller\Location
17
     */
18
    private $innerController;
19
20
    public function __construct($innerController)
21
    {
22
        $this->innerController = $innerController;
23
    }
24
25
    public function redirectLocation(Request $request)
26
    {
27
        // @todo we can't cache with the current data, unless we parse back the location's ID from the response.
28
        //       We could also change what the action returns.
29
        //       The value could contain the location, and leave the redirection to the visitor.
30
        return $this->innerController->redirectLocation($request); // TODO: Change the autogenerated stub
31
    }
32
33
    public function createLocation($contentId, Request $request)
34
    {
35
        return $this->innerController->createLocation($contentId, $request);
36
    }
37
38
    public function loadLocation($locationPath)
39
    {
40
        $restLocation = $this->innerController->loadLocation($locationPath);
41
42
        return new CachedValue(
43
            $restLocation,
44
            $this->getCacheTagsForLocation($restLocation->location)
0 ignored issues
show
Bug introduced by
The property location does not seem to exist in eZ\Publish\Core\REST\Server\Values\CachedValue.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
45
        );
46
    }
47
48
    public function deleteSubtree($locationPath)
49
    {
50
        return $this->innerController->deleteSubtree($locationPath);
51
    }
52
53
    public function copySubtree($locationPath, Request $request)
54
    {
55
        return $this->innerController->copySubtree($locationPath, $request);
56
    }
57
58
    public function moveSubtree($locationPath, Request $request)
59
    {
60
        return $this->innerController->moveSubtree($locationPath, $request);
61
    }
62
63
    public function swapLocation($locationPath, Request $request)
64
    {
65
        return $this->innerController->swapLocation($locationPath, $request);
66
    }
67
68
    public function loadLocationByRemoteId(Request $request)
69
    {
70
        return $this->innerController->loadLocationByRemoteId($request); // TODO: Change the autogenerated stub
71
    }
72
73
    public function loadLocationsForContent($contentId, Request $request)
74
    {
75
        $locationList = $this->innerController->loadLocationsForContent($contentId, $request);
76
77
        return new CachedValue(
78
            $locationList,
79
            [
80
                'location' => array_map(
81
                    function (RestLocation $location) {
82
                        return $location->location->id;
83
                    },
84
                    $locationList->locations
0 ignored issues
show
Bug introduced by
The property locations does not seem to exist in eZ\Publish\Core\REST\Server\Values\CachedValue.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
85
                ),
86
                'content' => $contentId,
87
            ]
88
        );
89
    }
90
91
    public function loadLocationChildren($locationPath, Request $request)
92
    {
93
        $locationList = $this->innerController->loadLocationChildren($locationPath, $request);
94
95
        // cache expires when the location's path is affected
96
        $pathArray = explode('/', trim($locationPath, '/'));
97
        $locationId = array_pop($pathArray);
98
99
        return new CachedValue(
100
            $locationList,
101
            [
102
                'path' => $locationId,
103
                'location' => array_merge(
104
                    [$locationId],
105
                    array_map(
106
                        function (RestLocation $location) {
107
                            return 'location-' . $location->location->id;
108
                        },
109
                        $locationList->locations
0 ignored issues
show
Bug introduced by
The property locations does not seem to exist in eZ\Publish\Core\REST\Server\Values\CachedValue.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
110
                    )
111
                ),
112
            ]
113
        );
114
    }
115
116
    public function updateLocation($locationPath, Request $request)
117
    {
118
        return $this->innerController->updateLocation($locationPath, $request);
119
    }
120
}
121