Example #1
0
 /**
  * Build a form based on the given table.
  * 
  * @param BundleInterface $bundle
  * @param Table           $table
  * @param string          $formTypeNamespace
  *
  * @return string
  */
 public function buildFormType(BundleInterface $bundle, Table $table, $formTypeNamespace)
 {
     $modelName = $table->getPhpName();
     $formTypeContent = file_get_contents(__DIR__ . '/../Resources/skeleton/FormType.php');
     $formTypeContent = str_replace('##NAMESPACE##', $bundle->getNamespace() . str_replace('/', '\\', $formTypeNamespace), $formTypeContent);
     $formTypeContent = str_replace('##CLASS##', $modelName . 'Type', $formTypeContent);
     $formTypeContent = str_replace('##FQCN##', sprintf('%s\\%s', $table->getNamespace(), $modelName), $formTypeContent);
     $formTypeContent = str_replace('##TYPE_NAME##', strtolower($modelName), $formTypeContent);
     $formTypeContent = str_replace('##BUILD_CODE##', $this->buildFormFields($table), $formTypeContent);
     return $formTypeContent;
 }
Example #2
0
 /**
  * Computes the table namespace based on the current relative or
  * absolute table namespace and the database namespace.
  *
  * @param  Table  $table
  * @return string
  */
 private function computeTableNamespace(Table $table)
 {
     $namespace = $table->getNamespace();
     if ($this->isAbsoluteNamespace($namespace)) {
         $namespace = ltrim($namespace, '\\');
         $table->setNamespace($namespace);
         return $namespace;
     }
     if ($namespace = $this->getNamespace()) {
         if ($table->getNamespace()) {
             $namespace .= '\\' . $table->getNamespace();
         }
         $table->setNamespace($namespace);
     }
     return $namespace;
 }
Example #3
0
 /**
  * This declares the class use and returns the correct name to use
  *
  * @param Table $table
  * @param bool $fqcn
  * @return string
  */
 public function getClassNameFromTable(Table $table, $fqcn = false)
 {
     $namespace = $table->getNamespace();
     $class = $table->getPhpName();
     return $this->declareClassNamespace($class, $namespace, true);
 }
 /**
  * @dataProvider provideNamespaces
  *
  */
 public function testSetNamespace($namespace, $expected)
 {
     $table = new Table();
     $table->setNamespace($namespace);
     $this->assertSame($expected, $table->getNamespace());
 }
Example #5
0
 /**
  * Appends the generated <table> XML node to its parent node.
  *
  * @param Table    $table      The Table model instance
  * @param \DOMNode $parentNode The parent DOMNode object
  */
 private function appendTableNode(Table $table, \DOMNode $parentNode)
 {
     $tableNode = $parentNode->appendChild($this->document->createElement('table'));
     $tableNode->setAttribute('name', $table->getCommonName());
     $database = $table->getDatabase();
     $schema = $table->getSchema();
     if ($schema && $schema !== $database->getSchema()) {
         $tableNode->setAttribute('schema', $schema);
     }
     if (IdMethod::NO_ID_METHOD !== ($idMethod = $table->getIdMethod())) {
         $tableNode->setAttribute('idMethod', $idMethod);
     }
     if ($phpName = $table->getPhpName()) {
         $tableNode->setAttribute('phpName', $phpName);
     }
     $package = $table->getPackage();
     if ($package && !$table->isPackageOverriden()) {
         $tableNode->setAttribute('package', $package);
     }
     if ($namespace = $table->getNamespace()) {
         $tableNode->setAttribute('namespace', $namespace);
     }
     if ($table->isSkipSql()) {
         $tableNode->setAttribute('skipSql', 'true');
     }
     if ($table->isAbstract()) {
         $tableNode->setAttribute('abstract', 'true');
     }
     if ($interface = $table->getInterface()) {
         $tableNode->setAttribute('interface', $interface);
     }
     if ($table->isCrossRef()) {
         $tableNode->setAttribute('isCrossRef', 'true');
     }
     $phpNamingMethod = $table->getPhpNamingMethod();
     if ($phpNamingMethod && $phpNamingMethod !== $database->getDefaultPhpNamingMethod()) {
         $tableNode->setAttribute('phpNamingMethod', $phpNamingMethod);
     }
     if ($baseClass = $table->getBaseClass()) {
         $tableNode->setAttribute('baseClass', $baseClass);
     }
     if ($baseQueryClass = $table->getBaseQueryClass()) {
         $tableNode->setAttribute('baseQueryClass', $baseQueryClass);
     }
     if ($table->isReadOnly()) {
         $tableNode->setAttribute('readOnly', 'true');
     }
     if ($table->isReloadOnInsert()) {
         $tableNode->setAttribute('reloadOnInsert', 'true');
     }
     if ($table->isReloadOnUpdate()) {
         $tableNode->setAttribute('reloadOnUpdate', 'true');
     }
     if (null !== ($referenceOnly = $table->isForReferenceOnly())) {
         $tableNode->setAttribute('forReferenceOnly', $referenceOnly ? 'true' : 'false');
     }
     if ($alias = $table->getAlias()) {
         $tableNode->setAttribute('alias', $alias);
     }
     if ($description = $table->getDescription()) {
         $tableNode->setAttribute('description', $description);
     }
     $defaultStringFormat = $table->getDefaultStringFormat();
     if (Table::DEFAULT_STRING_FORMAT !== $defaultStringFormat) {
         $tableNode->setAttribute('defaultStringFormat', $defaultStringFormat);
     }
     $defaultAccessorVisibility = $table->getDefaultAccessorVisibility();
     if ($defaultAccessorVisibility !== Table::VISIBILITY_PUBLIC) {
         $tableNode->setAttribute('defaultAccessorVisibility', $defaultAccessorVisibility);
     }
     $defaultMutatorVisibility = $table->getDefaultMutatorVisibility();
     if ($defaultMutatorVisibility !== Table::VISIBILITY_PUBLIC) {
         $tableNode->setAttribute('defaultMutatorVisibility', $defaultMutatorVisibility);
     }
     foreach ($table->getColumns() as $column) {
         $this->appendColumnNode($column, $tableNode);
     }
     foreach ($table->getForeignKeys() as $foreignKey) {
         $this->appendForeignKeyNode($foreignKey, $tableNode);
     }
     foreach ($table->getIdMethodParameters() as $parameter) {
         $this->appendIdMethodParameterNode($parameter, $tableNode);
     }
     foreach ($table->getIndices() as $index) {
         $this->appendIndexNode($index, $tableNode);
     }
     foreach ($table->getUnices() as $index) {
         $this->appendUniqueIndexNode($index, $tableNode);
     }
     foreach ($table->getVendorInformation() as $vendorInformation) {
         $this->appendVendorInformationNode($vendorInformation, $tableNode);
     }
     foreach ($table->getBehaviors() as $behavior) {
         $this->appendBehaviorNode($behavior, $tableNode);
     }
 }