Skip to content

Instantly share code, notes, and snippets.

@mishak87
Created December 21, 2012 20:04
Show Gist options
  • Save mishak87/4355394 to your computer and use it in GitHub Desktop.
Save mishak87/4355394 to your computer and use it in GitHub Desktop.
Simple script for converting Nette templates file structure from <Presenter>.<action>.phtml or .latte to <Presenter>/<action>.latte
<?php
$root = ltrim(getcwd(), DIRECTORY_SEPARATOR);
foreach (scandir($root) as $file) {
if (preg_match('/^(?P<presenter>[^.]+)\.(?P<action>[^.]+)\.(latte|phtml)$/', $file, $matches)) {
$dir = $root . DIRECTORY_SEPARATOR . $matches['presenter'];
$filename = $dir . DIRECTORY_SEPARATOR . $matches['action'] . '.latte';
if (!is_dir($dir)) {
mkdir($dir);
}
rename($root . DIRECTORY_SEPARATOR . $file, $filename);
// echo $root . DIRECTORY_SEPARATOR . $file, ' => ', $filename, "\n";
} else {
echo "Skipped $file\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment