Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F13143524
Ok.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
Ok.php
View Options
<?php
namespace
Keruald\OmniTools\DataTypes\Result
;
use
InvalidArgumentException
;
use
Keruald\OmniTools\Reflection\Type
;
class
Ok
extends
Result
{
private
mixed
$value
=
null
;
private
string
$type
=
"NULL"
;
public
function
__construct
(
$value
=
null
)
{
if
(
$value
!==
null
)
{
$this
->
setValue
(
$value
);
}
}
public
function
isOK
()
:
true
{
return
true
;
}
public
function
isError
()
:
false
{
return
false
;
}
public
function
getValue
()
:
mixed
{
return
$this
->
value
;
}
public
function
setValue
(
mixed
$value
)
:
void
{
$type
=
Type
::
getTypeOf
(
$value
);
if
(!
$this
->
isAcceptableValueType
(
$type
))
{
throw
new
InvalidArgumentException
(
<<<'EOD'
When you mutate the value of an Ok object, you can't mutate the object type.
Please consider return a new Ok instead.
EOD
);
}
$this
->
value
=
$value
;
$this
->
type
=
$type
;
}
private
function
isAcceptableValueType
(
string
$type
)
:
bool
{
return
$this
->
value
===
null
||
$type
===
$this
->
type
;
}
public
function
map
(
callable
$callable
)
:
self
{
$value
=
$callable
(
$this
->
value
);
return
new
self
(
$value
);
}
public
function
mapErr
(
callable
$callable
)
:
self
{
return
$this
;
}
public
function
orElse
(
mixed
$default
)
:
mixed
{
return
$this
->
value
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Nov 21, 16:37 (1 d, 22 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3138177
Default Alt Text
Ok.php (1 KB)
Attached To
Mode
rKERUALD Keruald libraries development repository
Attached
Detach File
Event Timeline
Log In to Comment