/**
  * Tests if the merge of two datasources returns the expected
  * configuration node structure.
  *
  * @return void
  */
 public function testMergeDatasources()
 {
     $configuration = new Configuration();
     $configuration->initFromFile(__DIR__ . '/_files/META-INF/appserver-01-ds.xml');
     $this->configuration->initFromFile(__DIR__ . '/_files/META-INF/appserver-ds.xml');
     $this->configuration->merge($configuration);
     $this->assertCount(2, $this->configuration->getChilds('/datasources/datasource'));
 }
Ejemplo n.º 2
0
 /**
  * Normalizes the passed configuration node and returns a \stdClass
  * representation of it.
  *
  * @param \AppserverIo\Configuration\Interfaces\ConfigurationInterface $configuration The configuration node to normalize
  *
  * @return \stdClass The normalized configuration node
  */
 public function normalize(ConfigurationInterface $configuration)
 {
     // initialize the \stdClass instance
     $node = $this->newInstance('\\stdClass');
     $node->{$configuration->getNodeName()} = new \stdClass();
     // set the node value if available
     if ($value = $configuration->getValue()) {
         $node->{$configuration->getNodeName()}->value = $value;
     }
     // set members by converting camel case to underscore (necessary for ember.js)
     foreach ($configuration->getAllData() as $member => $value) {
         $node->{$configuration->getNodeName()}->{strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $member))} = $value;
     }
     // return the normalized node instance
     return $node;
 }
Ejemplo n.º 3
0
 /**
  * Initializes the node with the value.
  *
  * @param \AppserverIo\Configuration\Interfaces\ConfigurationInterface $configuration The configuration instance
  *
  * @return void
  */
 public function initFromConfiguration(ConfigurationInterface $configuration)
 {
     $this->value = $configuration->getValue();
 }
Ejemplo n.º 4
0
 /**
  * Returns TRUE if the node signatures are equals, else FALSE
  *
  * @param \AppserverIo\Configuration\Interfaces\ConfigurationInterface $configuration The configuration node to check the signature
  *
  * @return boolean TRUE if the signature of the passed node equals the signature of this instance, else FALSE
  */
 public function hasSameSignature(ConfigurationInterface $configuration)
 {
     return $this->getSignature() === $configuration->getSignature();
 }
Ejemplo n.º 5
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));
     }
 }