public function testSetGetOutput() { $output1 = new Output('foo'); $output2 = new Output('bar'); $definition = new Definition('User', $output1); $this->assertSame($output1, $definition->getOutput()); $definition->setOutput($output2); $this->assertSame($output2, $definition->getOutput()); }
/** * 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); } }
private function globalMetadataProcess() { $output = new Output($this->getOption('metadata_factory_output'), true); $definition = new Definition($this->getOption('metadata_factory_class'), $output); $definition->setParentClass('\\Mongator\\MetadataFactory'); $this->definitions['metadata_factory'] = $definition; $output = new Output($this->getOption('metadata_factory_output'), true); $definition = new Definition($this->getOption('metadata_factory_class') . 'Info', $output); $this->definitions['metadata_factory_info'] = $definition; $classes = array(); foreach ($this->configClasses as $class => $configClass) { $classes[$class] = $configClass['isEmbedded']; $info = array(); // general $info['isEmbedded'] = $configClass['isEmbedded']; if (!$info['isEmbedded']) { $info['Mongator'] = $configClass['Mongator']; $info['connection'] = $configClass['connection']; $info['collection'] = $configClass['collection']; } // inheritable $info['inheritable'] = $configClass['inheritable']; // inheritance $info['inheritance'] = $configClass['inheritance']; // fields $info['fields'] = $configClass['fields']; // references $info['_has_references'] = $configClass['_has_references']; $info['referencesOne'] = $configClass['referencesOne']; $info['referencesMany'] = $configClass['referencesMany']; // embeddeds $info['embeddedsOne'] = $configClass['embeddedsOne']; $info['embeddedsMany'] = $configClass['embeddedsMany']; // relations if (!$info['isEmbedded']) { $info['relationsOne'] = $configClass['relationsOne']; $info['relationsManyOne'] = $configClass['relationsManyOne']; $info['relationsManyMany'] = $configClass['relationsManyMany']; $info['relationsManyThrough'] = $configClass['relationsManyThrough']; } // indexes $info['indexes'] = $configClass['indexes']; $info['_indexes'] = $configClass['_indexes']; // data cache $info['cache'] = $configClass['cache']; // behaviors $info['behaviors'] = $configClass['behaviors']; $info = \Mandango\Mondator\Dumper::exportArray($info, 12); $method = new Method('public', 'get' . str_replace('\\', '', $class) . 'Class', '', <<<EOF return {$info}; EOF ); $this->definitions['metadata_factory_info']->addMethod($method); } $property = new Property('protected', 'classes', $classes); $this->definitions['metadata_factory']->addProperty($property); }
protected function processInitDefinitionsAndOutputs() { // classes $classes = array('entity' => $this->class); if (false !== ($pos = strrpos($classes['entity'], '\\'))) { $entityNamespace = substr($classes['entity'], 0, $pos); $entityClassName = substr($classes['entity'], $pos + 1); $classes['entity_base'] = $entityNamespace . '\\Base\\' . $entityClassName; $classes['repository'] = $entityNamespace . '\\' . $entityClassName . 'Repository'; $classes['repository_base'] = $entityNamespace . '\\Base\\' . $entityClassName . 'Repository'; } else { $classes['entity_base'] = 'Base' . $classes['entity']; $classes['repository'] = $classes['entity'] . 'Repository'; $classes['repository_base'] = 'Base' . $classes['entity'] . 'Repository'; } // dir $dir = $this->getOption('default_output'); if (isset($this->configClass['output'])) { $dir = $this->configClass['output']; } if (!$dir) { throw new \RuntimeException(sprintf('The class "%s" does not have output.', $this->class)); } // entity $this->definitions['entity'] = $definition = new Definition($classes['entity'], new Output($dir)); $definition->setParentClass('\\' . $classes['entity_base']); $definition->setDocComment(<<<EOF /** * {$this->class} entity. */ EOF ); // entity_base $this->definitions['entity_base'] = $definition = new Definition($classes['entity_base'], new Output($dir . '/Base', true)); $definition->setAbstract(true); $definition->setDocComment(<<<EOF /** * Base class of the {$this->class} entity. */ EOF ); // repository $this->definitions['repository'] = $definition = new Definition($classes['repository'], new Output($dir)); $definition->setParentClass('\\' . $classes['repository_base']); $definition->setDocComment(<<<EOF /** * Repository of the {$this->class} entity. */ EOF ); // repository_base $this->definitions['repository_base'] = $definition = new Definition($classes['repository_base'], new Output($dir . '/Base', true)); $definition->setAbstract(true); $definition->setParentClass('\\Doctrine\\ORM\\EntityRepository'); $definition->setDocComment(<<<EOF /** * Base class of the repository of the {$this->class} entity. */ EOF ); }