/** * Return's the singleton instance. * * @return \AppserverIo\Appserver\Core\Utilities\Runlevels The singleton instance */ public static function singleton() { if (Runlevels::$instance == null) { Runlevels::$instance = new Runlevels(); } return Runlevels::$instance; }
$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();
/** * Translates and returns the runlevel of the passed a string representation. * * @param string $runlevel The string representation of the runlevel to return * * @return integer The runlevel of the passed string representation * * @throws \Exception Is thrown if the passed string representation is not a valid runlevel */ public function runlevelFromString($runlevel) { // query whether the passed string representation is a valid runlevel if (Runlevels::singleton()->isRunlevel($runlevel)) { return Runlevels::singleton()->getRunlevel($runlevel); } // throw an exception if the runlevel is unknown throw new \Exception(sprintf('Request invalid runlevel to string conversion for %s', $runlevel)); }