|
Perforce Chronicle 2012.2/486814
API Documentation
|
Provides access to information about the operating environment. More...
Static Public Member Functions | |
| static | addShutdownCallback ($callback) |
| Register a function to execute at shutdown. | |
| static | getArgMax () |
| Returns the maximum number of bytes that can be used for arguments when launching an application. | |
| static | getShutdownCallbacks () |
| Get all of the registered shutdown callbacks. | |
| static | isWindows () |
| Determines whether or not we are running on a windows system by checking for the PHP_WINDOWS_VERSION_MAJOR constant. | |
| static | runShutdownCallbacks () |
| Execute all of the registered shutdown callbacks. | |
| static | setShutdownCallbacks (array $callbacks=null) |
| Set all of the registered shutdown callbacks at once. | |
Static Protected Attributes | |
| static | $_shutdownCallbacks = array() |
| static | $_shutdownRegistered = false |
Provides access to information about the operating environment.
| static P4_Environment::addShutdownCallback | ( | $ | callback | ) | [static] |
Register a function to execute at shutdown.
This provides useful abstraction of PHP's built-in register_shutdown_function facility. This allows registered callbacks to be inspected or executed arbitrarily (especially useful during testing).
| callable | $callback | the function to execute at shutdown. |
{
if (!is_callable($callback)) {
throw new InvalidArgumentException(
"Cannot add shutdown callback. Given callback is not callable."
);
}
// if we haven't already done so, register
// runShutdownCallbacks as a shutdown function.
if (!static::$_shutdownRegistered) {
register_shutdown_function(
get_called_class() . "::runShutdownCallbacks"
);
static::$_shutdownRegistered = true;
}
static::$_shutdownCallbacks[] = $callback;
}
| static P4_Environment::getArgMax | ( | ) | [static] |
Returns the maximum number of bytes that can be used for arguments when launching an application.
{
// if we are on windows early exit with 32k
if (static::isWindows()) {
return 32768;
}
// try getting a value via getconf;
$argMax = `getconf ARG_MAX`;
// if we didn't get a plain number back return 32k as a default
if ($argMax !== (string)(int)$argMax) {
return 32768;
}
return $argMax;
}
| static P4_Environment::getShutdownCallbacks | ( | ) | [static] |
Get all of the registered shutdown callbacks.
{
return static::$_shutdownCallbacks;
}
| static P4_Environment::isWindows | ( | ) | [static] |
Determines whether or not we are running on a windows system by checking for the PHP_WINDOWS_VERSION_MAJOR constant.
{
return defined("PHP_WINDOWS_VERSION_MAJOR");
}
| static P4_Environment::runShutdownCallbacks | ( | ) | [static] |
Execute all of the registered shutdown callbacks.
Callbacks are run in the same order that they were registered. Once a callback has been executed, it is removed from the shutdown callbacks list.
{
foreach (static::$_shutdownCallbacks as $key => $callback) {
// if callback is still callable, execute it.
// as we run at shutdown it is possible, though unlikely,
// a callback could go away between add and now.
if (is_callable($callback)) {
call_user_func($callback);
}
unset(static::$_shutdownCallbacks[$key]);
}
}
| static P4_Environment::setShutdownCallbacks | ( | array $ | callbacks = null | ) | [static] |
Set all of the registered shutdown callbacks at once.
This could be useful for clearing, re-ordering or otherwise manipulating the list of registered shutdown callbacks.
| array | null | $callbacks | functions to execute at shutdown. |
{
// start by clearing existing callbacks if present
static::$_shutdownCallbacks = array();
// use add method to ensure callback is validated and our
// runShutdownCallbacks method has an opportunity to register.
foreach ($callbacks ?: array() as $callback) {
static::addShutdownCallback($callback);
}
}
P4_Environment::$_shutdownCallbacks = array() [static, protected] |
P4_Environment::$_shutdownRegistered = false [static, protected] |