Ubiquity
2.5.2
php rapid development framework
Loading...
Searching...
No Matches
ClassicArray.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Ubiquity\devtools\utils\arrays
;
4
5
use Ubiquity\utils\base\UArray;
6
use
Ubiquity\utils\base\UString
;
7
8
class
ClassicArray
extends
BaseArray
{
9
private
$fields
;
10
private
$iFields
;
11
private
$datas
;
12
13
public
function
__construct
(
$datas
,$part=
null
){
14
if
(!is_array(
$datas
)){
15
$datas
=[$part=>
$datas
];
16
}
17
if
(
sizeof
(
$datas
)==1 && is_array(current(
$datas
))){
18
$datas
=current(
$datas
);
19
}
20
$this->datas=
$datas
;
21
}
22
23
public
function
parse
($reverse=
true
){
24
if
($reverse){
25
return
$this->
parseReverse_
();
26
}
27
return
$this->
parse_
();
28
}
29
30
private
function
getFields
(){
31
if
(is_array($this->fields)){
32
$fields
=
$this->fields
;
33
}
else
{
34
$fields
=array_keys($this->datas);
35
}
36
return
$fields
;
37
}
38
39
private
function
parseReverse_
(){
40
if
(
sizeof
($this->datas)==0){
41
return
[[
'Nothing to display'
]];
42
}
43
if
(UArray::isAssociative($this->datas)){
44
$array=[[
'field'
,
'value'
]];
45
$fields
=$this->
getFields
();
46
foreach
(
$fields
as $field){
47
if
(isset($this->datas[$field]))
48
$array[]=[$field,$this->
parseValue
($this->datas[$field])];
49
}
50
}
else
{
51
$array=[];
52
53
foreach
($this->datas as $data){
54
$array[]=[$this->
parseValue
($data)];
55
}
56
57
}
58
return
$array;
59
}
60
61
private
function
parse_
(){
62
$fields
=$this->
getFields
();
63
$array=[
$fields
];
64
$result=array_intersect_key($this->datas, array_flip(
$fields
));
65
array_walk($result,
function
(&$item){$item=$this->
parseValue
($item);});
66
$array[]=$result;
67
return
$array;
68
}
69
70
protected
function
parseValue
($value) {
71
if
(is_array($value)){
72
return
$this->
parseArray
($value,$this->iFields);
73
}elseif(UString::isValid($value)){
74
return
var_export($value,
true
);
75
}
76
return
'{.}'
;
77
}
78
82
public
function
getDatas
() {
83
return
$this->datas
;
84
}
85
89
public
function
setFields
(
$fields
) {
90
$this->fields =
$fields
;
91
}
92
96
public
function
setDatas
(
$datas
) {
97
$this->datas =
$datas
;
98
}
102
public
function
setIFields
(
$iFields
) {
103
$this->iFields =
$iFields
;
104
}
105
106
107
}
108
Ubiquity\devtools\utils\arrays\BaseArray
Definition
BaseArray.php:7
Ubiquity\devtools\utils\arrays\BaseArray\parseArray
parseArray($value, $iFields=null)
Definition
BaseArray.php:21
Ubiquity\devtools\utils\arrays\ClassicArray
Definition
ClassicArray.php:8
Ubiquity\devtools\utils\arrays\ClassicArray\parseValue
parseValue($value)
Definition
ClassicArray.php:70
Ubiquity\devtools\utils\arrays\ClassicArray\$iFields
$iFields
Definition
ClassicArray.php:10
Ubiquity\devtools\utils\arrays\ClassicArray\parseReverse_
parseReverse_()
Definition
ClassicArray.php:39
Ubiquity\devtools\utils\arrays\ClassicArray\getDatas
getDatas()
Definition
ClassicArray.php:82
Ubiquity\devtools\utils\arrays\ClassicArray\setFields
setFields($fields)
Definition
ClassicArray.php:89
Ubiquity\devtools\utils\arrays\ClassicArray\parse_
parse_()
Definition
ClassicArray.php:61
Ubiquity\devtools\utils\arrays\ClassicArray\$fields
$fields
Definition
ClassicArray.php:9
Ubiquity\devtools\utils\arrays\ClassicArray\setDatas
setDatas($datas)
Definition
ClassicArray.php:96
Ubiquity\devtools\utils\arrays\ClassicArray\parse
parse($reverse=true)
Definition
ClassicArray.php:23
Ubiquity\devtools\utils\arrays\ClassicArray\__construct
__construct($datas, $part=null)
Definition
ClassicArray.php:13
Ubiquity\devtools\utils\arrays\ClassicArray\setIFields
setIFields($iFields)
Definition
ClassicArray.php:102
Ubiquity\devtools\utils\arrays\ClassicArray\$datas
$datas
Definition
ClassicArray.php:11
Ubiquity\devtools\utils\arrays\ClassicArray\getFields
getFields()
Definition
ClassicArray.php:30
Ubiquity\utils\base\UString
String utilities.
Definition
UString.php:15
Ubiquity\devtools\utils\arrays
Definition
BaseArray.php:3
C:
Users
myadd
Documents
GitHub
ubiquity-doc-api
vendor
phpmv
ubiquity-commands
src
Ubiquity
devtools
utils
arrays
ClassicArray.php
Generated on Sun Dec 10 2023 15:04:06 for
Ubiquity
by
doxygen
1.9.8