Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12423878
Boolean.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
Boolean.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
Keruald\OmniTools\Booleans
;
class
Boolean
{
///
/// Properties
///
private
bool
$value
;
///
/// Constructors
///
public
function
__construct
(
bool
$value
)
{
$this
->
value
=
$value
;
}
public
static
function
true
()
:
self
{
return
new
self
(
true
);
}
public
static
function
false
()
:
self
{
return
new
self
(
false
);
}
///
/// Basic logic operators
///
public
function
and
(
self
|
bool
$other
)
:
self
{
if
(
$this
->
value
===
true
)
{
$this
->
value
=
self
::
toScalar
(
$other
);
}
return
$this
;
}
public
function
or
(
self
|
bool
$other
)
:
self
{
if
(
$this
->
value
===
false
)
{
$this
->
value
=
self
::
toScalar
(
$other
);
}
return
$this
;
}
public
function
xor
(
self
|
bool
$other
)
:
self
{
$this
->
value
=
(
$this
->
value
xor
self
::
toScalar
(
$other
));
return
$this
;
}
public
function
not
()
:
self
{
$this
->
value
=
!
$this
->
value
;
return
$this
;
}
public
function
implication
(
self
|
bool
$other
)
:
self
{
$this
->
value
=
$this
->
value
===
false
||
self
::
toScalar
(
$other
);
return
$this
;
}
public
function
equivalence
(
self
|
bool
$other
)
:
self
{
$this
->
value
=
$this
->
isEqualsTo
(
$other
);
return
$this
;
}
///
/// Comparison
///
public
function
isEqualsTo
(
self
|
bool
$other
)
:
bool
{
return
$this
->
value
===
self
::
toScalar
(
$other
);
}
///
/// Type convert
///
public
function
asBool
()
:
bool
{
return
$this
->
value
;
}
public
function
asInteger
()
:
int
{
return
(
int
)
$this
->
value
;
}
public
function
asString
()
:
string
{
return
match
(
$this
->
value
)
{
true
=>
"true"
,
false
=>
"false"
,
};
}
public
static
function
toScalar
(
self
|
bool
$bool
)
:
bool
{
if
(
$bool
instanceof
self
)
{
return
$bool
->
value
;
}
return
(
bool
)
$bool
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Thu, Nov 6, 19:18 (7 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3137559
Default Alt Text
Boolean.php (2 KB)
Attached To
Mode
rKERUALD Keruald libraries development repository
Attached
Detach File
Event Timeline
Log In to Comment