예제 #1
0
 private function getRestDirHelper(EntityClass $entitlyClass)
 {
     $namespace = $entitlyClass->getClassMetadata()->namespace;
     if (preg_match('/entity/i', $namespace)) {
         $restDir = str_ireplace('entity', 'Controller\\Rest', $namespace);
     } else {
         $a = explode('\\', $namespace);
         $b = array_merge(array_slice($a, 0, 1), array('Controller', 'Rest'), array_slice($a, 2));
         $restDir = implode('\\', $b);
     }
     return $restDir;
 }
 private function getMethodGetAll()
 {
     $entityModel = new EntityModel();
     $entityWrapper = $this->getEntityClass();
     $entityModel->setSingularName(lcfirst($entityWrapper->getSingluarName()));
     $entityModel->setPlurarName(lcfirst($entityWrapper->getPluralName()));
     $entityModel->setFullName('\\' . $entityWrapper->getFullName());
     $repo = $this->getDoctrine()->getRepository($entityWrapper->getFullName());
     $entityModel->setRepoName('\\' . get_class($repo));
     $entityModel->setColumns($this->getColumns($entityWrapper));
     $entityModel->setMapping($this->getAssociationMappings($entityWrapper));
     $code = '<?php ' . PHP_EOL;
     $code .= $this->getTwig()->render('SoftflyGeneratorBundle:Rest:findAll.html.twig', $entityModel->toArray());
     $stmts = $this->parseCode($code);
     return $this->getFactory()->method('get' . ucfirst($this->entityClass->getPluralName()) . 'Action')->makePublic()->addStmts($stmts);
 }
 private function getAssociationMappings(EntityClass $entityWrapper, $ignore = null)
 {
     if ($this->depth >= $this->max_depth) {
         return array();
     } else {
         $this->depth++;
         $mappings = array();
         foreach ($entityWrapper->getClassMetadata()->getAssociationMappings() as $column) {
             if ($ignore != $column['fieldName']) {
                 $mappingModel = new AssociationMappingModel();
                 $entityWrapper2 = new EntityClass($column['targetEntity'], $this->getEm());
                 $mappingModel->setSingularName(lcfirst($entityWrapper2->getSingluarName()));
                 $mappingModel->setFullName('\\' . $entityWrapper2->getFullName());
                 $mappingModel->setGetMethod('get' . ucfirst($this->camelize($column['fieldName'])));
                 $mappingModel->setMapType($column['type']);
                 $mappingModel->setDepth($this->depth);
                 $mappingModel->setColumns($this->getColumns($entityWrapper2, $column['mappedBy']));
                 $mappingModel->setMapping($this->getAssociationMappings($entityWrapper2, $column['mappedBy']));
                 $mappings[] = $mappingModel;
             }
         }
         $this->depth--;
         return $mappings;
     }
 }