Completed
Push — master ( 412cc9...332cd3 )
by Peter
04:16
created

DocNavRecursive::__toString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: peter
5
 * Date: 26.07.17
6
 * Time: 15:49
7
 */
8
9
namespace Maslosoft\Zamm\Widgets;
10
11
12
use Maslosoft\Staple\Widgets\SubNavRecursive;
13
14
class DocNavRecursive extends SubNavRecursive
15
{
16
	public $title = '';
17
18
	public function __construct($options = [])
19
	{
20
		if(is_string($options))
21
		{
22
			$this->title = $options;
23
			$options = [];
24
		}
25
		$root = __DIR__;
26
		if(empty($options['root']))
27
		{
28
			$trace = debug_backtrace(null, 1);
29
			$root = dirname($trace[0]['file']);
30
		}
31
		$defaults = [
32
			'root' => $root,
33
			'path' => '.',
34
			'skipLevel' => 1
35
		];
36
		foreach ($defaults as $name => $value)
37
		{
38
			if (!array_key_exists($name, $options))
39
			{
40
				$options[$name] = $value;
41
			}
42
		}
43
		parent::__construct($options);
44
	}
45
46
	public function __toString()
47
	{
48
		$prefix = '';
49
		if($this->title)
50
		{
51
			$prefix = '<h3>' . $this->title . '</h3>' . "\n";
52
		}
53
		return $prefix . parent::__toString() . "\n\n";
54
	}
55
}