Exemple #1
0
 /**
  * @param string $modelClassName
  * @param Schema $schema
  * @param string $extendedClass
  * @param string $collectionClass
  * @throws Exception
  * @return string
  */
 public function getContent($modelClassName, Schema $schema, $extendedClass = '\\Dive\\Record', $collectionClass = '\\Dive\\Collection\\RecordCollection')
 {
     $usages = array();
     $tableName = $this->getTableName($modelClassName, $schema);
     if ($tableName === null) {
         throw new Exception("no table found for class {$modelClassName}");
     }
     $tableFields = $schema->getTableFields($tableName);
     $fields = array();
     foreach ($tableFields as $key => $tableField) {
         $type = $this->translateType($tableField['type'], $key);
         $fields[] = array($type, $key);
     }
     $tableRelations = $schema->getTableRelations($tableName);
     foreach ($tableRelations as $relationType => $relations) {
         foreach ($relations as $tableRelation) {
             if ($relationType === 'owning') {
                 $key = $tableRelation['refAlias'];
                 $relatedTable = $tableRelation['refTable'];
                 $isOneToOne = true;
             } else {
                 $key = $tableRelation['owningAlias'];
                 $relatedTable = $tableRelation['owningTable'];
                 $isOneToOne = $tableRelation['type'] == Relation::ONE_TO_ONE;
             }
             $relatedRecordClassFull = $schema->getRecordClass($relatedTable);
             $relatedRecordClass = ClassNameExtractor::splitClass($relatedRecordClassFull);
             if ($isOneToOne) {
                 $type = $relatedRecordClass;
             } else {
                 $type = $relatedRecordClass . '[]|' . ClassNameExtractor::splitClass($collectionClass);
                 $usages[] = $collectionClass;
             }
             $fields[] = array($type, $key);
         }
     }
     $this->formatter->setUsages($usages)->setExtendedFrom($extendedClass)->setAnnotations()->setAnnotation('author', $this->author)->setProperties($fields);
     if ($this->createdOn) {
         $this->formatter->setAnnotation('created', $this->createdOn);
     }
     return $this->formatter->getFileContent($modelClassName);
 }
Exemple #2
0
 /**
  * @param string $fullClass
  * @param string $targetDirectory
  * @return string
  */
 public function getTargetFileName($fullClass, $targetDirectory)
 {
     $className = ClassNameExtractor::splitClass($fullClass);
     return $targetDirectory . DIRECTORY_SEPARATOR . $className . '.' . self::FILE_EXTENSION;
 }