Пример #1
0
    protected function initDefinitionsProcess()
    {
        $classes = array('document' => $this->class);
        if (false !== ($pos = strrpos($classes['document'], '\\'))) {
            $documentNamespace = substr($classes['document'], 0, $pos);
            $documentClassName = substr($classes['document'], $pos + 1);
            $classes['document_base'] = $documentNamespace . '\\Base\\' . $documentClassName;
            $classes['repository'] = $documentNamespace . '\\' . $documentClassName . 'Repository';
            $classes['repository_base'] = $documentNamespace . '\\Base\\' . $documentClassName . 'Repository';
            $classes['query'] = $documentNamespace . '\\' . $documentClassName . 'Query';
            $classes['query_base'] = $documentNamespace . '\\Base\\' . $documentClassName . 'Query';
        } else {
            $classes['document_base'] = 'Base' . $classes['document'];
            $classes['repository'] = $classes['document'] . 'Repository';
            $classes['repository_base'] = 'Base' . $classes['document'] . 'Repository';
            $classes['query'] = $classes['document'] . 'Query';
            $classes['query_base'] = 'Base' . $classes['document'] . 'Query';
        }
        // document
        $dir = $this->getOption('default_output');
        if (isset($this->configClass['output'])) {
            $dir = $this->configClass['output'];
        }
        if (!$dir) {
            throw new \RuntimeException(sprintf('The document of the class "%s" does not have output.', $this->class));
        }
        $output = new Output($dir);
        $this->definitions['document'] = $definition = new Definition($classes['document'], $output);
        $definition->setParentClass('\\' . $classes['document_base']);
        $definition->setDocComment(<<<EOF
/**
 * {$this->class} document.
 */
EOF
);
        // document base
        $output = new Output($this->definitions['document']->getOutput()->getDir(), true);
        $this->definitions['document_base'] = $definition = new Definition($classes['document_base'], $output);
        $definition->setAbstract(true);
        if ($this->configClass['isEmbedded']) {
            $definition->setParentClass('\\Mongator\\Document\\EmbeddedDocument');
        } else {
            if ($this->configClass['inheritance']) {
                $definition->setParentClass('\\' . $this->configClass['inheritance']['class']);
            } else {
                $definition->setParentClass('\\Mongator\\Document\\Document');
            }
        }
        $definition->setDocComment(<<<EOF
/**
 * Base class of {$this->class} document.
 */
EOF
);
        if (!$this->configClass['isEmbedded']) {
            // repository
            $dir = $this->getOption('default_output');
            if (isset($this->configClass['output'])) {
                $dir = $this->configClass['output'];
            }
            if (!$dir) {
                throw new \RuntimeException(sprintf('The repository of the class "%s" does not have output.', $this->class));
            }
            $output = new Output($dir);
            $this->definitions['repository'] = $definition = new Definition($classes['repository'], $output);
            $definition->setParentClass('\\' . $classes['repository_base']);
            $definition->setDocComment(<<<EOF
/**
 * Repository of {$this->class} document.
 */
EOF
);
            // repository base
            $output = new Output($this->definitions['repository']->getOutput()->getDir(), true);
            $this->definitions['repository_base'] = $definition = new Definition($classes['repository_base'], $output);
            $definition->setAbstract(true);
            $definition->setParentClass('\\Mongator\\Repository');
            $definition->setDocComment(<<<EOF
/**
 * Base class of repository of {$this->class} document.
 */
EOF
);
            // query
            $dir = $this->getOption('default_output');
            if (isset($this->configClass['output'])) {
                $dir = $this->configClass['output'];
            }
            if (!$dir) {
                throw new \RuntimeException(sprintf('The query of the class "%s" does not have output.', $this->class));
            }
            $output = new Output($dir);
            $this->definitions['query'] = $definition = new Definition($classes['query'], $output);
            $definition->setParentClass('\\' . $classes['query_base']);
            $definition->setDocComment(<<<EOF
/**
 * Query of {$this->class} document.
 */
EOF
);
            // query
            $output = new Output($this->definitions['query']->getOutput()->getDir(), true);
            $this->definitions['query_base'] = $definition = new Definition($classes['query_base'], $output);
            $definition->setAbstract(true);
            if ((int) $this->configClass['cache'] > 0) {
                $definition->setParentClass('\\Mongator\\Query\\CachedQuery');
            } else {
                $definition->setParentClass('\\Mongator\\Query\\Query');
            }
            $definition->setDocComment(<<<EOF
/**
 * Base class of query of {$this->class} document.
 */
EOF
);
        }
    }
Пример #2
0
    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
);
    }