Skip to content
This repository has been archived by the owner on Nov 24, 2020. It is now read-only.

Symfony 3 to Symfony 4 directory structure #3

Open
TomasVotruba opened this issue Apr 27, 2020 · 0 comments
Open

Symfony 3 to Symfony 4 directory structure #3

TomasVotruba opened this issue Apr 27, 2020 · 0 comments

Comments

@TomasVotruba
Copy link
Member

TomasVotruba commented Apr 27, 2020

#!/usr/bin/php
<?php declare(strict_types=1);

use Nette\Utils\Finder;

require __DIR__ . '/../vendor/autoload.php';

// /src/AppBundle/Resources/views => /templates
if (file_exists(__DIR__ . '/../src/AppBundle/Resources/views')) {
	foreach (Finder::findFiles('*')->from(__DIR__ . '/../src/AppBundle/Resources/views') as $file) {
		$filePath = $file->getPathname();
		$newFilePath = str_replace('/src/AppBundle/Resources/views', '/templates', $filePath);
		\Nette\Utils\FileSystem::rename($filePath, $newFilePath);
	}
}

// /app/Resources/views => /templates
if (file_exists(__DIR__ . '/../app/Resources/views')) {
	foreach (Finder::findFiles('*')->from(__DIR__ . '/../app/Resources/views') as $file) {
		$filePath = $file->getPathname();
		$newFilePath = str_replace('/app/Resources/views', '/templates', $filePath);
		\Nette\Utils\FileSystem::rename($filePath, $newFilePath);
	}
}

// /src/AppBundle => /src
if (file_exists(__DIR__ . '/../src/AppBundle')) {
	foreach (Finder::findFiles('*')->from(__DIR__ . '/../src/AppBundle') as $file) {
		$filePath = $file->getPathname();
		$newFilePath = str_replace('/AppBundle', '', $filePath);
		\Nette\Utils\FileSystem::rename($filePath, $newFilePath);
	}
}

// /app/config -> /config
if (file_exists(__DIR__ . '/../app/config')) {
	foreach (Finder::findFiles('*')->from(__DIR__ . '/../app/config') as $file) {
		$filePath = $file->getPathname();
		$newFilePath = str_replace('/app', '', $filePath);
		\Nette\Utils\FileSystem::rename($filePath, $newFilePath);
	}
}

// /web -> /public
if (file_exists(__DIR__ . '/../web')) {
	foreach (Finder::findFiles('*')->from(__DIR__ . '/../web') as $file) {
		$filePath = $file->getPathname();
		$newFilePath = str_replace('web', 'public', $filePath);
		\Nette\Utils\FileSystem::rename($filePath, $newFilePath);
	}
}

$directoriesTransfer = [
	__DIR__ . '/../src/Resources/translations' => __DIR__ . '/../translations',
	__DIR__ . '/../app/Resources' => __DIR__ . '/../src/Resources',
	__DIR__ . '/../var/logs' => __DIR__ . '/../var/log',
	__DIR__ . '/../tests/Integration/AppBundle' => __DIR__ . '/../tests/Integration/App',
	__DIR__ . '/../tests/Unit/AppBundle' => __DIR__ . '/../tests/Unit/App',
];

foreach ($directoriesTransfer as $old => $new) {
	if (!file_exists($old)) {
		continue;
	}

	\Nette\Utils\FileSystem::rename($old, $new);
}

// config/*.yml -> config/*.yaml
$ymlFiles = Finder::findFiles('*.yml', '*.yml.*')->from(__DIR__ . '/../config');
foreach ($ymlFiles as $ymlFile) {
	$filePath = $ymlFile->getPathname();
	$newFilePath = str_replace('yml', 'yaml', $filePath);
	\Nette\Utils\FileSystem::rename($filePath, $newFilePath);
}

$filesToDelete = [
	__DIR__ . '/../app',
	__DIR__ . '/../web',
	__DIR__ . '/../src/AppBundle',
	__DIR__ . '/../src/Resources/views',
	__DIR__ . '/../src.php',
];

foreach ($filesToDelete as $fileToDelete) {
	\Nette\Utils\FileSystem::delete($fileToDelete);
}

// Replace everywhere App -> App
foreach (Finder::findFiles('*')->from(__DIR__ . '/..')->exclude('symfony-migrate-to-4', '.git', 'var', 'vendor') as $file) {
	$filePath = $file->getPathname();
	$content = \Nette\Utils\FileSystem::read($filePath);
	$content = str_replace('AppBundle', 'App', $content);
	\Nette\Utils\FileSystem::write($filePath, $content);
}

/////////////////////////
/////////////////////////
// Manually create and edit .env
// Manually edit .yaml configs (divide by packages)
// Manually edit .gitlab-ci.yml
// Manually edit templates, '@App' what to replace with
// Server configuration nginx -> index.php
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant