Esempio n. 1
0
 /**
  * Creates a table for a custom entity.
  * The custom entity is an entity which has no PHP class in any bundle. The definition of such entity is
  * created automatically in Symfony cache
  *
  * @param Schema $schema
  * @param string $entityName
  * @param array  $options
  *
  * @return Table
  *
  * @throws \InvalidArgumentException
  */
 public function createCustomEntityTable(Schema $schema, $entityName, array $options = [])
 {
     $className = ExtendHelper::ENTITY_NAMESPACE . $entityName;
     $tableName = $this->nameGenerator->generateCustomEntityTableName($className);
     $table = $schema->createTable($tableName);
     $this->entityMetadataHelper->registerEntityClass($tableName, $className);
     $options = new OroOptions($options);
     // set options
     $options->setAuxiliary(ExtendOptionsManager::ENTITY_CLASS_OPTION, $className);
     if ($options->has('extend', 'owner')) {
         if ($options->get('extend', 'owner') !== ExtendScope::OWNER_CUSTOM) {
             throw new \InvalidArgumentException(sprintf('The "extend.owner" option for a custom entity must be "%s".', ExtendScope::OWNER_CUSTOM));
         }
     } else {
         $options->set('extend', 'owner', ExtendScope::OWNER_CUSTOM);
     }
     if ($options->has('extend', 'is_extend')) {
         if ($options->get('extend', 'is_extend') !== true) {
             throw new \InvalidArgumentException('The "extend.is_extend" option for a custom entity must be TRUE.');
         }
     } else {
         $options->set('extend', 'is_extend', true);
     }
     $table->addOption(OroOptions::KEY, $options);
     // add a primary key
     $table->addColumn(self::AUTO_GENERATED_ID_COLUMN_NAME, 'integer', ['autoincrement' => true]);
     $table->setPrimaryKey([self::AUTO_GENERATED_ID_COLUMN_NAME]);
     return $table;
 }