/**
  * Will insert a structure definition into our hierarchy
  *
  * @param \AppserverIo\Doppelgaenger\Interfaces\StructureDefinitionInterface $node The structure definition to insert
  *
  * @return bool
  */
 public function insert(StructureDefinitionInterface $node)
 {
     // Already here? Nothing to do then
     $qualifiedName = $node->getQualifiedName();
     if (!empty($this->nodes[$qualifiedName])) {
         return true;
     }
     // Add the node
     $this->nodes[$qualifiedName] = $node;
     // Add empty entries for the dependencies so we can check if all where added
     $dependencies = $node->getDependencies();
     foreach ($dependencies as $dependency) {
         if (!empty($this->nodes[$dependency])) {
             continue;
         } else {
             $this->nodes[$dependency] = null;
         }
     }
     // Still here? Sounds great
     return true;
 }
 /**
  * Will check if a certain structure was mentioned in one(!) use statement.
  *
  * @param StructureDefinitionInterface $structureDefinition The structure $structureName is compared against
  * @param string                       $structureName       The name of the structure we have to check against the
  *                                                          use statements of the definition
  *
  * @return string
  */
 protected function resolveUsedNamespace(StructureDefinitionInterface &$structureDefinition, $structureName)
 {
     // If there was no useful name passed we can fail right here
     if (empty($structureName)) {
         return '';
     }
     // Walk over all namespaces and if we find something we will act accordingly.
     $result = $structureDefinition->getQualifiedName();
     foreach ($structureDefinition->getUsedStructures() as $key => $usedStructures) {
         // Check if the last part of the use statement is our structure
         $tmp = explode('\\', $usedStructures);
         if (array_pop($tmp) === $structureName) {
             // Tell them we succeeded
             return trim(implode('\\', $tmp) . '\\' . $structureName, '\\');
         }
     }
     // We did not seem to have found anything. Might it be that we are in our own namespace?
     if ($structureDefinition->getNamespace() !== null && strpos($structureName, '\\') !== 0) {
         return $structureDefinition->getNamespace() . '\\' . $structureName;
     }
     // Still here? Return what we got.
     return $result;
 }
 /**
  * Will substitute all function headers (we know about) with function headers indicating an original implementation by appending
  * a specific suffix
  *
  * @param string                                                             $bucketData          Payload of the currently filtered bucket
  * @param \AppserverIo\Doppelgaenger\Interfaces\StructureDefinitionInterface $structureDefinition The original path we have to place as our constants
  *
  * @return boolean
  */
 protected function substituteFunctionHeaders(&$bucketData, StructureDefinitionInterface $structureDefinition)
 {
     // is there event anything to substitute?
     if ($structureDefinition->getFunctionDefinitions()->count() <= 0) {
         return true;
     }
     // first of all we have to collect all functions we have to substitute
     $functionSubstitutes = array();
     $functionPatterns = array();
     foreach ($structureDefinition->getFunctionDefinitions() as $functionDefinition) {
         // we do not have to act on abstract methods
         if ($functionDefinition->isAbstract()) {
             continue;
         }
         $functionPatterns[] = '/function\\s' . $functionDefinition->getName() . '\\s*\\(/';
         $functionSubstitutes[] = 'function ' . $functionDefinition->getName() . ReservedKeywords::ORIGINAL_FUNCTION_SUFFIX . '(';
     }
     // do the actual replacing and propagate the result in success
     $result = preg_replace($functionPatterns, $functionSubstitutes, $bucketData);
     if (!is_null($result)) {
         $bucketData = $result;
         return true;
     }
     // still here? That seems to be wrong
     return false;
 }