public function testStatic() { $method = new Method('public', 'setVisibility', '$visibility', '$this->visibility = $visibility;'); $this->assertFalse($method->isStatic()); $method->setStatic(true); $this->assertTrue($method->isStatic()); }
/** * 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); } }
protected function processLoadMetadataMethod() { $method = new Method('public', 'loadMetadata', '\\Doctrine\\ORM\\Mapping\\ClassMetadata $metadata', implode("\n", $this->loadMetadataCode[$this->class])); $method->setStatic(true); $method->setDocComment(<<<EOF /** * Load the metadata. * * @param \\Doctrine\\ORM\\Mapping\\ClassMetadata \$metadata The metadata class. */ EOF ); $this->definitions['entity_base']->addMethod($method); }
/** * {@inheritdoc} */ protected function doClassProcess() { $validation = array('constraints' => array(), 'getters' => array()); // constraints if (isset($this->configClass['validation'])) { $validation['constraints'] = $this->configClass['validation']; } // getters // fields foreach ($this->configClass['fields'] as $name => $field) { if (empty($field['inherited']) && isset($field['validation']) && $field['validation']) { $validation['getters'][$name] = $field['validation']; } } // referencesOne foreach ($this->configClass['referencesOne'] as $name => $referenceOne) { if (empty($referenceOne['inherited']) && isset($referenceOne['validation']) && $referenceOne['validation']) { $validation['getters'][$name] = $referenceOne['validation']; } } // referencesMany foreach ($this->configClass['referencesMany'] as $name => $referenceMany) { if (empty($referenceMany['inherited']) && isset($referenceMany['validation']) && $referenceMany['validation']) { $validation['getters'][$name] = $referenceMany['validation']; } } // embeddedsOne foreach ($this->configClass['embeddedsOne'] as $name => $embeddedOne) { if (empty($embeddedOne['inherited']) && isset($embeddedOne['validation']) && $embeddedOne['validation']) { $validation['getters'][$name] = $embeddedOne['validation']; } } // embeddedsMany foreach ($this->configClass['embeddedsMany'] as $name => $embeddedMany) { if (empty($embeddedMany['inherited']) && isset($embeddedMany['validation']) && $embeddedMany['validation']) { $validation['getters'][$name] = $embeddedMany['validation']; } } $validation = Dumper::exportArray($validation, 12); $method = new Method('public', 'loadValidatorMetadata', '\\Symfony\\Component\\Validator\\Mapping\\ClassMetadata $metadata', <<<EOF \$validation = {$validation}; foreach (\\Mandango\\MandangoBundle\\Extension\\DocumentValidation::parseNodes(\$validation['constraints']) as \$constraint) { \$metadata->addConstraint(\$constraint); } foreach (\$validation['getters'] as \$getter => \$constraints) { foreach (\\Mandango\\MandangoBundle\\Extension\\DocumentValidation::parseNodes(\$constraints) as \$constraint) { \$metadata->addGetterConstraint(\$getter, \$constraint); } } return true; EOF ); $method->setStatic(true); $method->setDocComment(<<<EOF /** * Maps the validation. * * @param \\Symfony\\Component\\Validator\\Mapping\\ClassMetadata \$metadata The metadata class. */ EOF ); $this->definitions['document_base']->addMethod($method); }
protected function processQueryBuilderMethod() { $method = new Method('public', 'queryBuilder', '$alias', <<<EOF return static::repository()->createQueryBuilder(\$alias); EOF ); $method->setStatic(true); $method->setDocComment(<<<EOF /** * Create a query builder for this entity name. * * @param string \$alias The alias. * * @return \\Doctrine\\ORM\\QueryBuilder A query builder */ EOF ); $this->definitions['entity_base']->addMethod($method); }