Skip to content

Commit

Permalink
CreateCommand: remove dependency on nette/utils
Browse files Browse the repository at this point in the history
[closes #106][closes #114]
  • Loading branch information
JanTvrdik committed Jun 14, 2022
1 parent d409203 commit 2248f2d
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/Bridges/SymfonyConsole/CreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\String\Slugger\AsciiSlugger;


class CreateCommand extends BaseCommand
Expand Down Expand Up @@ -118,7 +119,7 @@ protected function getGroup($type)

$matchedGroups = [];
foreach ($this->config->getGroups() as $group) {
if (Strings::match($group->name, $groupNamePattern)) {
if (preg_match($groupNamePattern, $group->name)) {
$matchedGroups[] = $group;
}
}
Expand Down Expand Up @@ -148,7 +149,21 @@ protected function getGroup($type)
*/
protected function getFileName($label, $extension)
{
return date('Y-m-d-His-') . Strings::webalize($label, '.') . '.' . $extension;
if (preg_match('#^[a-z0-9.-]++$#i', $label)) {
$slug = strtolower($label);

} elseif (class_exists('Nette\Utils\Strings')) {
$slug = Strings::webalize($label, '.');

} elseif (class_exists('Symfony\Component\String\Slugger\AsciiSlugger')) {
$slugger = new AsciiSlugger('en');
$slug = $slugger->slug($label)->toString();

} else {
throw new Nextras\Migrations\LogicException("Provided label '$label' contains invalid characters.");
}

return date('Y-m-d-His-') . $slug . '.' . $extension;
}


Expand Down

0 comments on commit 2248f2d

Please sign in to comment.