Contao\CoreBundle\Doctrine\Schema\DcaSchemaProvider::appendToSchema PHP Метод

appendToSchema() публичный Метод

Adds the DCA data to the Doctrine schema.
public appendToSchema ( Doctrine\DBAL\Schema\Schema $schema )
$schema Doctrine\DBAL\Schema\Schema
    public function appendToSchema(Schema $schema)
    {
        $config = $this->getSqlDefinitions();
        foreach ($config as $tableName => $definitions) {
            $table = $schema->createTable($tableName);
            if (isset($definitions['SCHEMA_FIELDS'])) {
                foreach ($definitions['SCHEMA_FIELDS'] as $fieldName => $config) {
                    $options = $config;
                    unset($options['name'], $options['type']);
                    $table->addColumn($config['name'], $config['type'], $options);
                }
            }
            if (isset($definitions['TABLE_FIELDS'])) {
                foreach ($definitions['TABLE_FIELDS'] as $fieldName => $sql) {
                    $this->parseColumnSql($table, $fieldName, strtolower(substr($sql, strlen($fieldName) + 3)));
                }
            }
            if (isset($definitions['TABLE_CREATE_DEFINITIONS'])) {
                foreach ($definitions['TABLE_CREATE_DEFINITIONS'] as $keyName => $sql) {
                    $this->parseIndexSql($table, $keyName, strtolower($sql));
                }
            }
            if (isset($definitions['TABLE_OPTIONS'])) {
                if (preg_match('/ENGINE=([^ ]+)/i', $definitions['TABLE_OPTIONS'], $match)) {
                    $table->addOption('engine', $match[1]);
                }
                if (preg_match('/DEFAULT CHARSET=([^ ]+)/i', $definitions['TABLE_OPTIONS'], $match)) {
                    $table->addOption('charset', $match[1]);
                }
            }
        }
    }

Usage Example

Пример #1
0
 /**
  * Adds the Contao DCA information to the Doctrine schema.
  *
  * @param GenerateSchemaEventArgs $event
  */
 public function postGenerateSchema(GenerateSchemaEventArgs $event)
 {
     $this->provider->appendToSchema($event->getSchema());
 }