/**
  * Generate the XML Schema for a given class name.
  *
  * @param string $className Class name to generate the schema for.
  * @param string $namespace Namespace prefix. Used to split off the first parts of the class name.
  * @param \SimpleXMLElement $xmlRootNode XML root node where the xsd:element is appended.
  * @return void
  */
 protected function generateXmlForClassName($className, $namespace, \SimpleXMLElement $xmlRootNode)
 {
     $reflectionClass = new \TYPO3\CMS\Extbase\Reflection\ClassReflection($className);
     if (!$reflectionClass->isSubclassOf($this->abstractViewHelperReflectionClass)) {
         return;
     }
     $tagName = $this->getTagNameForClass($className, $namespace);
     $docbookSection = $xmlRootNode->addChild('section');
     $docbookSection->addChild('title', $tagName);
     $this->docCommentParser->parseDocComment($reflectionClass->getDocComment());
     $this->addDocumentation($this->docCommentParser->getDescription(), $docbookSection);
     $argumentsSection = $docbookSection->addChild('section');
     $argumentsSection->addChild('title', 'Arguments');
     $this->addArguments($className, $argumentsSection);
     return $docbookSection;
 }
Example #2
0
 /**
  * Write a simple model class for a non aggregate root domain object with one to one relation
  *
  * @test
  */
 function writeModelClassWithManyToManyRelation()
 {
     $modelName = 'ModelCgt5';
     $relatedModelName = 'RelatedModel';
     $propertyName = 'relNames';
     $domainObject = $this->buildDomainObject($modelName);
     $relatedDomainObject = $this->buildDomainObject($relatedModelName);
     $relation = new Relation\ManyToManyRelation($propertyName);
     $relation->setForeignModel($relatedDomainObject);
     $relation->setInlineEditing(false);
     $domainObject->addProperty($relation);
     $classFileContent = $this->fileGenerator->generateDomainObjectCode($domainObject, false);
     $modelClassDir = 'Classes/Domain/Model/';
     \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($this->extension->getExtensionDir(), $modelClassDir);
     $absModelClassDir = $this->extension->getExtensionDir() . $modelClassDir;
     $this->assertTrue(is_dir($absModelClassDir), 'Directory ' . $absModelClassDir . ' was not created');
     $modelClassPath = $absModelClassDir . $domainObject->getName() . '.php';
     \TYPO3\CMS\Core\Utility\GeneralUtility::writeFile($modelClassPath, $classFileContent);
     $this->assertFileExists($modelClassPath, 'File was not generated: ' . $modelClassPath);
     $className = $domainObject->getFullQualifiedClassName();
     if (!class_exists($className)) {
         include $modelClassPath;
     }
     $this->assertTrue(class_exists($className), 'Class was not generated:' . $className);
     $reflection = new \TYPO3\CMS\Extbase\Reflection\ClassReflection($className);
     $this->assertTrue($reflection->hasMethod('add' . ucfirst(Inflector::singularize($propertyName))), 'Add method was not generated');
     $this->assertTrue($reflection->hasMethod('remove' . ucfirst(Inflector::singularize($propertyName))), 'Remove method was not generated');
     $this->assertTrue($reflection->hasMethod('get' . ucfirst($propertyName)), 'Getter was not generated');
     $this->assertTrue($reflection->hasMethod('set' . ucfirst($propertyName)), 'Setter was not generated');
     $this->assertTrue($reflection->hasMethod('initStorageObjects'), 'initStorageObjects was not generated');
     //checking methods
     $setterMethod = $reflection->getMethod('set' . ucfirst($propertyName));
     $this->assertTrue($setterMethod->isTaggedWith('param'), 'No param tag set for setter method');
     $paramTagValues = $setterMethod->getTagValues('param');
     $this->assertEquals(0, strpos($paramTagValues[0], '\\TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage<' . $relatedDomainObject->getFullQualifiedClassName()), 'Wrong param tag:' . $paramTagValues[0]);
     $parameters = $setterMethod->getParameters();
     $this->assertEquals(1, count($parameters), 'Wrong parameter count in setter method');
     $parameter = current($parameters);
     $this->assertEquals($parameter->getName(), $propertyName, 'Wrong parameter name in setter method');
     $addMethod = $reflection->getMethod('add' . ucfirst(Inflector::singularize($propertyName)));
     $this->assertTrue($addMethod->isTaggedWith('param'), 'No param tag set for setter method');
     $paramTagValues = $addMethod->getTagValues('param');
     $this->assertEquals(0, strpos($paramTagValues[0], $relatedDomainObject->getFullQualifiedClassName()), 'Wrong param tag:' . $paramTagValues[0]);
     $parameters = $addMethod->getParameters();
     $this->assertEquals(1, count($parameters), 'Wrong parameter count in add method');
     $parameter = current($parameters);
     $this->assertEquals($parameter->getName(), Inflector::singularize($propertyName), 'Wrong parameter name in add method');
     $removeMethod = $reflection->getMethod('remove' . ucfirst(Inflector::singularize($propertyName)));
     $this->assertTrue($removeMethod->isTaggedWith('param'), 'No param tag set for remove method');
     $paramTagValues = $removeMethod->getTagValues('param');
     $this->assertEquals(0, strpos($paramTagValues[0], $relatedDomainObject->getFullQualifiedClassName()), 'Wrong param tag:' . $paramTagValues[0]);
     $parameters = $removeMethod->getParameters();
     $this->assertEquals(1, count($parameters), 'Wrong parameter count in remove method');
     $parameter = current($parameters);
     $this->assertEquals($parameter->getName(), Inflector::singularize($propertyName) . 'ToRemove', 'Wrong parameter name in remove method');
 }
 /**
  * Reflects the given class and stores the results in this service's properties.
  *
  * @param string $className Full qualified name of the class to reflect
  * @return void
  */
 protected function reflectClass($className)
 {
     $class = new \TYPO3\CMS\Extbase\Reflection\ClassReflection($className);
     $this->reflectedClassNames[$className] = time();
     foreach ($class->getTagsValues() as $tag => $values) {
         if (array_search($tag, $this->ignoredTags) === FALSE) {
             $this->taggedClasses[$tag][] = $className;
             $this->classTagsValues[$className][$tag] = $values;
         }
     }
     foreach ($class->getProperties() as $property) {
         $propertyName = $property->getName();
         $this->classPropertyNames[$className][] = $propertyName;
         foreach ($property->getTagsValues() as $tag => $values) {
             if (array_search($tag, $this->ignoredTags) === FALSE) {
                 $this->propertyTagsValues[$className][$propertyName][$tag] = $values;
             }
         }
     }
     foreach ($class->getMethods() as $method) {
         $methodName = $method->getName();
         foreach ($method->getTagsValues() as $tag => $values) {
             if (array_search($tag, $this->ignoredTags) === FALSE) {
                 $this->methodTagsValues[$className][$methodName][$tag] = $values;
             }
         }
         foreach ($method->getParameters() as $parameterPosition => $parameter) {
             $this->methodParameters[$className][$methodName][$parameter->getName()] = $this->convertParameterReflectionToArray($parameter, $parameterPosition, $method);
         }
     }
     ksort($this->reflectedClassNames);
     $this->dataCacheNeedsUpdate = TRUE;
 }