ProviderDecorator::url()   A
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
cc 6
eloc 11
c 4
b 1
f 0
nc 5
nop 2
dl 0
loc 18
rs 9.2222
1
<?php
2
/**
3
 * @author Gerard van Helden <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
 
7
namespace Zicht\Bundle\UrlBundle\Aliasing;
8
9
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
10
use Zicht\Bundle\UrlBundle\Exception\UnsupportedException;
11
use Zicht\Bundle\UrlBundle\Url\DelegatingProvider;
12
13
/**
14
 * Decorator for aliasing. No longer used, may be removed in next major release.
15
 *
16
 * @deprecated The provider decorator and it's aliasing implementation should no longer be used. The public aliasing
17
 *              is now handled by the request listener.
18
 */
19
class ProviderDecorator extends DelegatingProvider
20
{
21
    /**
22
     * Constructor
23
     *
24
     * @param Aliasing $aliasing
25
     */
26
    public function __construct(Aliasing $aliasing)
27
    {
28
        parent::__construct();
29
30
        $this->aliasing = $aliasing;
0 ignored issues
show
Bug Best Practice introduced by
The property aliasing does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
31
    }
32
33
34
    /**
35
     * @{inheritDoc}
36
     */
37
    public function url($object, array $options = array())
38
    {
39
        try {
40
            $ret = parent::url($object, $options);
41
        } catch (UnsupportedException $e) {
42
            if (is_string($object)) {
43
                // allows for referencing strings to be aliased separately.
44
                $ret = $object;
45
            } else {
46
                throw $e;
47
            }
48
        }
49
        if ((!isset($options['aliasing']) || $options['aliasing'] == false)
50
            && $publicUrl = $this->aliasing->hasPublicAlias($ret)
51
        ) {
52
            $ret = $publicUrl;
53
        }
54
        return $ret;
55
    }
56
    
57
    /**
58
     * @{inheritDoc}
59
     */
60
    public function all(AuthorizationCheckerInterface $security)
61
    {
62
        $urlList = parent::all($security);
63
64
        foreach ($urlList as &$info) {
65
            $info['value'] = $this->url($info['value']);
66
        }
67
68
        return $urlList;
69
    }
70
}
71