-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColumn.php
104 lines (85 loc) · 2.15 KB
/
Column.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
namespace Videni\BetterExcel;
class Column
{
private $code;
private $label;
private $style;
private $path;
private $letter;
private $resolver;
public function __construct(string $code, string $label, string $path = null, callable $resolver = null, Style $style = null)
{
$this->code = $code;
$this->label = $label;
$this->style = $style;
$this->path = $path;
$this->resolver = $resolver;
}
public function getLabel(): string
{
return $this->label;
}
public function getStyle(): ?Style
{
return $this->style;
}
public function getPath(): string
{
return $this->path ?? $this->code;
}
public function setPath(string $path = null): self
{
$this->path = $path;
return $this;
}
public function getCode()
{
return $this->code;
}
public function setLetter($letter)
{
$this->letter = $letter;
return $this;
}
/**
* Get the column index, such as A, B, C, etc.
*
* For some methods(setRow) in \Vtiful\Kernel\Excel, the column letter is required instead
* of integer based column index. this method here is to make your life easier.
*
* @return mixed
*/
public function getLetter()
{
return $this->letter;
}
public function setResolver($resolver): self
{
$this->resolver = $resolver;
return $this;
}
public function hasResolver()
{
return $this->resolver !== null;
}
public function getResolver(): ?callable
{
return $this->resolver;
}
public static function fromArray(string $code, array $column)
{
$style = $column['style']??[];
$style = $style instanceof Style ? $style: Style::fromArray((array)$style);
return new static($code,
$column['label']?? $code,
$column['path']?? $code,
$column['resolver']?? null,
$style
);
}
public function getUnresolvedValue($row, $default = null)
{
return data_get($row, $this->getPath(), $default);
}
}