/** * Get the environment modifier (if any) which helps to switch the configuration environment * * @param string $appBase The base of the application we are dealing with * * @return string * * @throws \AppserverIo\Properties\PropertyFileNotFoundException * @throws \AppserverIo\Properties\PropertyFileParseException */ public static function getEnvironmentModifier($appBase) { // check if we got the properties cached already, if not load them anew $properties = null; if (!is_null(self::$cachedProperties)) { $properties = self::$cachedProperties; } else { // load the properties from file $propertiesFile = DirectoryKeys::realpath(sprintf('%s/%s', $appBase, self::CONFIGURATION_FILE)); // load the properties from the configuration file if (file_exists($propertiesFile)) { $properties = Properties::create()->load($propertiesFile); } } // load the properties from the configuration file $result = ''; // get the actual property if it exists if (!is_null($properties) && $properties->exists(ConfigurationKeys::APP_ENVIRONMENT)) { $result = $properties->get(ConfigurationKeys::APP_ENVIRONMENT); } // ENV variable always wins if (defined(ConfigurationKeys::APP_ENVIRONMENT)) { $result = getenv(ConfigurationKeys::APP_ENVIRONMENT); } return $result; }
/** * Creates a new naming context and add's it to the passed manager. * * @param \AppserverIo\Psr\Application\ManagerInterface $manager The manager to add the naming context to * * @return void */ public static function visit(ManagerSettingsAwareInterface $manager) { // load the path to the web application $application = $manager->getApplication(); $webappPath = $application->getWebappPath(); // initialize the variable for the properties $properties = null; // load the configuration base directory if ($baseDirectory = $manager->getManagerSettings()->getBaseDirectory()) { // look for naming context properties in the manager's base directory $propertiesFile = DirectoryKeys::realpath(sprintf('%s/%s/%s', $webappPath, $baseDirectory, NamingContextFactory::CONFIGURATION_FILE)); // load the properties from the configuration file if (file_exists($propertiesFile)) { $properties = Properties::create()->load($propertiesFile); } } // create the initial context instance $initialContext = new InitialContext($properties); $initialContext->injectApplication($application); // set the initial context in the manager $manager->injectInitialContext($initialContext); }
$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(ApplicationServer::$runlevels) 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 (ApplicationServer::$runlevels 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();
/** * Makes the path an absolute path or returns null if passed path is empty. * * @param string $path A path to absolute * * @return string The absolute path */ protected function makePathAbsolute($path = '') { if (empty($path) === false) { return DIRECTORY_SEPARATOR . trim(DirectoryKeys::realpath($path), DIRECTORY_SEPARATOR); } }
/** * Return a new sender for the message queue with the passed lookup name. * * @param string $lookupName The lookup name of the queue to return a sender for * @param string $sessionId The session-ID to be passed to the queue session * * @return \AppserverIo\Messaging\QueueSender The sender instance */ public function createSenderForQueue($lookupName, $sessionId = null) { // load the application name $application = $this->getApplication(); $applicationName = $application->getName(); $webappPath = $application->getWebappPath(); // initialize the variable for the properties $properties = null; // load the configuration base directory if ($baseDirectory = $this->getManagerSettings()->getBaseDirectory()) { // look for naming context properties in the manager's base directory $propertiesFile = DirectoryKeys::realpath(sprintf('%s/%s/%s', $webappPath, $baseDirectory, QueueManagerSettingsInterface::CONFIGURATION_FILE)); // load the properties from the configuration file if (file_exists($propertiesFile)) { $properties = Properties::create()->load($propertiesFile); } } // initialize and return the sender $queue = \AppserverIo\Messaging\MessageQueue::createQueue($lookupName); $connection = \AppserverIo\Messaging\QueueConnectionFactory::createQueueConnection($applicationName, $properties); $session = $connection->createQueueSession(); return $session->createSender($queue); }