Completed
Push — master ( a32fd9...cce3a1 )
by Craig
06:00
created

RouteUrl   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 75
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getLanguage() 0 4 2
A setLanguage() 0 4 1
A getRoute() 0 4 1
A createFromRoute() 0 9 2
A toArray() 0 8 1
A getArgs() 0 4 1
A serialize() 0 4 1
A getFragment() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Zikula package.
5
 *
6
 * Copyright Zikula Foundation - http://zikula.org/
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zikula\Core;
13
14
use Symfony\Component\Routing\RouterInterface;
15
16
/**
17
 * RouteUrl class.
18
 */
19
class RouteUrl implements UrlInterface
20
{
21
    private $route;
22
23
    private $args;
24
25
    private $fragment;
26
27
    public function __construct($route, array $args = [], $fragment = null)
28
    {
29
        $this->route = $route;
30
        $this->args = $args;
31
        $this->fragment = $fragment;
32
    }
33
34
    public function getLanguage()
35
    {
36
        return isset($this->args['_locale']) ? $this->args['_locale'] : null;
37
    }
38
39
    public function setLanguage($lang)
40
    {
41
        $this->args['_locale'] = $lang;
42
    }
43
44
    public function getRoute()
45
    {
46
        return $this->route;
47
    }
48
49
    /**
50
     * Factory method to create instance and set Route simultaneously
51
     *
52
     * @param string $route
53
     * @param array $args
54
     * @param string $fragment
55
     *
56
     * @return RouteUrl
57
     *
58
     * @throws \InvalidArgumentException
59
     */
60
    public static function createFromRoute($route, $args = [], $fragment = '')
61
    {
62
        if (empty($route)) {
63
            throw new \InvalidArgumentException();
64
        }
65
        $routeUrl = new self($route, $args, $fragment);
66
67
        return $routeUrl;
68
    }
69
70
    public function toArray()
71
    {
72
        return [
73
            'route' => $this->route,
74
            'args' => $this->args,
75
            'fragment' => $this->fragment
76
        ];
77
    }
78
79
    public function getArgs()
80
    {
81
        return $this->args;
82
    }
83
84
    public function serialize()
85
    {
86
        return serialize($this->toArray());
87
    }
88
89
    public function getFragment()
90
    {
91
        return $this->fragment;
92
    }
93
}
94