Esempio n. 1
0
    /**
     * 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;
    }
Esempio n. 2
0
 /**
  * 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);
     }
 }
Esempio n. 3
0
 public function testDocComment()
 {
     $property = new Property('protected', 'visibilities', array('public', 'protected'));
     $property->setDocComment('myDoc');
     $this->assertSame('myDoc', $property->getDocComment());
 }
Esempio n. 4
0
    protected function processColumnsMapping()
    {
        foreach ($this->configClass['columns'] as $name => &$column) {
            if (is_string($column)) {
                $column = array('type' => $column);
            } else {
                if (!is_array($column)) {
                    throw new \RuntimeException(sprintf('The column "%s" is not an string or array.', $name));
                }
                if (!isset($column['type'])) {
                    throw new \RuntimeException(sprintf('The column "%s" does not have type.', $name));
                }
            }
            /*
             * Mapping
             */
            // column
            $fieldMapping = array('fieldName' => $name);
            foreach (array('type', 'length', 'precision', 'scale', 'nullable', 'unique', 'options', 'columnDefinition') as $attribute) {
                if (isset($column[$attribute])) {
                    $fieldMapping[$attribute] = $column[$attribute];
                }
            }
            if (isset($column['name'])) {
                $fieldMapping['columnName'] = $column['name'];
            }
            // identifier
            if (isset($column['id'])) {
                // field
                $fieldMapping['id'] = true;
                // check
                if (is_string($column['id'])) {
                    $column['id'] = array('strategy' => $column['id']);
                } else {
                    if (!is_array($column['id'])) {
                        throw new \RuntimeException(sprintf('The identifier "%s" is not an array or an string.', $name));
                    }
                    if (!isset($column['id']['strategy'])) {
                        throw new \RuntimeException(sprintf('The identifier "%s" does not have strategy.', $name));
                    }
                }
                // strategy
                $strategyUpper = strtoupper($column['id']['strategy']);
                $this->loadMetadataCode[$this->class][] = <<<EOF
        \$metadata->setIdGeneratorType(\\Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_{$strategyUpper});
EOF;
                // sequence
                if ('sequence' == $column['id']['strategy']) {
                    if (!isset($column['id']['sequence'])) {
                        $column['id']['sequence'] = array();
                    }
                    $sequenceMapping = array();
                    if (isset($column['id']['sequence']['name'])) {
                        $sequenceMapping['sequenceName'] = $column['id']['sequence']['name'];
                    }
                    if (isset($column['id']['sequence']['allocationSize'])) {
                        $sequenceMapping['sequenceName'] = $column['id']['sequence']['allocationSize'];
                    }
                    if (isset($column['id']['sequence']['initialValue'])) {
                        $sequenceMapping['sequenceName'] = $column['id']['sequence']['initialValue'];
                    }
                    $sequenceMapping = Dumper::exportArray($sequenceMapping, 12);
                    $this->loadMetadataCode[$this->class][] = <<<EOF
        \$metadata->setSequenceGeneratorDefinition({$sequenceMapping});
EOF;
                }
            }
            // map field
            $fieldMapping = Dumper::exportArray($fieldMapping, 12);
            $this->loadMetadataCode[$this->class][] = <<<EOF
        \$metadata->mapField({$fieldMapping});
EOF;
            /*
             * Property
             */
            $property = new Property('protected', $name, null);
            // default
            if (isset($column['default'])) {
                $property->setValue($column['default']);
            }
            $this->definitions['entity_base']->addProperty($property);
        }
    }