/**
  * Make a word human readable
  *
  * @param string $string The string to make human readable
  * @return string The human readable string
  */
 public function render($string = NULL)
 {
     if ($string === NULL) {
         $string = $this->renderChildren();
     }
     return $this->inflector->humanize($string);
 }
 /**
  * Pluralize a word
  *
  * @return string The pluralized string
  * @author Christopher Hlubek <*****@*****.**>
  */
 public function render()
 {
     $content = $this->renderChildren();
     $pluralizedContent = $this->inflector->pluralize($content);
     if ($pluralizedContent == $content) {
         $pluralizedContent .= 's';
     }
     return $pluralizedContent;
 }
 /**
  * Singularize a word
  *
  * @return string The pluralized string
  * @author Sebastian Kurfürst <*****@*****.**>
  */
 public function render()
 {
     $content = $this->renderChildren();
     return $this->inflector->singularize($content);
 }
Exemplo n.º 4
0
 /**
  * Removes all related methods, if a property was removed
  * @param Tx_ExtensionBuilder_Domain_Model_DomainObject_AbstractProperty $propertyToRemove
  *
  * @return void
  */
 protected function removePropertyAndRelatedMethods($propertyToRemove)
 {
     $propertyName = $propertyToRemove->getName();
     $this->classObject->removeProperty($propertyName);
     if ($propertyToRemove->isAnyToManyRelation()) {
         $this->classObject->removeMethod('add' . ucfirst(Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName)));
         $this->classObject->removeMethod('remove' . ucfirst(Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName)));
         t3lib_div::devLog('Methods removed: ' . 'add' . ucfirst(Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName)), 'extension_builder');
     }
     $this->classObject->removeMethod('get' . ucfirst($propertyName));
     $this->classObject->removeMethod('set' . ucfirst($propertyName));
     if ($propertyToRemove->isBoolean()) {
         $this->classObject->removeMethod('is' . ucfirst($propertyName));
     }
     t3lib_div::devLog('Methods removed: ' . 'get' . ucfirst($propertyName), 'extension_builder');
 }
 /**
  * Write a simple model class for a non aggregate root domain object with one to one relation
  *
  * @depends checkRequirements
  * @test
  */
 function writeModelClassWithManyToManyRelation()
 {
     $modelName = 'ModelCgt5';
     $relatedModelName = 'relatedModel';
     $propertyName = 'relNames';
     $domainObject = $this->buildDomainObject($modelName);
     $relatedDomainObject = $this->buildDomainObject($relatedModelName);
     $relation = new Tx_ExtensionBuilder_Domain_Model_DomainObject_Relation_ManyToManyRelation($propertyName);
     $relation->setForeignModel($relatedDomainObject);
     $relation->setInlineEditing(false);
     $domainObject->addProperty($relation);
     $classFileContent = $this->codeGenerator->generateDomainObjectCode($domainObject, $this->extension);
     $modelClassDir = 'Classes/Domain/Model/';
     $result = t3lib_div::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';
     t3lib_div::writeFile($modelClassPath, $classFileContent);
     $this->assertFileExists($modelClassPath, 'File was not generated: ' . $modelClassPath);
     $className = $domainObject->getClassName();
     include $modelClassPath;
     $this->assertTrue(class_exists($className), 'Class was not generated:' . $className);
     $reflection = new Tx_ExtensionBuilder_Reflection_ClassReflection($className);
     $this->assertTrue($reflection->hasMethod('add' . ucfirst(Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName))), 'Add method was not generated');
     $this->assertTrue($reflection->hasMethod('remove' . ucfirst(Tx_ExtensionBuilder_Utility_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->assertTrue(strpos($paramTagValues[0], 'Tx_Extbase_Persistence_ObjectStorage<' . $relatedDomainObject->getClassName()) === 0, 'Wrong param tag:' . $paramTagValues[0]);
     $parameters = $setterMethod->getParameters();
     $this->assertTrue(count($parameters) == 1, 'Wrong parameter count in setter method');
     $parameter = current($parameters);
     $this->assertTrue($parameter->getName() == $propertyName, 'Wrong parameter name in setter method');
     $this->assertTrue($parameter->getTypeHint() == 'Tx_Extbase_Persistence_ObjectStorage', 'Wrong type hint for setter parameter:' . $parameter->getTypeHint());
     $addMethod = $reflection->getMethod('add' . ucfirst(Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName)));
     $this->assertTrue($addMethod->isTaggedWith('param'), 'No param tag set for setter method');
     $paramTagValues = $addMethod->getTagValues('param');
     $this->assertTrue(strpos($paramTagValues[0], $relatedDomainObject->getClassName()) === 0, 'Wrong param tag:' . $paramTagValues[0]);
     $parameters = $addMethod->getParameters();
     $this->assertTrue(count($parameters) == 1, 'Wrong parameter count in add method');
     $parameter = current($parameters);
     $this->assertTrue($parameter->getName() == Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName), 'Wrong parameter name in add method');
     $this->assertTrue($parameter->getTypeHint() == $relatedDomainObject->getClassName(), 'Wrong type hint for add method parameter:' . $parameter->getTypeHint());
     $removeMethod = $reflection->getMethod('remove' . ucfirst(Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName)));
     $this->assertTrue($removeMethod->isTaggedWith('param'), 'No param tag set for remove method');
     $paramTagValues = $removeMethod->getTagValues('param');
     $this->assertTrue(strpos($paramTagValues[0], $relatedDomainObject->getClassName()) === 0, 'Wrong param tag:' . $paramTagValues[0]);
     $parameters = $removeMethod->getParameters();
     $this->assertTrue(count($parameters) == 1, 'Wrong parameter count in remove method');
     $parameter = current($parameters);
     $this->assertTrue($parameter->getName() == Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName) . 'ToRemove', 'Wrong parameter name in remove method');
     $this->assertTrue($parameter->getTypeHint() == $relatedDomainObject->getClassName(), 'Wrong type hint for remove method parameter:' . $parameter->getTypeHint());
 }
 /**
  * @test
  */
 public function classBuilderGeneratesMethodsForRelationProperty()
 {
     $modelName2 = 'Model2';
     $propertyName = 'relNames';
     $domainObject1 = $this->buildDomainObject($this->modelName, true, true);
     $relatedDomainObject = $this->buildDomainObject($modelName2);
     $relationProperty = new Tx_ExtensionBuilder_Domain_Model_DomainObject_Relation_ManyToManyRelation($propertyName);
     $relationProperty->setForeignModel($relatedDomainObject);
     $domainObject1->addProperty($relationProperty);
     $modelClassObject = $this->classBuilder->generateModelClassObject($domainObject1);
     $this->assertTrue($modelClassObject->methodExists('add' . ucfirst(Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName))), 'Add method was not generated');
     $this->assertTrue($modelClassObject->methodExists('remove' . ucfirst(Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName))), 'Remove method was not generated');
     $this->assertTrue($modelClassObject->methodExists('set' . ucfirst($propertyName)), 'Setter was not generated');
     $this->assertTrue($modelClassObject->methodExists('set' . ucfirst($propertyName)), 'Setter was not generated');
     $addMethod = $modelClassObject->getMethod('add' . ucfirst(Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName)));
     $this->assertTrue($addMethod->isTaggedWith('param'), 'No param tag set for setter method');
     $paramTagValues = $addMethod->getTagsValues('param');
     $this->assertTrue(strpos($paramTagValues, $relatedDomainObject->getClassName()) === 0, 'Wrong param tag:' . $paramTagValues);
     $parameters = $addMethod->getParameters();
     $this->assertTrue(count($parameters) == 1, 'Wrong parameter count in add method');
     $parameter = current($parameters);
     $this->assertTrue($parameter->getName() == Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName), 'Wrong parameter name in add method');
     $this->assertTrue($parameter->getTypeHint() == $relatedDomainObject->getClassName(), 'Wrong type hint for add method parameter:' . $parameter->getTypeHint());
 }
Exemplo n.º 7
0
 /**
  *
  * @param Tx_ExtensionBuilder_Domain_Model_DomainObject_AbstractProperty $property
  * @param string $methodType (set,add,remove)
  * @return string method body
  */
 public function getParameterName($domainProperty, $methodType)
 {
     $propertyName = $domainProperty->getName();
     switch ($methodType) {
         case 'set':
             return $propertyName;
         case 'add':
             return Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName);
         case 'remove':
             return Tx_ExtensionBuilder_Utility_Inflector::singularize($propertyName) . 'ToRemove';
     }
 }