コード例 #1
0
 public function testValidManagerWhenInvalidProperty()
 {
     $properties = $this->classManager->getProperties();
     $properties->add(new PropertyManager($this->classManager));
     // broken property
     $this->classManager->setProperties($properties);
     $errors = $this->getValidator()->validate($this->classManager);
     $this->assertEquals(4, $errors->count());
 }
コード例 #2
0
 /**
  * Get properties to render in item file
  *
  * @param ClassManager $item
  * @param ReflectionClass $reflectionClass
  * @return ArrayCollection
  */
 protected function resolvePropertiesToRender(ClassManager $item, ReflectionClass $reflectionClass)
 {
     $propertiesToRender = new ArrayCollection();
     foreach ($item->getProperties() as $itemProperty) {
         $found = false;
         foreach ($reflectionClass->getProperties() as $reflectionProperty) {
             if ($itemProperty->getPreparedName() == $reflectionProperty->name) {
                 $found = true;
                 break;
             }
         }
         if (false == $found) {
             $propertiesToRender->add($itemProperty);
         }
     }
     return $propertiesToRender;
 }
コード例 #3
0
 /**
  * @param ClassManager $class
  * @return string
  * @throws RendererException
  */
 protected function renderClass(ClassManager $class)
 {
     $template = $class->getTemplate();
     $tags = $class->getTemplateTags();
     $properties = [];
     $methods = [];
     $interfacePart = '';
     $extendsPart = '';
     foreach ($class->getProperties() as $property) {
         $properties[] = $this->render($property);
     }
     foreach ($class->getMethods() as $method) {
         $methods[] = $this->render($method);
     }
     if ($class->hasExtends()) {
         $extendsPart = sprintf(" extends %s", $class->getExtends());
     }
     if ($class->hasInterface()) {
         $interfacePart = sprintf(" implements %s", $class->getInterface()->getNamespace());
     }
     $args[RenderableInterface::TAG_NAMESPACE] = $class->getNamespaceWithoutNameAndBackslashPrefix();
     $args[RenderableInterface::TAG_COMMENT] = empty($class->getComment()) ? "" : sprintf(" %s", $class->getComment());
     $args[RenderableInterface::TAG_NAME] = $class->getName();
     $args[RenderableInterface::TAG_EXTENDS] = $extendsPart;
     $args[RenderableInterface::TAG_INTERFACE] = $interfacePart;
     $args[RenderableInterface::TAG_CONSTRUCTOR] = $this->render($class->getConstructor());
     $args[RenderableInterface::TAG_PROPERTIES] = Tools::implodeArrayToTemplate($properties);
     $args[RenderableInterface::TAG_METHODS] = Tools::implodeArrayToTemplate($methods);
     $args[RenderableInterface::TAG_MULTILINE_COMMENT] = $this->prepareMultilineCommentForElement($class);
     return $this->addNewLineAfter($this->replace($tags, $args, $template));
 }
コード例 #4
0
 /**
  * Generate class components
  * - setters and getters for Class and Interface (optional)
  * - method with prefix is for boolean properties
  *
  * @param \HelloWordPl\SimpleEntityGeneratorBundle\Lib\ClassManager $classManager
  */
 protected function generateAndFillClassMethods(ClassManager $classManager)
 {
     $methodsForClass = new ArrayCollection();
     // fix - jms serializer does not call ClassManager constructor during deserialization
     if (false == $classManager->getProperties() instanceof ArrayCollection) {
         $classManager->setProperties(new ArrayCollection());
     }
     foreach ($classManager->getProperties() as $property) {
         if ($property->isTypeBoolean()) {
             $methodsForClass->add((new MethodGetterBooleanManager($classManager))->setProperty($property));
         }
         $methodSetterManager = new MethodSetterManager($classManager);
         $methodSetterManager->setProperty($property);
         $methodGetterManager = new MethodGetterManager($classManager);
         $methodGetterManager->setProperty($property);
         $methodsForClass->add($methodSetterManager);
         $methodsForClass->add($methodGetterManager);
     }
     $classManager->setMethods($methodsForClass);
     return $classManager;
 }