Perforce Chronicle 2012.2/486814
API Documentation

P4_Environment Class Reference

Provides access to information about the operating environment. More...

List of all members.

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

Detailed Description

Provides access to information about the operating environment.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

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).

Parameters:
callable$callbackthe function to execute at shutdown.
Returns:
void
    {
        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.

Returns:
int bytes available for arguments
    {
        // 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.

Returns:
array the list of registered shutdown functions.
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.

Returns:
boolean whether or not we are running on a windows OS
    {
        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.

Returns:
void
    {
        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.

Parameters:
array | null$callbacksfunctions to execute at shutdown.
Returns:
void
    {
        // 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);
        }
    }

Member Data Documentation

P4_Environment::$_shutdownCallbacks = array() [static, protected]
P4_Environment::$_shutdownRegistered = false [static, protected]

The documentation for this class was generated from the following file: