/** * 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); }
/** * @param $value * * @throws \AppserverIo\Collections\InvalidKeyException * @throws \AppserverIo\Lang\NullPointerException */ public static function setEnvironmentProperty($value) { self::$cachedProperties = Properties::create(); self::$cachedProperties->add(ConfigurationKeys::APP_ENVIRONMENT, $value); }
/** * 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); }
/** * Returns the system proprties. If a container node has been passed, * the container properties will also be appended. * * @param ContainerNodeInterface|null $containerNode The container to return the system properties for * * @return \AppserverIo\Properties\Properties The system properties */ public function getSystemProperties(ContainerNodeInterface $containerNode = null) { // initialize the properties $properties = Properties::create(); // append the system properties $properties->add(SystemPropertyKeys::BASE, $this->getBaseDirectory()); $properties->add(SystemPropertyKeys::VAR_LOG, $this->getLogDir()); $properties->add(SystemPropertyKeys::ETC, $this->getEtcDir()); $properties->add(SystemPropertyKeys::ETC_APPSERVER, $this->getConfDir()); $properties->add(SystemPropertyKeys::ETC_APPSERVER_CONFD, $this->getConfdDir()); // append the declared system propertie /** @var \AppserverIo\Appserver\Core\Api\Node\SystemPropertyNode $systemProperty */ foreach ($this->getSystemConfiguration()->getSystemProperties() as $systemProperty) { $properties->add($systemProperty->getName(), $systemProperty->castToType()); } // query whether or not a container node has been passed if ($containerNode != null) { // append the container specific properties $properties->add(SystemPropertyKeys::TMP, $this->getTmpDir($containerNode)); $properties->add(SystemPropertyKeys::CONTAINER_NAME, $containerNode->getName()); $properties->add(SystemPropertyKeys::WEBAPPS, $this->getWebappsDir($containerNode)); // append the host specific system properties if ($host = $containerNode->getHost()) { $properties->add(SystemPropertyKeys::HOST_APP_BASE, $host->getAppBase()); $properties->add(SystemPropertyKeys::HOST_TMP_BASE, $host->getTmpBase()); $properties->add(SystemPropertyKeys::HOST_DEPLOY_BASE, $host->getDeployBase()); } } // return the properties return $properties; }