コード例 #1
0
ファイル: Core.php プロジェクト: srggroup/mongator
    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);
    }
コード例 #2
0
ファイル: Core.php プロジェクト: keeguon/doctrator
    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
);
    }