Ejemplo n.º 1
0
 /**
  * @test
  */
 public function createClassWithProperties()
 {
     $newClassFileObject = new Tx_PhpParser_Domain_Model_File();
     $newClassName = 'Tx_PhpParser_Test_NewClassWithProperties';
     $newProperty1 = new Tx_PhpParser_Domain_Model_Class_Property('property1');
     $newProperty1->setDescription('example property2')->setValue('example')->setTag('var', 'string $property1');
     $newProperty2 = new Tx_PhpParser_Domain_Model_Class_Property('property2');
     $newProperty2->setDescription('example property2')->setValue(array('test' => 123))->setTag('var', 'array $property2')->setModifier('private');
     $newClass = new Tx_PhpParser_Domain_Model_Class($newClassName);
     $newClass->setDescription("This is a class created\nfrom scratch")->setTag('author', 'John Doe')->setProperty($newProperty1)->setProperty($newProperty2);
     $newClassFileObject->addClass($newClass);
     $newClassFilePath = $this->testDir . 'NewClassWithProperties.php';
     t3lib_div::writeFile($newClassFilePath, "<?php\n\n" . $this->printer->renderFileObject($newClassFileObject) . "\n?>");
     $this->compareClasses($newClassFileObject, $newClassFilePath);
 }
Ejemplo n.º 2
0
 public function buildPropertyObjectFromNode(PHPParser_Node_Stmt_Property $propertyNode)
 {
     $propertyName = '';
     $propertyDefault = NULL;
     foreach ($propertyNode->getProps() as $subNode) {
         if ($subNode instanceof PHPParser_Node_Stmt_PropertyProperty) {
             $propertyName = $subNode->getName();
             if ($subNode->getDefault()) {
                 $propertyDefault = $subNode->getDefault();
             }
         }
     }
     $propertyObject = new Tx_PhpParser_Domain_Model_Class_Property($propertyName);
     $propertyObject->setModifiers($propertyNode->getType());
     $propertyObject->setNode($propertyNode);
     $propertyObject->initDocComment();
     if (NULL !== $propertyDefault) {
         $propertyObject->setValue(Tx_PhpParser_Parser_Utility_NodeConverter::getValueFromNode($propertyDefault), FALSE, $propertyObject->isTaggedWith('var'));
     }
     return $propertyObject;
 }
Ejemplo n.º 3
0
 /**
  * add a property (returns TRUE if successfull added)
  *
  * @param Tx_PhpParser_Domain_Model_Class_Property $classProperty
  * @return boolean success
  */
 public function addProperty(Tx_PhpParser_Domain_Model_Class_Property $classProperty)
 {
     if (!$this->propertyExists($classProperty->getName())) {
         $this->propertyNames[] = $classProperty->getName();
         $this->properties[$classProperty->getName()] = $classProperty;
         return TRUE;
     } else {
         return FALSE;
     }
 }