/** * The default constructor. * * @param \AppserverIo\Properties\Properties $defaults The properties we want want to use for initialization */ public function __construct(Properties $defaults = null) { // check if properties are passed if ($defaults != null) { // if yes set them parent::__construct($defaults->toArray()); } else { parent::__construct(); } }
/** * 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); }
/** * Initialize the initial context with the values of the passed properties. * * @param \AppserverIo\Properties\PropertiesInterface $properties The configuration properties */ public function __construct(PropertiesInterface $properties = null) { // initialize the default properties if no ones has been passed if ($properties == null) { // initialize the default properties $properties = new Properties(); foreach ($this->defaultProperties as $key => $value) { $properties->setProperty($key, $value); } } // inject the properties $this->injectProperties($properties); // create a factory for the lexer we use to parse the JNDI style bean names $factory = new UsingPregReplace(new LexerDataGenerator()); // create the lexer instance and inject it $this->injectLexer($factory->createLexer(array('php' => InitialContext::T_SCHEME, 'global\\/([a-zA-Z0-9_-]+)' => InitialContext::T_GLOBAL_SCOPE, 'app' => InitialContext::T_APPLICATION_SCOPE, '\\:' => InitialContext::T_COLON, '\\/' => InitialContext::T_SEPARATOR, 'local|remote' => InitialContext::T_INTERFACE, '\\w+' => InitialContext::T_CLASS))); }
/** * Loads the values found in the configuration file and merges * them with the servlet context initialization parameters. * * @return void */ protected function initConfiguration() { // load the relative path to the Routlt configuration file $configurationFileName = $this->getInitParameter(ControllerServlet::INIT_PARAMETER_ROUTLT_CONFIGURATION_FILE); // load the path to the configuration file $configurationFile = $this->getServletConfig()->getWebappPath() . DIRECTORY_SEPARATOR . ltrim($configurationFileName, '/'); // if the file is readable if (is_file($configurationFile) && is_readable($configurationFile)) { // load the properties from the file $properties = new Properties(); $properties->load($configurationFile); // append the properties to the servlet context foreach ($properties as $paramName => $paramValue) { $this->getServletContext()->addInitParameter($paramName, $paramValue); } } }
/** * Checks if the resource identifier will be initialized propertly * from a URL with global scope and remote interface. * * @return void */ public function testWithDefaultPropertiesPopulatedWithGlobalScopeAndRemoteInterface() { // create default properties $defaultProperties = new Properties(); $defaultProperties->setProperty('indexFile', InitialContextTest::INDEX_FILE); $defaultProperties->setProperty('contextName', InitialContextTest::CONTEXT_NAME); $defaultProperties->setProperty('transport', InitialContextTest::TRANSPORT); // create the initial context initialized with the default properties $this->initialContext->injectProperties($defaultProperties); // populate the identifier with the data of the passed URL $resourceIdentifier = $this->initialContext->prepareResourceIdentifier(InitialContextTest::IDENTIFIER_GLOBAL_REMOTE); // check the data from the resource identifier $this->assertSame(InitialContextTest::INDEX_FILE, $resourceIdentifier->getIndexFile()); $this->assertSame(InitialContextTest::CLASS_NAME, $resourceIdentifier->getClassName()); $this->assertSame(InitialContextTest::CONTEXT_NAME, $resourceIdentifier->getContextName()); $this->assertSame(InitialContextTest::TRANSPORT, $resourceIdentifier->getTransport()); $this->assertSame(EnterpriseBeanResourceIdentifier::REMOTE_INTERFACE, $resourceIdentifier->getInterface()); }
/** * Initializes the connection. * * @param string $appName Name of the webapp using this client connection * @param \AppserverIo\Properties\PropertiesInterface $properties The properties containing the connection parameters */ public function __construct($appName = '', PropertiesInterface $properties = null) { // set the application name $this->appName = $appName; // initialize the message queue parser and the session $this->parser = new MessageQueueParser(); $this->sessions = new \ArrayObject(); // initialize the default properties if no ones has been passed if ($properties == null) { // initialize the default properties $properties = new Properties(); foreach ($this->defaultProperties as $key => $value) { $properties->setProperty($key, $value); } } // inject the properties $this->injectProperties($properties); }
/** * 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); }
/** * @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); }
/** * Test the replaceProperties() method. * * @return void */ public function testReplaceProperties() { // initialize the properties $properties = new Properties(); $properties->setProperty('foo.bar', $propertyValue = 'foo.bar'); // try to replace the variables in the node value's value $this->nodeValue->replaceProperties($properties); // assert that the property has been replaced $this->assertSame(str_replace('${foo.bar}', $propertyValue, $this->constructorValue), $this->nodeValue->getValue()); }
/** * 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; }