/** * Creates property object * @return Property */ public function create() { $property = new Property($this->visibility, $this->name, null); $property->setDocComment(<<<EOF /** * @var {$this->type} */ EOF ); return $property; }
/** * Twig. */ protected function processTemplate(Definition $definition, $name, array $variables = array()) { $twig = $this->getTwig(); $variables['options'] = $this->options; $variables['class'] = $this->class; $variables['config_class'] = $this->configClass; $variables['config_classes'] = $this->configClasses; $result = $twig->loadTemplate($name)->render($variables); // properties $expression = '/ (?P<docComment>\\ \\ \\ \\ \\/\\*\\*\\n[\\s\\S]*\\ \\ \\ \\ \\ \\*\\/)?\\n? \\ \\ \\ \\ (?P<static>static\\ )? (?P<visibility>public|protected|private) \\s \\$ (?P<name>[a-zA-Z0-9_]+) ; /xU'; preg_match_all($expression, $result, $matches); for ($i = 0; $i <= count($matches[0]) - 1; $i++) { $property = new Property($matches['visibility'][$i], $matches['name'][$i], null); if ($matches['static'][$i]) { $property->setStatic(true); } if ($matches['docComment'][$i]) { $property->setDocComment($matches['docComment'][$i]); } $definition->addProperty($property); } // methods $expression = '/ (?P<docComment>\\ \\ \\ \\ \\/\\*\\*\\n[\\s\\S]*\\ \\ \\ \\ \\ \\*\\/)?\\n \\ \\ \\ \\ (?P<static>static\\ )? (?P<visibility>public|protected|private) \\s function \\s (?P<name>[a-zA-Z0-9_]+) \\((?P<arguments>[$a-zA-Z0-9_\\\\=\\(\\), ]*)\\) \\n \\ \\ \\ \\ \\{ (?P<code>[\\s\\S]*) \\n\\ \\ \\ \\ \\} /xU'; preg_match_all($expression, $result, $matches); for ($i = 0; $i <= count($matches[0]) - 1; $i++) { $code = trim($matches['code'][$i], "\n"); $method = new Method($matches['visibility'][$i], $matches['name'][$i], $matches['arguments'][$i], $code); if ($matches['static'][$i]) { $method->setStatic(true); } if ($matches['docComment'][$i]) { $method->setDocComment($matches['docComment'][$i]); } $definition->addMethod($method); } }
public function testDocComment() { $property = new Property('protected', 'visibilities', array('public', 'protected')); $property->setDocComment('myDoc'); $this->assertSame('myDoc', $property->getDocComment()); }