Completed
Push — ezp26297-rest_embedding_http_c... ( 123323 )
by
unknown
80:28 queued 54:58
created

LocationController::loadLocationChildren()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 2
dl 0
loc 15
rs 9.4285
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\Core\REST\Server\Values\CachedValue;
9
use eZ\Publish\Core\REST\Server\Values\RestLocation;
10
use Symfony\Component\HttpFoundation\Request;
11
12
class LocationController extends AbstractController
13
{
14
    /**
15
     * @var \eZ\Publish\Core\REST\Server\Controller\Location
16
     */
17
    private $innerController;
18
19
    public function __construct($innerController)
20
    {
21
        $this->innerController = $innerController;
22
    }
23
24
    public function redirectLocation(Request $request)
25
    {
26
        return $this->innerController->redirectLocation($request); // TODO: Change the autogenerated stub
27
    }
28
29
    public function createLocation($contentId, Request $request)
30
    {
31
        return $this->innerController->createLocation($contentId, $request);
32
    }
33
34
    public function loadLocation($locationPath)
35
    {
36
        $restLocation = $this->innerController->loadLocation($locationPath);
37
38
        return new CachedValue(
39
            $restLocation,
40
            $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...
41
        );
42
    }
43
44
    public function deleteSubtree($locationPath)
45
    {
46
        return $this->innerController->deleteSubtree($locationPath);
47
    }
48
49
    public function copySubtree($locationPath, Request $request)
50
    {
51
        return $this->innerController->copySubtree($locationPath, $request);
52
    }
53
54
    public function moveSubtree($locationPath, Request $request)
55
    {
56
        return $this->innerController->moveSubtree($locationPath, $request);
57
    }
58
59
    public function swapLocation($locationPath, Request $request)
60
    {
61
        return $this->innerController->swapLocation($locationPath, $request);
62
    }
63
64
    public function loadLocationByRemoteId(Request $request)
65
    {
66
        return $this->innerController->loadLocationByRemoteId($request); // TODO: Change the autogenerated stub
67
    }
68
69
    public function loadLocationsForContent($contentId, Request $request)
70
    {
71
        $locationList = $this->innerController->loadLocationsForContent($contentId, $request);
72
73
        return new CachedValue(
74
            $locationList,
75
            [
76
                'location' => array_map(
77
                    function (RestLocation $location) {
78
                        return $location->location->id;
79
                    },
80
                    $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...
81
                ),
82
                'content' => $contentId
83
            ]
84
        );
85
    }
86
87
    public function loadLocationChildren($locationPath, Request $request)
88
    {
89
        $children = $this->innerController->loadLocationChildren($locationPath, $request);
90
91
        // cache expires when the location's path is affected
92
        $pathArray = explode('/', trim($locationPath, '/'));
93
        $locationId = array_pop($pathArray);
94
        return new CachedValue(
95
            $children,
96
            [
97
                'path' => $locationId,
98
                'location' => $locationId,
99
            ]
100
        );
101
    }
102
103
    public function updateLocation($locationPath, Request $request)
104
    {
105
        return $this->innerController->updateLocation($locationPath, $request);
106
    }
107
}
108