20 private static function parseValue($v, $depth = 1, $format =
false) {
21 if (\is_numeric ( $v ) && gettype($v)!==
'string') {
25 } elseif (\is_array ( $v )) {
26 $result = self::asPhpArray_ ( $v, $depth + 1, $format );
27 } elseif (\is_string ( $v ) && self::isExpression($v)) {
29 } elseif ($v instanceof \Closure) {
31 } elseif ($v instanceof \DateTime) {
32 $result =
"\DateTime::createFromFormat('Y-m-d H:i:s','" . $v->format (
'Y-m-d H:i:s' ) .
"')";
35 $result =
"\"" . \str_replace ( [
'$',
'"' ], [
'\$',
'\"' ], $result ) .
"\"";
39 private static function as_($array,$formatParams=[
'prefix' =>
'',
'before'=>
'(',
'after'=>
')'], $valueCallback=
null,$depth = 1,$format =
false) {
45 $tab = \str_repeat (
"\t", $depth );
48 foreach ( $array as $k => $v ) {
49 $v=self::parseValue ( $v, $depth + 1, $format );
50 if (\is_string ( $k )) {
51 if(isset($valueCallback)){
52 $exts []=$valueCallback($k,$v);
61 if (\count ( $exts ) > 0) {
62 $extsStr = $formatParams[
'before'].
"{$nl}{$tab}" . \implode (
",{$nl}{$tab}", $exts ) .
"{$nl}{$tab}".$formatParams[
'after'];
64 $extsStr = $formatParams[
'before'].$formatParams[
'after'];
66 return $formatParams[
'prefix'] . $extsStr;
68 public static function asPhpArray($array, $prefix =
'', $depth = 1, $format =
false) {
69 return self::as_($array,[
'prefix'=>$prefix,
'before'=>
'(',
'after'=>
')'],
null,$depth,$format);
72 public static function asPhpArray_($array, $depth = 1, $format =
false) {
73 return self::as_($array,[
'prefix'=>
'',
'before'=>
'[',
'after'=>
']'],
null,$depth,$format);
76 public static function asPhpAttribute($array, $prefix =
'', $depth = 1, $format =
false) {
77 return self::as_($array,[
'prefix'=>$prefix,
'before'=>
'(',
'after'=>
')'],
function($k,$v){
return $k.
': '.$v;},$depth,$format);
80 public static function asPhpClass($array, $name, $namespace =
'', $format =
false) {
87 $content =
'public static $value=' . self::asPhpArray ( $array,
'array', 1,
true ) .
';';
88 if ($namespace !=
null) {
89 $namespace =
"namespace {$namespace};{$nl}";
91 return "{$namespace}class {$name} {" . $nl . $tab . $content . $nl . $tab .
"}";
94 public static function asJSON($array) {
95 return \json_encode ( $array, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE );
Ubiquity\utils\base$UIntrospection This class is part of Ubiquity.
static closure_dump(\Closure $c)
static isBooleanStr($value)
static startswith($hay, $needle)
static doubleBackSlashes($value)
static getBooleanStr($value)
Ubiquity\utils\base\traits$UArrayAsTrait This class is part of Ubiquity.
static parseValue($v, $depth=1, $format=false)
static asPhpAttribute($array, $prefix='', $depth=1, $format=false)
static as_($array, $formatParams=['prefix'=> '', 'before'=>'(', 'after'=>')'], $valueCallback=null, $depth=1, $format=false)
static asPhpArray_($array, $depth=1, $format=false)
static isExpression(string $v)
static asPhpClass($array, $name, $namespace='', $format=false)
static asPhpArray($array, $prefix='', $depth=1, $format=false)