Esempio n. 1
0
 /**
  * Will create an altered definition of the structure defined in the $mapEntry variable.
  * Will also add it to the cache map
  *
  * @param \TechDivision\PBC\Entities\Definitions\Structure $mapEntry        Entry of a StructureMap we want created
  * @param boolean                                          $createRecursive If contract inheritance is enabled
  *
  * @throws \TechDivision\PBC\Exceptions\GeneratorException
  *
  * @return boolean
  */
 public function create(Structure $mapEntry, $createRecursive = false)
 {
     // We know what we are searching for and we got a fine factory so lets get us a parser
     $structureParserFactory = new StructureParserFactory();
     $parser = $structureParserFactory->getInstance($mapEntry->getType(), $mapEntry->getPath(), $this->config, $this->structureMap, $this->structureDefinitionHierarchy);
     // Lets get the definition we are looking for
     $structureDefinition = $parser->getDefinition($mapEntry->getIdentifier(), $createRecursive);
     if (!$structureDefinition instanceof StructureDefinitionInterface) {
         return false;
     }
     $qualifiedName = $structureDefinition->getQualifiedName();
     $filePath = $this->createFilePath($qualifiedName, $mapEntry->getPath());
     $tmp = $this->createFileFromDefinition($filePath, $structureDefinition);
     if ($tmp === false) {
         throw new GeneratorException('Could not create contracted definition for ' . $qualifiedName);
     }
     // Now get our new file into the cacheMap
     $this->cache->add(new Structure(filectime($mapEntry->getPath()), $qualifiedName, $filePath, $structureDefinition->getType()));
     // Still here? Than everything worked out great.
     return true;
 }
 /**
  * This method will add all assertions any ancestral structures (parent classes, implemented interfaces) might have
  * to the passed class definition.
  *
  * @param \TechDivision\PBC\Entities\Definitions\FunctionDefinition $functionDefinition The function definition
  *                                                                                      we are working on
  *
  * @return void
  */
 protected function addAncestralAssertions(FunctionDefinition $functionDefinition)
 {
     $dependencies = $this->currentDefinition->getDependencies();
     foreach ($dependencies as $dependency) {
         // freshly set the dependency definition to avoid side effects
         $dependencyDefinition = null;
         $fileEntry = $this->structureMap->getEntry($dependency);
         if (!$fileEntry instanceof Structure) {
             // Continue, don't fail as we might have dependencies which are not under PBC surveillance
             continue;
         }
         // Get the needed parser
         $structureParserFactory = new StructureParserFactory();
         $parser = $structureParserFactory->getInstance($fileEntry->getType(), $fileEntry->getPath(), $this->config, $this->structureMap, $this->structureDefinitionHierarchy);
         // Get the definition
         $dependencyDefinition = $parser->getDefinition($dependency, true);
         // Get the function definitions of the dependency structure
         $dependencyFunctionDefinitions = $dependencyDefinition->getFunctionDefinitions();
         // If we have a method with the name of the current one we have to get the conditions as ancestrals
         if ($dependencyFunctionDefinitions->entryExists($functionDefinition->getName())) {
             // Get the definition
             $dependencyFunctionDefinition = $dependencyFunctionDefinitions->get($functionDefinition->getName());
             // If the ancestral function uses the old keyword we have to do too
             if ($dependencyFunctionDefinition->getUsesOld() !== false) {
                 $functionDefinition->usesOld = true;
             }
             // Get the conditions
             $functionDefinition->ancestralPreconditions = $dependencyFunctionDefinition->getAllPreconditions(true);
             $functionDefinition->ancestralPostconditions = $dependencyFunctionDefinition->getAllPostconditions(true);
         }
     }
 }
 /**
  * This method will add all assertions any ancestral structures (parent classes, implemented interfaces) might have
  * to the passed class definition.
  *
  * @param \TechDivision\PBC\Entities\Definitions\ClassDefinition $classDefinition The class definition we have to
  *                                                                                add the assertions to
  *
  * @return null
  */
 protected function addAncestralAssertions(ClassDefinition $classDefinition)
 {
     $dependencies = $classDefinition->getDependencies();
     foreach ($dependencies as $dependency) {
         // freshly set the dependency definition to avoid side effects
         $dependencyDefinition = null;
         $fileEntry = $this->structureMap->getEntry($dependency);
         if (!$fileEntry instanceof Structure) {
             // Continue, don't fail as we might have dependencies which are not under PBC surveillance
             continue;
         }
         // Get the needed parser
         $structureParserFactory = new StructureParserFactory();
         $parser = $structureParserFactory->getInstance($fileEntry->getType(), $fileEntry->getPath(), $this->config, $this->structureMap, $this->structureDefinitionHierarchy);
         // Get the definition
         $dependencyDefinition = $parser->getDefinition($dependency, true);
         // Only classes and traits have invariants
         if ($fileEntry->getType() === 'class') {
             $classDefinition->ancestralInvariants = $dependencyDefinition->getInvariants(true);
         }
         // Finally add the dependency definition to our structure definition hierarchy to avoid
         // redundant parsing
         $this->structureDefinitionHierarchy->insert($dependencyDefinition);
     }
 }