Ejemplo n.º 1
0
 /**
  * Handle an event.
  *
  * @param \League\Event\EventInterface $event The triggering event
  *
  * @return void
  * @see \League\Event\ListenerInterface::handle()
  */
 public function handle(EventInterface $event)
 {
     try {
         // load the application server and the naming directory instance
         /** @var \AppserverIo\Appserver\Core\Interfaces\ApplicationServerInterface $applicationServer */
         $applicationServer = $this->getApplicationServer();
         /** @var \AppserverIo\Psr\Naming\NamingDirectoryInterface $namingDirectory */
         $namingDirectory = $applicationServer->getNamingDirectory();
         // initialize configuration and schema file name
         $configurationFileName = $applicationServer->getConfigurationFilename();
         // get an instance of our configuration tester
         $configurationService = new ConfigurationService(new InitialContext(new AppserverNode()));
         // load the parsed system configuration
         /** @var \DOMDocument $doc */
         $doc = $configurationService->loadConfigurationByFilename($configurationFileName);
         // validate the configuration file with the schema
         $configurationService->validateXml($doc, null, true);
         try {
             // query whether we're in configuration test mode or not
             if ($namingDirectory->search('php:env/args/t')) {
                 echo 'Syntax OK' . PHP_EOL;
                 exit(0);
             }
         } catch (NamingException $ne) {
             // do nothing, because we're NOT in configuration test mode
         }
         // initialize the SimpleXMLElement with the content XML configuration file
         $configuration = new Configuration();
         $configuration->initFromString($doc->saveXML());
         // initialize the configuration and the base directory
         $systemConfiguration = new AppserverNode();
         $systemConfiguration->initFromConfiguration($configuration);
         $applicationServer->setSystemConfiguration($systemConfiguration);
     } catch (\Exception $e) {
         // render the validation errors and exit immediately
         echo $e . PHP_EOL;
         exit(0);
     }
 }
Ejemplo n.º 2
0
 /**
  * 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('\\AppserverIo\\Appserver\\Core\\Api\\Node\\DatasourceNode');
         $datasourceNode->initFromConfiguration($datasourceConfiguration);
         $datasourceNodes[$datasourceNode->getPrimaryKey()] = $datasourceNode;
     }
     return $datasourceNodes;
 }
 /**
  * Returns an array with initialized parameters.
  *
  * @return array<\AppserverIo\Appserver\Core\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;
 }
Ejemplo n.º 4
0
 /**
  * Returns a dummy deployment configuration.
  *
  * @return \AppserverIo\Configuration\Configuration A dummy deployment configuration
  */
 public function getDeploymentConfiguration()
 {
     $configuration = new Configuration();
     $configuration->initFromFile(__DIR__ . '/../../../_files/appserver_container_deployment.xml');
     return $configuration;
 }
Ejemplo n.º 5
0
 /**
  * Tests if the initialization from a configuration instance works as expected.
  *
  * @return void
  */
 public function testInitFromConfiguration()
 {
     // initialize the configuration
     $configuration = new Configuration();
     $configuration->initFromFile(__DIR__ . '/_files/location.xml');
     // initialize the location node
     $this->location->setNodeName('location');
     $this->location->initFromConfiguration($configuration);
     // validate the node
     $this->validate();
 }
Ejemplo n.º 6
0
 /**
  * Merges this configuration element with the passed configuration data.
  *
  * @param string $string The string with the XML content to initialize from
  *
  * @return \AppserverIo\Configuration\Interfaces\ConfigurationInterface The configuration created from the passed string
  */
 public function mergeFromString($string)
 {
     // initialize a new configuration instance
     $configuration = new Configuration();
     $configuration->initFromString($string);
     // merge the instance with this one
     $this->merge($configuration);
     // return this instance
     return $configuration;
 }
Ejemplo n.º 7
0
 /**
  * Appends the value of the passed reflection property to the
  * configuration under the also passed path.
  *
  * @param \ReflectionProperty                                          $reflectionProperty The reflection property
  * @param \AppserverIo\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);
         // if we can find it
     } elseif (!empty($token) && empty($next)) {
         // 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));
     }
 }