Completed
Push — ezp25003-trash_subitems_count_... ( e4ea85...5e3f64 )
by André
54:00
created

parseIdFromHref()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 2
eloc 4
c 2
b 1
f 0
nc 2
nop 1
dl 0
loc 8
rs 9.4285
1
<?php
2
/**
3
 * @license For full copyright and license information view LICENSE file distributed with this source code.
4
 */
5
namespace eZ\Publish\Core\REST\Server\Input\Parser\Limitation;
6
7
use eZ\Publish\API\Repository\Values;
8
use eZ\Publish\Core\REST\Common\Exceptions;
9
10
/**
11
 * Generic limitation value parser.
12
 *
13
 * Instances are built with:
14
 * - The name of a route parameter, that will be searched for limitation values
15
 *   Example: "sectionId" from "/content/section/{sectionId}"
16
 * - The FQN of the limitation value object that the parser builds
17
 */
18
class PathStringRouteBasedLimitationParser extends RouteBasedLimitationParser
19
{
20
    /**
21
     * Prefixes the value parsed by the parent with a '/'.
22
     *
23
     * @throws \eZ\Publish\Core\REST\Common\Exceptions\Parser if the '_href' attribute doesn't end with a slash, since 6.4
24
     *
25
     * @param $limitationValue
26
     *
27
     * @return false|mixed
28
     */
29
    protected function parseIdFromHref($limitationValue)
30
    {
31
        if (substr($limitationValue['_href'], -1) !== '/') {
32
            throw new Exceptions\Parser("The '_href' attribute must end with a slash.");
33
        }
34
35
        return '/' . ltrim(parent::parseIdFromHref($limitationValue), '/');
36
    }
37
}
38