Class Common
Final
Namespace: oroboros
Author:
Brian Dayhoff
brian@mopsyd.me
Since:
0.0.2a
Todo:
factor this into a trait
Review:
whether or not this class is neccessary any longer. Utilities likely cover it's scope already.
Located at Common.php
Methods summary
public static
boolean
|
#
each( array & $subject, mixed $callback )
Applies a callback as a filter to each element of the subject.
The callback should expect the first parameter (the value) to
be passed by reference, and the second parameter (the key) to
be passed normally.
Applies a callback as a filter to each element of the subject.
The callback should expect the first parameter (the value) to
be passed by reference, and the second parameter (the key) to
be passed normally.
The callback parameter may be any of the following:
-any calleable argument
-an object with a public method called 'execute'
-an array, with an object as the first parameter and a public method as the second parameter
Parameters
Returns
boolean [true] if execution occurred, [false] if the callback was invalid.
Since
0.0.2a
See
\oroboros\Common::map() for passback without referential changes
|
public static
array|boolean
|
#
map( array $subject, mixed $callback )
Applies a callback as a filter to each element of the subject.
The callback should expect the first parameter (the value) and
the second parameter (the key) to be passed normally, and should
return a new result. Does not change original subject. Unlike
native PHP array_map, this follows the same argument pattern
as array walk, and passes the key as the second argument.
Applies a callback as a filter to each element of the subject.
The callback should expect the first parameter (the value) and
the second parameter (the key) to be passed normally, and should
return a new result. Does not change original subject. Unlike
native PHP array_map, this follows the same argument pattern
as array walk, and passes the key as the second argument.
The callback parameter may be any of the following:
-any calleable argument
-an object with a public method called 'execute'
-an array, with an object as the first parameter and a public method as the second parameter
Parameters
Returns
array|boolean The results of the callback, or [false] if the callback was invalid.
Since
0.0.2a
See
\oroboros\Common::each() for referential changes
|
public static
mixed
|
#
cast( string $type, mixed $data, type $delimiter = ' ', array $flags = array() )
Casts the supplied data [$data] to the type specified by [$type].
Will use [$delimiter] for implode/explode operations.
Casts the supplied data [$data] to the type specified by [$type].
Will use [$delimiter] for implode/explode operations.
Parameters
- $type
- [string|array|object|int|bool]
- $data
- The data to cast
- $delimiter
- (optional) A delimiter for implode/explode operations, when casting strings to objects or arrays.
- $flags
- (optional) Accepts [ ::recursive:: ] (unimplemented)
Returns
mixed Returns [$data] cast to the type specified by [$type], or NULL if not possible.
Since
0.0.2a
|
public static
boolean
|
#
isInternetAccessible( )
This method is meant to help prevent
requests if the system is running on
a dev machine without an internet
connection. This makes a safe check
to determine whether to serve resources
from a CDN or locally.
This method is meant to help prevent
requests if the system is running on
a dev machine without an internet
connection. This makes a safe check
to determine whether to serve resources
from a CDN or locally.
Returns
boolean [true] if connected to the internet, [false] if no network connection available.
Since
0.0.2a
Note
The site used here [example.com] is maintained by IANA, and should never be down unless the entire internet is down, which should circumvent any false flags.
|