AppserverIo\Appserver\Core\Utilities\Runlevels::singleton PHP Method

singleton() public static method

Return's the singleton instance.
public static singleton ( ) : Runlevels
return Runlevels The singleton instance
    public static function singleton()
    {
        if (Runlevels::$instance == null) {
            Runlevels::$instance = new Runlevels();
        }
        return Runlevels::$instance;
    }

Usage Example

Example #1
0
$namingDirectory->createSubdirectory('php:env');
$namingDirectory->createSubdirectory('php:env/args');
$namingDirectory->createSubdirectory('php:global');
$namingDirectory->createSubdirectory('php:global/log');
$namingDirectory->createSubdirectory('php:services');
// create the default subdirectories
foreach (array_keys(Runlevels::singleton()->getRunlevels()) as $runlevel) {
    $namingDirectory->createSubdirectory(sprintf('php:services/%s', $runlevel));
}
// bind the command line arguments to the naming directory
foreach ($arguments as $name => $value) {
    $namingDirectory->bind(sprintf('php:env/args/%s', $name), empty($value) ? true : $value);
}
// bind the current user to the naming directory
$namingDirectory->bind('php:env/currentUser', isset($_SERVER['SUDO_USER']) ? $_SERVER['SUDO_USER'] : get_current_user());
// bind the path to the default configuration and bootstrap filenames
$namingDirectory->bind('php:env/configurationFilename', DirectoryKeys::realpath($filename));
$namingDirectory->bind('php:env/bootstrapConfigurationFilename', DirectoryKeys::realpath($bootstrapFilename));
// add the storeage containers for the runlevels
$runlevels = new GenericStackable();
foreach (Runlevels::singleton()->getRunlevels() as $runlevel) {
    $runlevels[$runlevel] = new GenericStackable();
}
// initialize and start the application server
$applicationServer = ApplicationServer::singleton($namingDirectory, $runlevels);
// we've to wait for shutdown
while ($applicationServer->keepRunning()) {
    sleep(1);
}
// wait until all threads have been stopped
$applicationServer->join();
All Usage Examples Of AppserverIo\Appserver\Core\Utilities\Runlevels::singleton