Completed
Push — master ( 0881bb...3a6ebc )
by Michael
04:47
created

AltsysBreadcrumbs   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 59
rs 10
wmc 11
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 8 2
A appendPath() 0 15 3
A hasPaths() 0 4 1
A __construct() 0 3 1
A getXoopsBreadcrumbs() 0 17 4
1
<?php
2
3
// singleton for xoops_breadcrumbs
4
class AltsysBreadcrumbs
5
{
6
7
    public $paths = array() ;
8
9
    public function __construct()
10
    {
11
    }
12
//HACK by domifara for php5.3+
13
//function &getInstance()
14
public static function &getInstance()
15
{
16
    static $instance ;
17
    if (! isset($instance)) {
18
        $instance = new AltsysBreadcrumbs() ;
19
    }
20
    return $instance ;
21
}
22
23
    public function getXoopsBreadcrumbs()
24
    {
25
        $ret = array() ;
26
        foreach ($this->paths as $val) {
27
            // delayed language constant
28
        if (substr($val['name'], 0, 1) == '_' && defined($val['name'])) {
29
            $ret[] = array(
30
                'url' => $val['url'] ,
31
                'name' => constant($val['name'])
32
            ) ;
33
        } else {
34
            $ret[] = $val ;
35
        }
36
        }
37
        unset($ret[count($ret) - 1 ]['url']) ;
38
        return $ret ;
39
    }
40
41
// all data should be escaped
42
public function appendPath($url_or_path, $name = '...')
43
{
44
    if (is_array($url_or_path)) {
45
        if (empty($url_or_path['name'])) {
46
            // multiple paths
47
            $this->paths = array_merge($this->paths, $url_or_path) ;
48
        } else {
49
            // array format (just a path)
50
            $this->paths[] = $url_or_path ;
51
        }
52
    } else {
53
        // separate format
54
        $this->paths[] = array( 'url' => $url_or_path , 'name' => $name ) ;
55
    }
56
}
57
58
    public function hasPaths()
59
    {
60
        return ! empty($this->paths) ;
61
    }
62
}
63