<?php
use \Dsheiko\Extras\Any;
$res = Any::chain(new \ArrayObject([1,2,3]))
->toArray() // value is [1,2,3]
->map(function($num){ return [ "num" => $num ]; })
// value is [[ "num" => 1, ..]]
->reduce(function($carry, $arr){
$carry .= $arr["num"];
return $carry;
}, "") // value is "123"
->replace("/2/", "") // value is "13"
->then(function($value){
if (empty($value)) {
throw new \Exception("Empty value");
}
return $value;
})
->value();
echo $res; // "13"
Returns true if source is an instance of DateTime.
{mixed} $source
- value to check
isDate($source): bool
<?php
$res = Any::isDate(new DateTime('2011-01-01T15:03:01.012345Z')); // true
Returns true if source is an Error
{mixed} $source
- value to check
isError($source): bool
<?php
try {
throw new Error("message");
} catch (\Error $ex) {
$res = Any::isError($ex); // true
}
Returns true if source is an Exception
{mixed} $source
- value to check
isException($source): bool
<?php
try {
throw new Error("message");
} catch (\Exception $ex) {
$res = Any::isException($ex); // true
}
Returns true if source is NULL
{mixed} $source
- value to check
isNull($source): bool
<?php
Any::isNull(null); // true
Returns a wrapped object. Calling methods on this object will continue to return wrapped objects until value is called.
{string} $value
- source
chain(string $value)