configuration = $configuration; $this->platform = $platform; } /** @param string[] $sql */ public function generate( array $sql, bool $formatted = false, int $lineLength = 120, bool $checkDbPlatform = true ): string { $code = []; $storageConfiguration = $this->configuration->getMetadataStorageConfiguration(); foreach ($sql as $query) { if ( $storageConfiguration instanceof TableMetadataStorageConfiguration && stripos($query, $storageConfiguration->getTableName()) !== false ) { continue; } if ($formatted) { $maxLength = $lineLength - 18 - 8; // max - php code length - indentation if (strlen($query) > $maxLength) { $query = (new SqlFormatter(new NullHighlighter()))->format($query); } } $code[] = sprintf('$this->addSql(%s);', var_export($query, true)); } if (count($code) !== 0 && $checkDbPlatform && $this->configuration->isDatabasePlatformChecked()) { $currentPlatform = '\\' . get_class($this->platform); array_unshift( $code, sprintf( <<<'PHP' $this->abortIf( !$this->connection->getDatabasePlatform() instanceof %s, "Migration can only be executed safely on '%s'." ); PHP , $currentPlatform, $currentPlatform ), '' ); } return implode("\n", $code); } }