Title::prepend()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * Meta
5
 * @copyright Copyright (c) 2011 - 2014 Aleksandr Torosh (http://wezoom.com.ua)
6
 * @author Aleksandr Torosh <[email protected]>
7
 */
8
9
namespace Application\Mvc\Helper;
10
11
class Title extends \Phalcon\Mvc\User\Component
12
{
13
14
    private static $instance;
15
    private static $parts = array();
16
    private static $separator = ' | ';
17
18
    public static function getInstance($title = null, $h1 = false)
19
    {
20
        if (!self::$instance) {
21
            self::$instance = new Title();
22
        }
23
        if ($title) {
24
            self::$instance->append($title);
25
            if ($h1) {
26
                self::$instance->getDi()->get('view')->setVar('title', $title);
27
            }
28
        }
29
        return self::$instance;
30
31
    }
32
33
    public function prepend($string)
34
    {
35
        if ($string) {
36
            array_unshift(self::$parts, $string);
37
        }
38
    }
39
40
    public function append($string)
41
    {
42
        if ($string) {
43
            self::$parts[] = $string;
44
        }
45
    }
46
47
    public function get()
48
    {
49
        if (!empty(self::$parts)) {
50
            return implode(self::$separator, self::$parts);
51
        }
52
    }
53
54
    public function set($string)
55
    {
56
        if ($string) {
57
            self::$parts = array($string);
58
        }
59
    }
60
61
}
62