Page Menu
Home
Code
Search
Configure Global Search
Log In
Files
F1136910
StringView.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
StringView.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
Zed\Engines\API\Format
;
use
Keruald\OmniTools\Collections\HashMap
;
use
Keruald\OmniTools\Collections\Vector
;
use
LogicException
;
class
StringView
{
public
static
function
toString
(
mixed
$data
)
:
string
{
switch
(
ValueRepresentation
::
from
(
$data
))
{
case
ValueRepresentation
::
List
:
$response
=
Vector
::
from
(
$data
)
->
map
(
fn
(
$item
)
=>
self
::
toString
(
$item
))
->
implode
(
", "
);
return
"[$response]"
;
case
ValueRepresentation
::
Object
:
$response
=
HashMap
::
from
(
$data
)
->
mapToVector
(
fn
(
$key
,
$value
)
=>
"$key: "
.
self
::
toString
(
$value
)
)
->
implode
(
", "
);
return
'{'
.
$response
.
'}'
;
case
ValueRepresentation
::
Scalar
:
return
self
::
getScalarElement
(
$data
);
}
throw
new
LogicException
(
"Unreachable code"
);
}
public
static
function
getScalarElement
(
mixed
$data
)
:
string
{
if
(
is_bool
(
$data
))
{
return
$data
?
'true'
:
'false'
;
}
return
(
string
)
$data
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Jul 11, 10:37 (3 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
21313
Default Alt Text
StringView.php (1 KB)
Attached To
rZED Zed
Event Timeline
Log In to Comment