Completed
Push — master ( 5f2e51...f2779d )
by Jean-Christophe
03:46
created

InstanceViewerCaption::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
namespace Ajax\semantic\widgets\base;
3
use Ajax\semantic\widgets\base\InstanceViewer;
4
5
class InstanceViewerCaption extends InstanceViewer {
6
	protected $captions;
7
8
	public function __construct($instance=NULL,$captions=NULL){
9
		parent::__construct($instance);
10
		$this->setCaptions($captions);
11
	}
12
13
	public function getCaption($index){
14
		if($this->properties[$index] instanceof \ReflectionProperty)
15
			return $this->properties[$index]->getName();
16
		elseif(\is_callable($this->properties[$index]))
17
			return "";
18
		else
19
			return $this->properties[$index];
20
	}
21
22
	public function getCaptions(){
23
		if(isset($this->captions)){
24
			$result= $this->captions;
25
			for($i=\sizeof($result);$i<$this->count();$i++){
26
				$result[]="";
27
			}
28
			return $result;
29
		}
30
		$captions=[];
31
		$index=0;
32
		$count=$this->count();
33
		while($index<$count){
34
			$captions[]=$this->getCaption($index++);
35
		}
36
		return $captions;
37
	}
38
39
	public function setCaptions($captions) {
40
		$this->captions=$captions;
41
		return $this;
42
	}
43
}