/** * Returns an array with initialized parameters. * * @return array<\TechDivision\ApplicationServer\Api\Node\ParamNode> The array with params */ public function getParamNodes() { $configuration = new Configuration(); $configuration->initFromFile(__DIR__ . '/_files/params.xml'); $params = array(); foreach ($configuration->getChilds('/params/param') as $paramConfiguration) { $paramNode = new ParamNode(); $paramNode->initFromConfiguration($paramConfiguration); $params[$paramNode->getName()] = $paramNode; } return $params; }
/** * Test the server's start method. * * @return void */ public function testStart() { // initialize the configuration $configuration = $this->getAppserverConfiguration(); // replace the base directory $appserverConfiguration = new Configuration(); $appserverConfiguration->setNodeName('appserver'); $baseDirectoryConfiguration = new Configuration(); $baseDirectoryConfiguration->setNodeName('baseDirectory'); $baseDirectoryConfiguration->setValue(__DIR__); $appserverConfiguration->addChild($baseDirectoryConfiguration); $configuration->merge($appserverConfiguration); // create a new mock server implementation $server = $this->getMock('TechDivision\\ApplicationServer\\Server', array('startContainers'), array($configuration)); // mock the servers start method $server->expects($this->once())->method('startContainers'); // start the server instance $server->start(); // check that we found the configured container $this->assertCount(1, $server->getContainers()); }
/** * Returns a dummy deployment configuration. * * @return \TechDivision\Configuration\Configuration A dummy deployment configuration */ public function getDeploymentConfiguration() { $configuration = new Configuration(); $configuration->initFromFile(__DIR__ . '/../../_files/appserver_container_deployment.xml'); return $configuration; }
/** * Merges this configuration element with the passed configuration data. * * @param string $string The string with the XML content to initialize from * * @return \TechDivision\Configuration\Interfaces\ConfigurationInterface The configuration created from the passed string */ public function mergeFromString($string) { // initialize a new configutation instance $configuration = new Configuration(); $configuration->loadFromString($string); // merge the instance with this one $this->merge($configuration); // return this instance return $configuration; }
/** * Appends the value of the passed reflection property to the * configuration under the also passed path. * * @param \ReflectionProperty $reflectionProperty The reflection property * @param \TechDivision\Configuration\Interfaces\ConfigurationInterface $configuration The configuration instance * @param string $path A path were to append to * * @return void * @throws \Exception */ public function appendConfigurationChild(\ReflectionProperty $reflectionProperty, ConfigurationInterface $configuration, $path) { // tokenize the we want to append the configuration $token = strtok($path, '/'); $next = substr($path, strlen('/' . $token)); // if we can't find the specified path in that instance if (!empty($token) && !empty($next)) { // initialize the configuration value $child = new Configuration(); $child->setNodeName($token); // add it to this instance $this->appendConfigurationChild($reflectionProperty, $child, $next); // and also add it to the passed configuration $configuration->addChild($child); } elseif (!empty($token) && empty($next)) { // if we can find it // only add it the the passed configuration foreach ($this->{$reflectionProperty->getName()} as $node) { $configuration->addChild($node->exportToConfiguration()); } } else { // or throw an exception if the passed path is not valid throw new \Exception(sprintf('Found invalid path %s', $path)); } }
/** * Creates an array with datasources found in the configuration * file with the passed name. * * @param string $filename The filename to initialize the datasources from * @param string $containerName The name of the container the datasource can be used in * * @return array */ public function initFromFile($filename, $containerName = '') { // initialize the configuration and load the data from the passed file $configuration = new Configuration(); $configuration->initFromFile($filename); // iterate over the found datasources, append them to the array and return the array $datasourceNodes = array(); foreach ($configuration->getChilds('/datasources/datasource') as $datasourceConfiguration) { // Add the information about the container name here $datasourceConfiguration->appendData(array('containerName' => $containerName)); // Instantiate the datasource node using the configuration $datasourceNode = $this->newInstance('\\TechDivision\\ApplicationServer\\Api\\Node\\DatasourceNode'); $datasourceNode->initFromConfiguration($datasourceConfiguration); $datasourceNodes[$datasourceNode->getPrimaryKey()] = $datasourceNode; } return $datasourceNodes; }